Skip to content

Commit

Permalink
added completed status
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Apr 8, 2024
1 parent f196707 commit ce569ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions routes/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ce569ae

Please sign in to comment.