diff --git a/db/db.go b/db/db.go index 0d04078c0..4bce4e82d 100644 --- a/db/db.go +++ b/db/db.go @@ -522,9 +522,12 @@ func (db database) GetBountiesCount(r *http.Request) int64 { open := keys.Get("Open") assingned := keys.Get("Assigned") paid := keys.Get("Paid") + completed := keys.Get("Completed") + openQuery := "" assignedQuery := "" paidQuery := "" + completedQuery := "" if open != "" && open == "true" { openQuery = "AND assignee = '' AND paid != true" @@ -537,6 +540,13 @@ func (db database) GetBountiesCount(r *http.Request) int64 { assignedQuery = "AND assignee != '' AND paid = false" } } + if completed != "" && completed == "true" { + if open != "" && open == "true" { + completedQuery = "OR assignee != '' AND completed = true AND paid = false" + } else { + completedQuery = "AND assignee != '' AND completed = true AND paid = false" + } + } if paid != "" && paid == "true" { if open != "" && open == "true" || assingned != "" && assingned == "true" { paidQuery = "OR paid = true" @@ -550,7 +560,7 @@ func (db database) GetBountiesCount(r *http.Request) int64 { var count int64 query := "SELECT COUNT(*) FROM bounty WHERE show != false" - allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + allQuery := query + " " + openQuery + " " + assignedQuery + " " + completedQuery + " " + paidQuery db.db.Raw(allQuery).Scan(&count) return count } @@ -558,16 +568,19 @@ func (db database) GetBountiesCount(r *http.Request) int64 { func (db database) GetFilterStatusCount() FilterStattuCount { var openCount int64 var assignedCount int64 + var completedCount int64 var paidCount int64 db.db.Model(&Bounty{}).Where("show != false").Where("assignee = ''").Where("paid != true").Count(&openCount) db.db.Model(&Bounty{}).Where("show != false").Where("assignee != ''").Where("paid != true").Count(&assignedCount) + db.db.Model(&Bounty{}).Where("show != false").Where("assignee != ''").Where("completed = true").Where("paid != true").Count(&completedCount) db.db.Model(&Bounty{}).Where("show != false").Where("assignee != ''").Where("paid = true").Count(&paidCount) ms := FilterStattuCount{ - Open: openCount, - Assigned: assignedCount, - Paid: paidCount, + Open: openCount, + Assigned: assignedCount, + Completed: completedCount, + Paid: paidCount, } return ms @@ -579,6 +592,7 @@ func (db database) GetWorkspaceBounties(r *http.Request, org_uuid string) []Boun offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") @@ -614,6 +628,9 @@ func (db database) GetWorkspaceBounties(r *http.Request, org_uuid string) []Boun if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } @@ -662,6 +679,7 @@ func (db database) GetWorkspaceBountiesCount(r *http.Request, org_uuid string) i search := keys.Get("search") open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") @@ -682,6 +700,9 @@ func (db database) GetWorkspaceBountiesCount(r *http.Request, org_uuid string) i if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } @@ -901,6 +922,7 @@ func (db database) GetPreviousBountyByCreated(r *http.Request) (uint, error) { open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") @@ -921,6 +943,9 @@ func (db database) GetPreviousBountyByCreated(r *http.Request) (uint, error) { if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } @@ -963,6 +988,7 @@ func (db database) GetNextWorkspaceBountyByCreated(r *http.Request) (uint, error open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") @@ -983,6 +1009,9 @@ func (db database) GetNextWorkspaceBountyByCreated(r *http.Request) (uint, error if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } @@ -1025,6 +1054,7 @@ func (db database) GetPreviousWorkspaceBountyByCreated(r *http.Request) (uint, e open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") @@ -1045,6 +1075,9 @@ func (db database) GetPreviousWorkspaceBountyByCreated(r *http.Request) (uint, e if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } @@ -1101,6 +1134,7 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) open := keys.Get("Open") assingned := keys.Get("Assigned") + completed := keys.Get("Completed") paid := keys.Get("Paid") orgUuid := keys.Get("org_uuid") languages := keys.Get("languages") @@ -1135,6 +1169,9 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { if assingned == "true" { statusConditions = append(statusConditions, "assignee != '' AND paid = false") } + if completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") + } if paid == "true" { statusConditions = append(statusConditions, "paid = true") } diff --git a/db/structs.go b/db/structs.go index 934f1ae15..ee8233045 100644 --- a/db/structs.go +++ b/db/structs.go @@ -501,8 +501,11 @@ type StatusBudget struct { OrgUuid string `json:"org_uuid"` CurrentBudget uint `json:"current_budget"` OpenBudget uint `json:"open_budget"` + OpenCount int64 `json:"open_count"` AssignedBudget uint `json:"assigned_budget"` + AssignedCount int64 `json:"assigned_count"` CompletedBudget uint `json:"completed_budget"` + CompletedCount int64 `json:"completed_count"` } type BudgetInvoiceRequest struct { @@ -695,9 +698,10 @@ type MetricsBountyCsv struct { } type FilterStattuCount struct { - Open int64 `json:"open"` - Assigned int64 `json:"assigned"` - Paid int64 `json:"paid"` + Open int64 `json:"open"` + Assigned int64 `json:"assigned"` + Completed int64 `json:"completed"` + Paid int64 `json:"paid"` } func (Person) TableName() string { diff --git a/db/workspaces.go b/db/workspaces.go index 29ea28ee4..97cf37e37 100644 --- a/db/workspaces.go +++ b/db/workspaces.go @@ -159,18 +159,30 @@ func (db database) GetWorkspaceStatusBudget(org_uuid string) StatusBudget { var openBudget uint db.db.Model(&Bounty{}).Where("assignee = '' ").Where("paid != true").Select("SUM(price)").Row().Scan(&openBudget) + var openCount int64 + db.db.Model(&Bounty{}).Where("assignee = '' ").Where("paid != true").Count(&openCount) + var assignedBudget uint db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Select("SUM(price)").Row().Scan(&assignedBudget) + var assignedCount int64 + db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Count(&assignedCount) + var completedBudget uint db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Select("SUM(price)").Row().Scan(&completedBudget) + var completedCount int64 + db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Count(&completedCount) + statusBudget := StatusBudget{ OrgUuid: org_uuid, CurrentBudget: orgBudget.TotalBudget, OpenBudget: openBudget, + OpenCount: openCount, AssignedBudget: assignedBudget, + AssignedCount: assignedCount, CompletedBudget: completedBudget, + CompletedCount: completedCount, } return statusBudget diff --git a/handlers/workspaces_test.go b/handlers/workspaces_test.go index 8630709b6..6917d2030 100644 --- a/handlers/workspaces_test.go +++ b/handlers/workspaces_test.go @@ -436,8 +436,11 @@ func TestGetWorkspaceBudget(t *testing.T) { OrgUuid: orgUUID, CurrentBudget: 10000, OpenBudget: 1000, + OpenCount: 10, AssignedBudget: 2000, + AssignedCount: 15, CompletedBudget: 3000, + CompletedCount: 5, } oHandler.userHasAccess = mockUserHasAccess diff --git a/routes/bounty.go b/routes/bounty.go index 3d440c0e4..6f743d479 100644 --- a/routes/bounty.go +++ b/routes/bounty.go @@ -21,6 +21,8 @@ func BountyRoutes() chi.Router { r.Get("/previous/{created}", bountyHandler.GetPreviousBountyByCreated) r.Get("/org/next/{uuid}/{created}", bountyHandler.GetWorkspaceNextBountyByCreated) r.Get("/org/previous/{uuid}/{created}", bountyHandler.GetWorkspacePreviousBountyByCreated) + r.Get("/workspace/next/{uuid}/{created}", bountyHandler.GetWorkspaceNextBountyByCreated) + r.Get("/workspace/previous/{uuid}/{created}", bountyHandler.GetWorkspacePreviousBountyByCreated) r.Get("/created/{created}", bountyHandler.GetBountyByCreated) r.Get("/count/{personKey}/{tabType}", handlers.GetUserBountyCount)