Skip to content

Commit

Permalink
Merge pull request #1609 from stakwork/feat/mark_as_completed
Browse files Browse the repository at this point in the history
Added bounty completed functionality
  • Loading branch information
elraphty authored Apr 8, 2024
2 parents f196707 + 8ef3264 commit 3a238ad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 19 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.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

Expand Down Expand Up @@ -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,
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 3a238ad

Please sign in to comment.