diff --git a/db/db.go b/db/db.go index cdc056d8b..314dc45fc 100644 --- a/db/db.go +++ b/db/db.go @@ -1234,6 +1234,15 @@ func (db database) UpdateBountyPayment(b Bounty) (Bounty, error) { db.db.Model(&b).Where("created", b.Created).Updates(map[string]interface{}{ "paid": b.Paid, }) + db.db.Model(&b).Where("created", b.Created).Updates(b) + return b, nil +} + +func (db database) UpdateBountyCompleted(b Bounty) (Bounty, error) { + db.db.Model(&b).Where("created", b.Created).Updates(map[string]interface{}{ + "completed": b.Completed, + }) + db.db.Model(&b).Where("created", b.Created).Updates(b) return b, nil } diff --git a/handlers/bounty.go b/handlers/bounty.go index 5b37aec23..7ef6bd60d 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.CompletionDate = &now + bounty.Completed = true + } + db.DB.UpdateBountyCompleted(bounty) + } + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(bounty) +} + func (h *bountyHandler) GenerateBountyResponse(bounties []db.Bounty) []db.BountyResponse { var bountyResponse []db.BountyResponse @@ -370,6 +388,7 @@ func (h *bountyHandler) GenerateBountyResponse(bounties []db.Bounty) []db.Bounty OrgUuid: bounty.OrgUuid, Updated: bounty.Updated, CodingLanguages: bounty.CodingLanguages, + Completed: bounty.Completed, }, Assignee: db.Person{ ID: assignee.ID, 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 }