Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ticket Endpoint will require new logic to create a version and associate ticket group #2182

Closed
8 tasks
Tracked by #2131
humansinstitute opened this issue Dec 13, 2024 · 3 comments · Fixed by #2184
Closed
8 tasks
Tracked by #2131
Assignees

Comments

@humansinstitute
Copy link
Contributor

humansinstitute commented Dec 13, 2024

Context

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:

  1. User edits an existing ticket ticket = ID1, Version = 1, group = 1 in the ticket editor UI.
  2. These changes are submitted to the updateTicket endpoint as a ticket update with a new description.
  3. 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
@MahtabBukhari
Copy link
Contributor

@humansinstitute please assign

@humansinstitute
Copy link
Contributor Author

@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.

@MahtabBukhari
Copy link
Contributor

@humansinstitute sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants