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

Draft: Filters on homepage aren't working properly #1501

Merged
merged 1 commit into from
Feb 15, 2024
Merged
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
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
Loading