diff --git a/db/db.go b/db/db.go index ace70e706..95729765a 100644 --- a/db/db.go +++ b/db/db.go @@ -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 } @@ -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 diff --git a/handlers/bounty.go b/handlers/bounty.go index 5e408b683..a580fc7b2 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -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") diff --git a/routes/bounty.go b/routes/bounty.go index 0b90ad220..7047995c4 100644 --- a/routes/bounty.go +++ b/routes/bounty.go @@ -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)