fix: add return statement & delete fmt Errorf with piece
This commit is contained in:
@@ -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, "Статус заказа успешно изменен")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user