From ab133df8372549c5def55997ca4b90359e21ef15 Mon Sep 17 00:00:00 2001 From: elraphty Date: Fri, 8 Dec 2023 19:47:33 +0100 Subject: [PATCH 1/6] Sent status request to the backend --- db/db.go | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/db/db.go b/db/db.go index 3aa3fcab9..21cacb0dc 100644 --- a/db/db.go +++ b/db/db.go @@ -447,11 +447,18 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B keys := r.URL.Query() tags := keys.Get("tags") // this is a string of tags separated by commas offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") ms := []Bounty{} orderQuery := "" limitQuery := "" searchQuery := "" + openQuery := "" + assignedQuery := "" + paidQuery := "" + if sortBy != "" && direction != "" { orderQuery = "ORDER BY " + sortBy + " " + direction } else { @@ -463,10 +470,24 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B if search != "" { searchQuery = fmt.Sprintf("WHERE LOWER(title) LIKE %s", "'%"+search+"%'") } + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } - rawQuery := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'` - - theQuery := db.db.Raw(rawQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery) + query := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'` + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery + theQuery := db.db.Raw(allQuery) if tags != "" { // pull out the tags and add them in here @@ -514,12 +535,18 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { keys := r.URL.Query() tags := keys.Get("tags") // this is a string of tags separated by commas offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") ms := []Bounty{} orderQuery := "" limitQuery := "" searchQuery := "" + openQuery := "" + assignedQuery := "" + paidQuery := "" if sortBy != "" && direction != "" { orderQuery = "ORDER BY " + sortBy + " " + direction @@ -532,10 +559,24 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { if search != "" { searchQuery = fmt.Sprintf("AND LOWER(title) LIKE %s", "'%"+search+"%'") } + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } query := "SELECT * FROM public.bounty WHERE show != false" - allQuery := query + " " + searchQuery + " " + orderQuery + " " + limitQuery + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery theQuery := db.db.Raw(allQuery) From 4ec441dbea9e8a8f11a5466680271bcaaf8a89a3 Mon Sep 17 00:00:00 2001 From: elraphty Date: Fri, 8 Dec 2023 20:14:46 +0100 Subject: [PATCH 2/6] removed commented code From 3d013560cb5ff2c458e0340141abb4e78b7ce688 Mon Sep 17 00:00:00 2001 From: elraphty Date: Fri, 8 Dec 2023 20:35:17 +0100 Subject: [PATCH 3/6] added load more for filter From 2c28efbc01a5f5e842ecd6c70dfe032b3a31510a Mon Sep 17 00:00:00 2001 From: elraphty Date: Sat, 9 Dec 2023 15:40:35 +0100 Subject: [PATCH 4/6] moved total and current items to Tickets.tsx --- db/db.go | 30 ++++++++++++++++++++++++++++-- handlers/bounty.go | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/db/db.go b/db/db.go index 21cacb0dc..c030aae36 100644 --- a/db/db.go +++ b/db/db.go @@ -437,9 +437,35 @@ func (db database) GetUserBountiesCount(personKey string, tabType string) int64 return count } -func (db database) GetBountiesCount() int64 { +func (db database) GetBountiesCount(r *http.Request) int64 { + keys := r.URL.Query() + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") + openQuery := "" + assignedQuery := "" + paidQuery := "" + + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } + var count int64 - db.db.Model(&Bounty{}).Where("show != ?", false).Count(&count) + + query := "SELECT COUNT(*) FROM bounty WHERE show != false" + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + db.db.Raw(allQuery).Scan(&count) return count } diff --git a/handlers/bounty.go b/handlers/bounty.go index e0dbc6315..d4e15e523 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -71,7 +71,7 @@ func GetUserBountyCount(w http.ResponseWriter, r *http.Request) { } func GetBountyCount(w http.ResponseWriter, r *http.Request) { - bountyCount := db.DB.GetBountiesCount() + bountyCount := db.DB.GetBountiesCount(r) w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bountyCount) } From 74adfde32d5c5c03da92fc97c1d7e0bfd53ea455 Mon Sep 17 00:00:00 2001 From: elraphty Date: Sat, 9 Dec 2023 15:47:20 +0100 Subject: [PATCH 5/6] reran prettier --- db/db_codes_test.go | 2 -- db/store_test.go | 6 ------ 2 files changed, 8 deletions(-) diff --git a/db/db_codes_test.go b/db/db_codes_test.go index 4caad51cf..9a552688e 100644 --- a/db/db_codes_test.go +++ b/db/db_codes_test.go @@ -28,9 +28,7 @@ func TestCodeGet(t *testing.T) { defer db.Close() gorm.Open("postgres", db) - rows := sqlmock.NewRows([]string{"connection_string", "date_created", "is_used", "date_created"}).AddRow(code.ID, code.ConnectionString, code.IsUsed, code.DateCreated) - mock.ExpectQuery(regexp.QuoteMeta( `SELECT connection_string, date_created FROM connectioncodes WHERE is_used = ? ORDER BY id DESC LIMIT 1`)). WithArgs(false). diff --git a/db/store_test.go b/db/store_test.go index f6c365ace..3d404f1e3 100644 --- a/db/store_test.go +++ b/db/store_test.go @@ -9,9 +9,7 @@ func TestSetCache(t *testing.T) { var value = "Trial" InitCache() - Store.SetCache(key, value) - cacheValue, err := Store.GetCache(key) if err != nil { @@ -30,7 +28,6 @@ func TestDeleteCache(t *testing.T) { InitCache() Store.SetCache(key, value) - cacheValue, err := Store.GetCache(key) if err != nil { @@ -42,7 +39,6 @@ func TestDeleteCache(t *testing.T) { } Store.DeleteCache(key) - _, errD := Store.GetCache(key) if errD == nil { @@ -60,9 +56,7 @@ func TestSetLnCache(t *testing.T) { } InitCache() - Store.SetLnCache(key, value) - cacheValue, err := Store.GetLnCache(key) if err != nil { From f7196c01e89d5cb69235a78c94ca6bfd55bc73ff Mon Sep 17 00:00:00 2001 From: elraphty Date: Sat, 9 Dec 2023 15:57:16 +0100 Subject: [PATCH 6/6] merge master