Skip to content

Commit

Permalink
added status to user assigned bounties
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Mar 1, 2024
1 parent bbcc852 commit f4583ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 26 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,37 @@ func (db database) GetAssignedBounties(r *http.Request) ([]Bounty, error) {
uuid := chi.URLParam(r, "uuid")
person := db.GetPersonByUuid(uuid)
pubkey := person.OwnerPubKey
keys := r.URL.Query()

open := keys.Get("Open")
assingned := keys.Get("Assigned")
paid := keys.Get("Paid")

orderQuery := ""
limitQuery := ""
var statusQuery string
var statusConditions []string

if open == "true" {
statusConditions = append(statusConditions, "assignee = '' AND paid != true")
}
if assingned == "true" {
statusConditions = append(statusConditions, "assignee != '' AND paid = false")
}
if paid == "true" {
statusConditions = append(statusConditions, "paid = true")
}

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

if sortBy != "" && direction != "" {
orderQuery = "ORDER BY " + sortBy + " " + direction
} else {
orderQuery = " ORDER BY paid ASC"
orderQuery = " ORDER BY created DESC"
}
if offset >= 0 && limit != 0 {
limitQuery = fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset)
Expand All @@ -747,7 +770,7 @@ func (db database) GetAssignedBounties(r *http.Request) ([]Bounty, error) {
ms := []Bounty{}

query := `SELECT * FROM public.bounty WHERE assignee = '` + pubkey + `' AND show != false`
allQuery := query + " " + orderQuery + " " + limitQuery
allQuery := query + " " + statusQuery + " " + orderQuery + " " + limitQuery
err := db.db.Raw(allQuery).Find(&ms).Error
return ms, err
}
Expand Down Expand Up @@ -787,7 +810,7 @@ func (db database) GetCreatedBounties(r *http.Request) ([]Bounty, error) {
if sortBy != "" && direction != "" {
orderQuery = "ORDER BY " + sortBy + " " + direction
} else {
orderQuery = "ORDER BY paid ASC"
orderQuery = "ORDER BY created DESC"
}

if offset >= 0 && limit != 0 {
Expand Down
4 changes: 3 additions & 1 deletion handlers/bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,13 +971,15 @@ func GetPersonAssigned(t *testing.T) {
expectedBounties := []db.Bounty{
{ID: 1, Assignee: "user1"},
{ID: 2, Assignee: "user1"},
{ID: 3, OwnerID: "user2", Assignee: "user1"},
{ID: 4, OwnerID: "user2", Assignee: "user1", Paid: true},
}

mockDb.On("GetAssignedBounties", mock.Anything).Return(expectedBounties, nil).Once()
mockDb.On("GetPersonByPubkey", mock.Anything).Return(db.Person{}, nil)
mockDb.On("GetOrganizationByUuid", mock.Anything).Return(db.Organization{}, nil)
rr := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/wanteds/assigned/uuid", nil)
req, err := http.NewRequest("GET", "/wanteds/assigned/uuid?Assigned=true&Paid=true&offset=0&limit=4", nil)
req = req.WithContext(ctx)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit f4583ff

Please sign in to comment.