sphinx-tribes icon indicating copy to clipboard operation
sphinx-tribes copied to clipboard

Create handler GetTickets (ByPhaseUUID)

Open humansinstitute opened this issue 1 year ago • 2 comments

Context

This handler will interact with a utility function "GetTicketsByPhase" (https://github.com/stakwork/sphinx-tribes/issues/1984) to return an array of ticket objects for a given Phase UUID. This can be utilised to load up the ticket plan for a specific phase.

Task

Create a handler function that retrieves ticket UUIDs using GetTicketsByPhase based on feature UUID and phase UUID parameters.

Outcome

A simplified handler that delegates database operations to the utility function.

Design

// handlers/feature/tickets.go
package feature

import (
    "net/http"
    "encoding/json"
)

type TicketsResponse struct {
    Success bool     `json:"success"`
    Tickets []string `json:"tickets"`
    Error   string  `json:"error,omitempty"`
}

func GetTickets(w http.ResponseWriter, r *http.Request) {
    // Get parameters from URL
    featureUUID := chi.URLParam(r, "featureUUID")
    phaseUUID := chi.URLParam(r, "phaseUUID")

    // Validate UUIDs
    if !isValidUUID(featureUUID) || !isValidUUID(phaseUUID) {
        respondWithError(w, http.StatusBadRequest, "Invalid UUID format")
        return
    }

    // Use utility function to get tickets
    tickets, err := utils.GetTicketsByPhase(phaseUUID) //TO BE IMPLEMENTED IN SEPERATE TICKET
    if err != nil {
        respondWithError(w, http.StatusInternalServerError, "Failed to fetch tickets")
        return
    }

    // Extract UUIDs for response
    ticketUUIDs := make([]string, len(tickets))
    for i, ticket := range tickets {
        ticketUUIDs[i] = ticket.UUID
    }

    // Return response
    respondWithJSON(w, http.StatusOK, TicketsResponse{
        Success: true,
        Tickets: ticketUUIDs,
    })
}

Acceptance Criteria

  • [ ] Handler successfully uses GetTicketsByPhase utility function
  • [ ] UUID validation in place
  • [ ] HTTP status codes are correctly set:
    • 200: Successful retrieval
    • 400: Invalid UUID
    • 500: Database/Server errors
  • [ ] Response headers are properly set

humansinstitute avatar Nov 27 '24 05:11 humansinstitute

@humansinstitute, Please assign me?

MuhammadUmer44 avatar Nov 27 '24 05:11 MuhammadUmer44

@humansinstitute, I can help?

AbuBakar877 avatar Nov 27 '24 05:11 AbuBakar877