add PATCH update delivery status by id
This commit is contained in:
@@ -160,6 +160,47 @@ func (h *Handler) UpdateDelivery(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Delivery updated"})
|
||||
}
|
||||
|
||||
// PATCH /api/deliveries/:id/status
|
||||
func (h *Handler) UpdateDeliveryStatus(c *gin.Context) {
|
||||
var req struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
if id == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID is required"})
|
||||
return
|
||||
}
|
||||
|
||||
parsedID, err := uuid.Parse(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid UUID format", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
status := req.Status
|
||||
if status == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Status is required"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.queries.UpdateDeliveryStatus(c.Request.Context(), sqlc.UpdateDeliveryStatusParams{
|
||||
ID: pgtype.UUID{Bytes: parsedID, Valid: true},
|
||||
Status: status,
|
||||
}); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update delivery status", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Delivery status updated"})
|
||||
}
|
||||
|
||||
// DELETE /api/deliveries/:id
|
||||
func (h *Handler) DeleteDelivery(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
Reference in New Issue
Block a user