Skip to content

Commit

Permalink
added count to budget and added workspace/next endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Apr 17, 2024
1 parent b43c477 commit cfd4613
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions handlers/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions routes/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cfd4613

Please sign in to comment.