fix: add return statement & delete fmt Errorf with piece

This commit is contained in:
2026-06-23 15:58:46 +03:00
parent 3b2b4b947c
commit d8ea3094a1
3 changed files with 34 additions and 3 deletions
+30
View File
@@ -121,3 +121,33 @@ func GetAllOrders(c *gin.Context) {
c.JSON(http.StatusOK, orders)
}
func UpdateOrderStatus(c *gin.Context) {
orderID := c.Param("id")
var req struct {
Status string `json:"status" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Не указан статус заказа"})
return
}
if req.Status != "new" && req.Status != "packed" && req.Status != "delivered" && req.Status != "cancel" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Неверно указанный статус заказа"})
}
result := database.DB.Model(&models.Order{}).Where("id = ? ", orderID).Update("status", req.Status)
if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Ошибка при изменении статуса заказа"})
return
}
if result.RowsAffected == 0 {
c.JSON(http.StatusNotFound, gin.H{"error": "Заказ не найден"})
return
}
c.JSON(http.StatusAccepted, "Статус заказа успешно изменен")
}