From cc89621b166ac95b3c80201864ee688f46de82f9 Mon Sep 17 00:00:00 2001 From: elraphty Date: Thu, 31 Oct 2024 16:19:12 +0100 Subject: [PATCH 1/2] added backend backend filters bounties with failed and pending payments --- db/db.go | 157 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 60 deletions(-) diff --git a/db/db.go b/db/db.go index 96060aaae..4e01243aa 100644 --- a/db/db.go +++ b/db/db.go @@ -447,38 +447,6 @@ func makeExtrasListQuery(columnName string) string { ` } -func makePersonExtrasListQuery(columnName string) string { - // this is safe because columnName is not provided by the user, its hard-coded in db.go - return `SELECT - json_build_object('owner_pubkey', owner_pub_key, 'owner_alias', owner_alias, 'img', img, 'unique_name', unique_name, 'id', id, '` + columnName + `', extras->'` + columnName + `', 'github_issues', github_issues) #>> '{}' as person, - arr.item_object as body - FROM people, - jsonb_array_elements(extras->'` + columnName + `') with ordinality - arr(item_object, position) - WHERE arr.item_object->'assignee'->>'owner_pubkey' = ? - AND LOWER(arr.item_object->>'title') LIKE ? - AND CASE - WHEN arr.item_object->>'show' = 'false' THEN false - ELSE true - END` -} - -func addNewerThanXDaysToExtrasRawQuery(query string, days int) string { - secondsInDay := 86400 - newerThan := secondsInDay * days - t := strconv.Itoa(newerThan) - return query + ` AND CAST(arr.item_object->>'created' AS INT) > (extract(epoch from now()) - ` + t + `) ` -} - -func addNewerThanTimestampToExtrasRawQuery(query string, timestamp int) string { - t := strconv.Itoa(timestamp) - return query + ` AND CAST(arr.item_object->>'created' AS INT) > ` + t -} - -func addOrderToExtrasRawQuery(query string) string { - return query + `ORDER BY cast(arr.item_object->>'created' as integer) DESC` -} - func addNotMineToExtrasRawQuery(query string, pubkey string) string { return query + ` AND people.owner_pub_key != ` + pubkey + ` ` } @@ -525,44 +493,41 @@ func (db database) GetBountiesCount(r *http.Request) int64 { assingned := keys.Get("Assigned") paid := keys.Get("Paid") completed := keys.Get("Completed") + pending := keys.Get("Pending") + failed := keys.Get("Failed") - openQuery := "" - assignedQuery := "" - paidQuery := "" - completedQuery := "" + var statusConditions []string - if open != "" && open == "true" { - openQuery = "AND assignee = '' AND paid != true" - assignedQuery = "" + if open == "true" { + statusConditions = append(statusConditions, "assignee = '' AND paid != true") } - if assingned != "" && assingned == "true" { - if open != "" && open == "true" { - assignedQuery = "OR assignee != '' AND paid = false" - } else { - assignedQuery = "AND assignee != '' AND paid = false" - } + if assingned == "true" { + statusConditions = append(statusConditions, "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 completed == "true" { + statusConditions = append(statusConditions, "assignee != '' AND completed = true AND paid = false") } - if paid != "" && paid == "true" { - if open != "" && open == "true" || assingned != "" && assingned == "true" { - paidQuery = "OR paid = true" - } else if open != "" && open == "true" && assingned == "" && assingned != "true" { - assignedQuery = "" - } else { - paidQuery = "AND paid = true" - } + if paid == "true" { + statusConditions = append(statusConditions, "paid = true") + } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } + + var statusQuery string + if len(statusConditions) > 0 { + statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" + } else { + statusQuery = "" } var count int64 query := "SELECT COUNT(*) FROM bounty WHERE show != false" - allQuery := query + " " + openQuery + " " + assignedQuery + " " + completedQuery + " " + paidQuery + allQuery := query + " " + statusQuery db.db.Raw(allQuery).Scan(&count) return count } @@ -596,6 +561,8 @@ func (db database) GetWorkspaceBounties(r *http.Request, workspace_uuid string) assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -636,6 +603,12 @@ func (db database) GetWorkspaceBounties(r *http.Request, workspace_uuid string) if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } var statusQuery string if len(statusConditions) > 0 { @@ -683,6 +656,8 @@ func (db database) GetWorkspaceBountiesCount(r *http.Request, workspace_uuid str assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -708,6 +683,12 @@ func (db database) GetWorkspaceBountiesCount(r *http.Request, workspace_uuid str if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } var statusQuery string if len(statusConditions) > 0 { @@ -763,6 +744,8 @@ func (db database) GetAssignedBounties(r *http.Request) ([]NewBounty, error) { open := keys.Get("Open") assingned := keys.Get("Assigned") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") orderQuery := "" limitQuery := "" @@ -778,6 +761,12 @@ func (db database) GetAssignedBounties(r *http.Request) ([]NewBounty, error) { if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -816,6 +805,8 @@ func (db database) GetCreatedBounties(r *http.Request) ([]NewBounty, error) { open := keys.Get("Open") assingned := keys.Get("Assigned") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") orderQuery := "" limitQuery := "" @@ -831,6 +822,12 @@ func (db database) GetCreatedBounties(r *http.Request) ([]NewBounty, error) { if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -872,6 +869,8 @@ func (db database) GetNextBountyByCreated(r *http.Request) (uint, error) { open := keys.Get("Open") assingned := keys.Get("Assigned") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -894,6 +893,12 @@ func (db database) GetNextBountyByCreated(r *http.Request) (uint, error) { if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -934,6 +939,8 @@ func (db database) GetPreviousBountyByCreated(r *http.Request) (uint, error) { assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -959,6 +966,12 @@ func (db database) GetPreviousBountyByCreated(r *http.Request) (uint, error) { if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -1000,6 +1013,8 @@ func (db database) GetNextWorkspaceBountyByCreated(r *http.Request) (uint, error assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -1025,6 +1040,12 @@ func (db database) GetNextWorkspaceBountyByCreated(r *http.Request) (uint, error if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -1066,6 +1087,8 @@ func (db database) GetPreviousWorkspaceBountyByCreated(r *http.Request) (uint, e assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") languages := keys.Get("languages") languageArray := strings.Split(languages, ",") languageLength := len(languageArray) @@ -1091,6 +1114,12 @@ func (db database) GetPreviousWorkspaceBountyByCreated(r *http.Request) (uint, e if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } if len(statusConditions) > 0 { statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")" @@ -1146,6 +1175,8 @@ func (db database) GetAllBounties(r *http.Request) []NewBounty { assingned := keys.Get("Assigned") completed := keys.Get("Completed") paid := keys.Get("Paid") + pending := keys.Get("Pending") + failed := keys.Get("Failed") orgUuid := keys.Get("org_uuid") workspaceUuid := keys.Get("workspace_uuid") languages := keys.Get("languages") @@ -1202,6 +1233,12 @@ func (db database) GetAllBounties(r *http.Request) []NewBounty { if paid == "true" { statusConditions = append(statusConditions, "paid = true") } + if pending == "true" { + statusConditions = append(statusConditions, "payment_pending = true") + } + if failed == "true" { + statusConditions = append(statusConditions, "payment_failed = true") + } var statusQuery string if len(statusConditions) > 0 { From 731d5b2c871b99e5d5bcfe4e91bb2bcfb92dcf0b Mon Sep 17 00:00:00 2001 From: elraphty Date: Thu, 31 Oct 2024 18:30:36 +0100 Subject: [PATCH 2/2] adding pending and failed payments to filter count --- db/db.go | 6 ++++++ db/structs.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/db/db.go b/db/db.go index 4e01243aa..a085ec485 100644 --- a/db/db.go +++ b/db/db.go @@ -537,17 +537,23 @@ func (db database) GetFilterStatusCount() FilterStattuCount { var assignedCount int64 var completedCount int64 var paidCount int64 + var pendingCount int64 + var failedCount 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) + db.db.Model(&Bounty{}).Where("show != false").Where("assignee != ''").Where("payment_pending = true").Count(&pendingCount) + db.db.Model(&Bounty{}).Where("show != false").Where("assignee != ''").Where("payment_failed = true").Count(&failedCount) ms := FilterStattuCount{ Open: openCount, Assigned: assignedCount, Completed: completedCount, Paid: paidCount, + Pending: pendingCount, + Failed: failedCount, } return ms diff --git a/db/structs.go b/db/structs.go index 4e37fc974..9a125ced6 100644 --- a/db/structs.go +++ b/db/structs.go @@ -906,6 +906,8 @@ type FilterStattuCount struct { Assigned int64 `json:"assigned"` Completed int64 `json:"completed"` Paid int64 `json:"paid"` + Pending int64 `json:"pending"` + Failed int64 `json:"failed"` } func (Person) TableName() string {