Skip to content

Commit

Permalink
Merge pull request #2037 from aliraza556/fix-ticket-review-unmarshal-…
Browse files Browse the repository at this point in the history
…stakwork

[BUG] Fix Stakwork TicketReview Unmarshalling and Remove Pubkey Authentication for `bounties/ticket/review` Route
  • Loading branch information
humansinstitute authored Dec 2, 2024
2 parents 8754727 + 15cb5bb commit 9f1041c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
8 changes: 5 additions & 3 deletions handlers/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/google/uuid"
Expand Down Expand Up @@ -383,15 +384,16 @@ func (th *ticketHandler) ProcessTicketReview(w http.ResponseWriter, r *http.Requ
return
}

ticket, err := th.db.GetTicket(reviewReq.TicketUUID)
ticket, 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.TicketDescription
ticket.Description = reviewReq.Value.TicketDescription
ticket.UpdatedAt = time.Now()

updatedTicket, err := th.db.UpdateTicket(ticket)
if err != nil {
Expand All @@ -401,7 +403,7 @@ func (th *ticketHandler) ProcessTicketReview(w http.ResponseWriter, r *http.Requ
return
}

log.Printf("Successfully updated ticket %s", reviewReq.TicketUUID)
log.Printf("Successfully updated ticket %s", reviewReq.Value.TicketUUID)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(updatedTicket)
}
Expand Down
8 changes: 2 additions & 6 deletions routes/ticket_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ func TicketRoutes() chi.Router {
r := chi.NewRouter()
ticketHandler := handlers.NewTicketHandler(http.DefaultClient, db.DB)

r.Options("/*", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

r.Group(func(r chi.Router) {
r.Get("/{uuid}", ticketHandler.GetTicket)
r.Post("/review", ticketHandler.ProcessTicketReview)
})

r.Group(func(r chi.Router) {
r.Use(auth.PubKeyContext)

r.Get("/feature/{feature_uuid}/phase/{phase_uuid}", ticketHandler.GetTicketsByPhaseUUID)
r.Post("/review/send", ticketHandler.PostTicketDataToStakwork)
r.Post("/review", ticketHandler.ProcessTicketReview)

r.Post("/{uuid}", ticketHandler.UpdateTicket)

r.Delete("/{uuid}", ticketHandler.DeleteTicket)
})

Expand Down
13 changes: 9 additions & 4 deletions utils/ticket_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import (
)

type TicketReviewRequest struct {
TicketUUID string `json:"ticketUUID" validate:"required"`
TicketDescription string `json:"ticketDescription" validate:"required"`
Value struct {
FeatureUUID string `json:"featureUUID"`
PhaseUUID string `json:"phaseUUID"`
TicketUUID string `json:"ticketUUID" validate:"required"`
TicketDescription string `json:"ticketDescription" validate:"required"`
} `json:"value"`
RequestUUID string `json:"requestUUID"`
}

func ValidateTicketReviewRequest(req *TicketReviewRequest) error {
if req.TicketUUID == "" {
if req.Value.TicketUUID == "" {
return errors.New("ticketUUID is required")
}
if req.TicketDescription == "" {
if req.Value.TicketDescription == "" {
return errors.New("ticketDescription is required")
}
return nil
Expand Down

0 comments on commit 9f1041c

Please sign in to comment.