You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current Tickets has been updated to accommodate additional optional fields: ticketGroup, author, and authorID. to support versioning.
This will update the ticket update endpoint r.Post("/{uuid}", ticketHandler.UpdateTicket) -> to ensure that on update we keep the old version of the ticket and update the new ticket in the correct ticket group.
Example flow:
User edits an existing ticket ticket = ID1, Version = 1, group = 1 in the ticket editor UI.
These changes are submitted to the updateTicket endpoint as a ticket update with a new description.
Instead of updating the specific ticketUUID record (current behaivour) we do the following:
a. get the current details of ticket that was updated
b. generate a new ticket with a new ID
c. copy the existing metadata from the original ticket
d. update with the new ticket title | description | author | authorID
e. set ticketgroupID to the previous tickets ticketGroupUUID
f. Set version as +1 on the ticket.
Task
Ensure that on submission of a new ticket for update create a new record associated as a version of the previous ticket through the ticketGroup
Ensure correct unmarshalling against structs
Esnure we are correctly setting author and author ID as sent from the front end update.
Outcome
updateTicket will now create a new ticket record, increment the version number and ensure a ticketgroup is retained.
Design
Example Code
// Current Ticket struct with new fields
type Ticket struct {
UUID uuid.UUID `json:"uuid" gorm:"type:uuid;primary_key"`
Title string `json:"title"`
Description string `json:"description"`
Status string `json:"status"`
TicketGroup uuid.UUID `json:"ticketGroup" gorm:"type:uuid;index"`
Version int `json:"version" gorm:"not null"`
Author string `json:"author"`
AuthorID string `json:"authorId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Example of new updateTicket implementation
func (h *TicketHandler) UpdateTicket(w http.ResponseWriter, r *http.Request) {
// Parse ticket UUID from request
ticketUUID := chi.URLParam(r, "uuid")
if ticketUUID == "" {
http.Error(w, "missing ticket UUID", http.StatusBadRequest)
return
}
// Parse update request body
var updateRequest Ticket
if err := json.NewDecoder(r.Body).Decode(&updateRequest); err != nil {
http.Error(w, fmt.Sprintf("invalid request body: %v", err), http.StatusBadRequest)
return
}
// Get existing ticket
existingTicket, err := h.db.GetTicket(uuid.MustParse(ticketUUID))
if err != nil {
http.Error(w, fmt.Sprintf("failed to fetch ticket: %v", err), http.StatusNotFound)
return
}
// Create new version of ticket
newTicket := Ticket{
UUID: uuid.New(),
Title: updateRequest.Title,
Description: updateRequest.Description,
Status: updateRequest.Status,
TicketGroup: existingTicket.TicketGroup,
Version: existingTicket.Version + 1,
Author: updateRequest.Author,
AuthorID: updateRequest.AuthorID,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
// Save new ticket version
savedTicket, err := h.db.CreateTicket(newTicket)
if err != nil {
http.Error(w, fmt.Sprintf("failed to create new ticket version: %v", err), http.StatusInternalServerError)
return
}
// Return new ticket version
json.NewEncoder(w).Encode(savedTicket)
}
Acceptance Criteria
When updating a ticket, a new record is created instead of modifying the existing record
New ticket maintains the same ticketGroup as the original ticket
Version number is incremented by 1 from the previous version
Author and AuthorID from the update request are correctly stored in the new version
Original ticket remains unchanged in the database
API response includes the complete new ticket version details
All existing ticket metadata (other than the updated fields) is correctly copied to the new version
Error handling provides appropriate HTTP status codes and messages
The text was updated successfully, but these errors were encountered:
@MahtabBukhari we have some staging issues today so just paying out bounties for now given PRs are in.
Will test once we're back up and running and then add bugs if required.
Context
The current
Tickets
has been updated to accommodate additional optional fields:ticketGroup
,author
, andauthorID
. to support versioning.This will update the ticket update endpoint
r.Post("/{uuid}", ticketHandler.UpdateTicket) ->
to ensure that on update we keep the old version of the ticket and update the new ticket in the correct ticket group.Example flow:
ticket = ID1, Version = 1, group = 1
in the ticket editor UI.a. get the current details of ticket that was updated
b. generate a new ticket with a new ID
c. copy the existing metadata from the original ticket
d. update with the new ticket title | description | author | authorID
e. set ticketgroupID to the previous tickets ticketGroupUUID
f. Set version as +1 on the ticket.
Task
Outcome
updateTicket will now create a new ticket record, increment the version number and ensure a ticketgroup is retained.
Design
Example Code
Acceptance Criteria
The text was updated successfully, but these errors were encountered: