Skip to content

Commit c6762d9

Browse files
Merge pull request #2683 from aliraza556/feature/bounty-stake-process-by-bounty-id
Add endpoint to retrieve bounty stake processes by bounty ID
2 parents fca7cf9 + a3d09fc commit c6762d9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

handlers/bounty.go

+22
Original file line numberDiff line numberDiff line change
@@ -3315,3 +3315,25 @@ func (h *bountyHandler) DeleteBountyStakeProcess(w http.ResponseWriter, r *http.
33153315
w.WriteHeader(http.StatusOK)
33163316
json.NewEncoder(w).Encode(map[string]string{"message": "Stake process deleted successfully"})
33173317
}
3318+
3319+
func (h *bountyHandler) GetBountyStakeProcessesByBountyID(w http.ResponseWriter, r *http.Request) {
3320+
bountyIDStr := chi.URLParam(r, "bountyId")
3321+
bountyID, err := strconv.ParseUint(bountyIDStr, 10, 32)
3322+
if err != nil {
3323+
logger.Log.Error("[bounty_stake_process] invalid bounty ID: %v", err)
3324+
w.WriteHeader(http.StatusBadRequest)
3325+
json.NewEncoder(w).Encode(map[string]string{"error": "Invalid bounty ID format"})
3326+
return
3327+
}
3328+
3329+
processes, err := h.db.GetBountyStakeProcessesByBountyID(uint(bountyID))
3330+
if err != nil {
3331+
logger.Log.Error("[bounty_stake_process] failed to get stake processes: %v", err)
3332+
w.WriteHeader(http.StatusInternalServerError)
3333+
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
3334+
return
3335+
}
3336+
3337+
w.WriteHeader(http.StatusOK)
3338+
json.NewEncoder(w).Encode(processes)
3339+
}

routes/bounty.go

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func BountyRoutes() chi.Router {
7676
r.Post("/stake/stakeprocessing", bountyHandler.CreateBountyStakeProcess)
7777
r.Get("/stake/stakeprocessing", bountyHandler.GetAllBountyStakeProcesses)
7878
r.Get("/stake/stakeprocessing/{id}", bountyHandler.GetBountyStakeProcessByID)
79+
r.Get("/stake/stakeprocessing/bounty/{bountyId}", bountyHandler.GetBountyStakeProcessesByBountyID)
7980
r.Put("/stake/stakeprocessing/{id}", bountyHandler.UpdateBountyStakeProcess)
8081
r.Delete("/stake/stakeprocessing/{id}", bountyHandler.DeleteBountyStakeProcess)
8182
})

0 commit comments

Comments
 (0)