Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added count to budget and added workspace/next endpoint #1613

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -550,24 +560,27 @@ 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
}

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
Expand All @@ -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, ",")
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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, ",")
Expand All @@ -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")
}
Expand Down Expand Up @@ -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, ",")
Expand All @@ -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")
}
Expand Down Expand Up @@ -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, ",")
Expand All @@ -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")
}
Expand Down Expand Up @@ -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, ",")
Expand All @@ -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")
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
Expand Down
10 changes: 7 additions & 3 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 Expand Up @@ -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 {
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
Loading