From cfd46133a88523c03b4603fc021695a0ccf33afc Mon Sep 17 00:00:00 2001 From: elraphty Date: Wed, 17 Apr 2024 13:35:45 +0100 Subject: [PATCH] added count to budget and added workspace/next endpoint --- db/structs.go | 3 +++ db/workspaces.go | 12 ++++++++++++ handlers/workspaces_test.go | 3 +++ routes/bounty.go | 2 ++ 4 files changed, 20 insertions(+) diff --git a/db/structs.go b/db/structs.go index 934f1ae15..3abe1edb0 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 { 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)