Skip to content

Commit

Permalink
fix: queries
Browse files Browse the repository at this point in the history
  • Loading branch information
anish authored and anish committed Feb 10, 2024
1 parent 2811e42 commit ca36370
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,6 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {
orderQuery := ""
limitQuery := ""
searchQuery := ""
openQuery := ""
assignedQuery := ""
paidQuery := ""
orgQuery := ""
languageQuery := ""

Expand All @@ -1009,26 +1006,26 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {
if 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" {
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" {
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 orgUuid != "" {
orgQuery = "AND org_uuid = '" + orgUuid + "'"
}
Expand All @@ -1048,8 +1045,8 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {

query := "SELECT * FROM public.bounty WHERE show != false"

allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orgQuery + " " + languageQuery + " " + orderQuery + " " + limitQuery

allQuery := query + " " + statusQuery + " " + searchQuery + " " + orgQuery + " " + languageQuery + " " + orderQuery + " " + limitQuery
theQuery := db.db.Raw(allQuery)

if tags != "" {
Expand Down

0 comments on commit ca36370

Please sign in to comment.