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 }