From ce569ae6391424deeaaeb6bab5f707a38ed3dcae Mon Sep 17 00:00:00 2001 From: elraphty Date: Mon, 8 Apr 2024 13:30:25 +0100 Subject: [PATCH] added completed status --- handlers/bounty.go | 18 ++++++++++++++++++ routes/bounty.go | 1 + 2 files changed, 19 insertions(+) diff --git a/handlers/bounty.go b/handlers/bounty.go index 5b37aec23..1ffe7afcf 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -333,6 +333,24 @@ func UpdatePaymentStatus(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(bounty) } +func UpdateCompletedStatus(w http.ResponseWriter, r *http.Request) { + createdParam := chi.URLParam(r, "created") + created, _ := strconv.ParseUint(createdParam, 10, 32) + + bounty, _ := db.DB.GetBountyByCreated(uint(created)) + if bounty.ID != 0 && bounty.Created == int64(created) { + now := time.Now() + // set bounty as completed + if !bounty.Paid && !bounty.Completed { + bounty.Completed = true + bounty.CompletionDate = &now + } + db.DB.UpdateBountyPayment(bounty) + } + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(bounty) +} + func (h *bountyHandler) GenerateBountyResponse(bounties []db.Bounty) []db.BountyResponse { var bountyResponse []db.BountyResponse diff --git a/routes/bounty.go b/routes/bounty.go index 6e5049747..1158a6a8d 100644 --- a/routes/bounty.go +++ b/routes/bounty.go @@ -38,6 +38,7 @@ func BountyRoutes() chi.Router { r.Delete("/assignee", handlers.DeleteBountyAssignee) r.Delete("/{pubkey}/{created}", bountyHandler.DeleteBounty) r.Post("/paymentstatus/{created}", handlers.UpdatePaymentStatus) + r.Post("/completedstatus/{created}", handlers.UpdateCompletedStatus) }) return r }