Skip to content

Commit

Permalink
ticket versioning incorrect on ticket builder flow
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed Dec 17, 2024
1 parent fb68627 commit 8eb2e12
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions handlers/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,34 +556,46 @@ func (th *ticketHandler) ProcessTicketReview(w http.ResponseWriter, r *http.Requ
return
}

ticket, err := th.db.GetTicket(reviewReq.Value.TicketUUID)
existingTicket, err := th.db.GetTicket(reviewReq.Value.TicketUUID)
if err != nil {
log.Printf("Error fetching ticket: %v", err)
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"error": "Ticket not found"})
return
}

ticket.Description = reviewReq.Value.TicketDescription
ticket.UpdatedAt = time.Now()
newTicket := db.Tickets{
UUID: uuid.New(),
TicketGroup: existingTicket.TicketGroup,
FeatureUUID: existingTicket.FeatureUUID,
PhaseUUID: existingTicket.PhaseUUID,
Name: existingTicket.Name,
Sequence: existingTicket.Sequence,
Dependency: existingTicket.Dependency,
Description: reviewReq.Value.TicketDescription,
Status: existingTicket.Status,
Version: existingTicket.Version + 1,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

updatedTicket, err := th.db.UpdateTicket(ticket)
createdTicket, err := th.db.CreateOrEditTicket(&newTicket)
if err != nil {
log.Printf("Error updating ticket: %v", err)
log.Printf("Error creating new ticket: %v", err)
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to update ticket"})
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to create new ticket"})
return
}

ticketMsg := websocket.TicketMessage{
BroadcastType: "direct",
SourceSessionID: reviewReq.SourceWebsocket,
Message: fmt.Sprintf("Successful update of %s", reviewReq.Value.TicketUUID),
Message: fmt.Sprintf("Successfully created new version for ticket %s", createdTicket.UUID.String()),
Action: "process",
TicketDetails: websocket.TicketData{
FeatureUUID: reviewReq.Value.FeatureUUID,
PhaseUUID: reviewReq.Value.PhaseUUID,
TicketUUID: reviewReq.Value.TicketUUID,
TicketUUID: createdTicket.UUID.String(),
TicketDescription: reviewReq.Value.TicketDescription,
},
}
Expand All @@ -592,15 +604,15 @@ func (th *ticketHandler) ProcessTicketReview(w http.ResponseWriter, r *http.Requ
log.Printf("Failed to send websocket message: %v", err)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
"ticket": updatedTicket,
"ticket": createdTicket,
"websocket_error": err.Error(),
})
return
}

log.Printf("Successfully updated ticket %s", reviewReq.Value.TicketUUID)
log.Printf("Successfully created new ticket version %s", createdTicket.UUID.String())
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(updatedTicket)
json.NewEncoder(w).Encode(createdTicket)
}

func (th *ticketHandler) GetTicketsByPhaseUUID(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 8eb2e12

Please sign in to comment.