Skip to content

Commit

Permalink
bounty cards route handler response
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed Dec 23, 2024
1 parent 7d1fee9 commit 554b9f8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,15 @@ type FilterStattuCount struct {
Failed int64 `json:"failed"`
}

type BountyCard struct {
BountyID uint `json:"id"`
Title string `json:"title"`
AssigneePic string `json:"assignee_img,omitempty"`
Features WorkspaceFeatures `json:"features"`
Phase FeaturePhase `json:"phase"`
Workspace Workspace `json:"workspace"`
}

type WfRequestStatus string

const (
Expand Down
42 changes: 42 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,3 +1491,45 @@ func GetFilterCount(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(filterCount)
}

func (h *bountyHandler) GetBountyCards(w http.ResponseWriter, r *http.Request) {
bounties := h.db.GetAllBounties(r)
var bountyCardResponse []db.BountyCard = h.GenerateBountyCardResponse(bounties)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyCardResponse)
}

func (h *bountyHandler) GenerateBountyCardResponse(bounties []db.NewBounty) []db.BountyCard {
var bountyCardResponse []db.BountyCard

for i := 0; i < len(bounties); i++ {
bounty := bounties[i]

assignee := h.db.GetPersonByPubkey(bounty.Assignee)
workspace := h.db.GetWorkspaceByUuid(bounty.WorkspaceUuid)

var phase db.FeaturePhase
var feature db.WorkspaceFeatures

if bounty.PhaseUuid != "" {
phase, _ = h.db.GetPhaseByUuid(bounty.PhaseUuid)
}

if phase.FeatureUuid != "" {
feature = h.db.GetFeatureByUuid(phase.FeatureUuid)
}
b := db.BountyCard{
BountyID: bounty.ID,
Title: bounty.Title,
AssigneePic: assignee.Img,
Features: feature,
Phase: phase,
Workspace: workspace,
}

bountyCardResponse = append(bountyCardResponse, b)
}

return bountyCardResponse
}
1 change: 1 addition & 0 deletions routes/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func BountyRoutes() chi.Router {
r.Group(func(r chi.Router) {
r.Use(auth.PubKeyContext)

r.Get("/bounty-cards", bountyHandler.GetBountyCards)
r.Post("/budget/withdraw", bountyHandler.BountyBudgetWithdraw)
r.Post("/pay/{id}", bountyHandler.MakeBountyPayment)
r.Get("/payment/status/{id}", bountyHandler.GetBountyPaymentStatus)
Expand Down

0 comments on commit 554b9f8

Please sign in to comment.