Skip to content

Commit

Permalink
Merge pull request stakwork#2476 from aliraza556/feature/delete-ticke…
Browse files Browse the repository at this point in the history
…t-after-bounty-creation

Delete ticket after successful bounty creation
  • Loading branch information
elraphty authored Jan 21, 2025
2 parents 9ac2313 + 4018254 commit 6772655
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
21 changes: 20 additions & 1 deletion handlers/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,31 @@ func (th *ticketHandler) TicketToBounty(w http.ResponseWriter, r *http.Request)
"bounty_id", bounty.ID,
"owner_id", bounty.OwnerID)

// Delete the ticket after successful bounty creation
if err := th.db.DeleteTicket(ticketUUID); err != nil {
logger.Log.Error("failed to delete ticket after bounty creation",
"error", err,
"ticket_uuid", ticketUUID)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(CreateBountyResponse{
BountyID: bounty.ID,
Success: true,
Message: "Bounty created successfully, but failed to delete original ticket",
})
return
}

logger.Log.Info("ticket deleted successfully after bounty creation",
"ticket_uuid", ticketUUID)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(CreateBountyResponse{
BountyID: bounty.ID,
Success: true,
Message: "Bounty created successfully",
Message: "Bounty created successfully and ticket deleted",
})
}

Expand Down
11 changes: 8 additions & 3 deletions handlers/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestTicketToBounty(t *testing.T) {
wantCode: http.StatusNotFound,
},
{
name: "success - creates bounty from ticket",
name: "success - creates bounty from ticket and deletes ticket",
ticket: createdTicket.UUID.String(),
auth: workspace.OwnerPubKey,
wantCode: http.StatusCreated,
Expand All @@ -551,16 +551,21 @@ func TestTicketToBounty(t *testing.T) {

assert.True(t, resp.Success)
assert.NotZero(t, resp.BountyID)
assert.Equal(t, "Bounty created successfully", resp.Message)
assert.Equal(t, "Bounty created successfully and ticket deleted", resp.Message)

// Verify bounty was created correctly
bounty := db.TestDB.GetBounty(resp.BountyID)

assert.Equal(t, createdTicket.Name, bounty.Title)
assert.Equal(t, createdTicket.Description, bounty.Description)
assert.Equal(t, createdTicket.PhaseUUID, bounty.PhaseUuid)
assert.Equal(t, "freelance_job_request", bounty.Type)
assert.Equal(t, uint(21), bounty.Price)
assert.True(t, bounty.Show)

// Verify ticket was deleted
_, err := db.TestDB.GetTicket(createdTicket.UUID.String())
assert.Error(t, err)
assert.Equal(t, "ticket not found", err.Error())
},
},
}
Expand Down

0 comments on commit 6772655

Please sign in to comment.