Skip to content

Commit

Permalink
Merge pull request #919 from stakwork/fix/pay_bounty_expired
Browse files Browse the repository at this point in the history
Fix/pay bounty expired
  • Loading branch information
elraphty authored Nov 10, 2023
2 parents d6c7daa + 3f08f01 commit 5f259ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
func (db database) GetAssignedBounties(pubkey string) ([]BountyData, error) {
ms := []BountyData{}

err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.assignee = '` + pubkey + `' ORDER BY body.id DESC`).Find(&ms).Error
err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.assignee = '` + pubkey + `' AND body.show != false ORDER BY body.id DESC`).Find(&ms).Error

return ms, err
}
Expand All @@ -499,6 +499,14 @@ func (db database) GetBountyById(id string) ([]BountyData, error) {
return ms, err
}

func (db database) GetBountyDataByCreated(created string) ([]BountyData, error) {
ms := []BountyData{}

err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.created = '` + created + `' ORDER BY body.id DESC`).Find(&ms).Error

return ms, err
}

func (db database) AddBounty(b Bounty) (Bounty, error) {
db.db.Create(&b)
return b, nil
Expand Down
16 changes: 16 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func GetBountyById(w http.ResponseWriter, r *http.Request) {
}
}

func GetBountyByCreated(w http.ResponseWriter, r *http.Request) {
created := chi.URLParam(r, "created")
if created == "" {
w.WriteHeader(http.StatusNotFound)
}
bounties, err := db.DB.GetBountyDataByCreated(created)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = generateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetBountyCount(w http.ResponseWriter, r *http.Request) {
personKey := chi.URLParam(r, "personKey")
tabType := chi.URLParam(r, "tabType")
Expand Down
1 change: 1 addition & 0 deletions routes/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func BountyRoutes() chi.Router {
r.Group(func(r chi.Router) {
r.Get("/all", handlers.GetAllBounties)
r.Get("/id/{bountyId}", handlers.GetBountyById)
r.Get("/created/{created}", handlers.GetBountyByCreated)
r.Get("/count/{personKey}/{tabType}", handlers.GetBountyCount)
r.Get("/invoice/{paymentRequest}", handlers.GetInvoiceData)

Expand Down

0 comments on commit 5f259ae

Please sign in to comment.