Skip to content

Commit

Permalink
Merge pull request #1476 from AbdulWahab3181/fix/org-bounties-query-v3
Browse files Browse the repository at this point in the history
updated status filter for accurate result
  • Loading branch information
elraphty authored Jan 31, 2024
2 parents d38bbd0 + 775bead commit 6d1b818
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,6 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
orderQuery := ""
limitQuery := ""
searchQuery := ""
openQuery := ""
assignedQuery := ""
paidQuery := ""
languageQuery := ""

if sortBy != "" && direction != "" {
Expand All @@ -530,30 +527,28 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
limitQuery += fmt.Sprintf(" OFFSET %d", offset)
}
if search != "" {
searchQuery = fmt.Sprintf("AND LOWER(title) LIKE %s", "'%"+search+"%'")
searchQuery = fmt.Sprintf("AND LOWER(title) LIKE %s", "'%"+strings.ToLower(search)+"%'")
}
if open != "" && open == "true" {
openQuery = "AND assignee = '' AND paid != true"
assignedQuery = ""

var statusConditions []string

if open == "true" {
statusConditions = append(statusConditions, "assignee = '' AND paid != true")
}
if assingned != "" && assingned == "true" {
assignedQuery = "AND assignee != '' AND paid = false"
if open != "" && open == "true" {
assignedQuery = "OR assignee != '' AND paid != true"
} else {
assignedQuery = "AND assignee != '' AND paid != true"
}
if assingned == "true" {
statusConditions = append(statusConditions, "assignee != '' AND paid = false")
}
if paid != "" && paid == "true" {
paidQuery = "AND 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")
}

var statusQuery string
if len(statusConditions) > 0 {
statusQuery = " AND (" + strings.Join(statusConditions, " OR ") + ")"
} else {
statusQuery = ""
}

if languageLength > 0 {
langs := ""
for i, val := range languageArray {
Expand All @@ -569,7 +564,7 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
}

query := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'`
allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + languageQuery + " " + orderQuery + " " + limitQuery
allQuery := query + " " + statusQuery + " " + searchQuery + " " + languageQuery + " " + orderQuery + " " + limitQuery
theQuery := db.db.Raw(allQuery)

if tags != "" {
Expand Down

0 comments on commit 6d1b818

Please sign in to comment.