fix: add unit type for piece items
This commit is contained in:
@@ -68,29 +68,35 @@ func UpdateItem(c *gin.Context) {
|
||||
}
|
||||
|
||||
database.DB.Model(&item).Updates(models.Item{
|
||||
Name: input.Name,
|
||||
Unit: input.Unit,
|
||||
City: input.City,
|
||||
Price: input.Price,
|
||||
Name: input.Name,
|
||||
Unit: input.Unit,
|
||||
UnitType: input.UnitType,
|
||||
City: input.City,
|
||||
Price: input.Price,
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, item)
|
||||
}
|
||||
|
||||
func AddItem(c *gin.Context) {
|
||||
var input models.Item
|
||||
var item models.Item
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
if err := c.ShouldBindJSON(&item); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Неверные данные"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.DB.Create(&input).Error; err != nil {
|
||||
if item.UnitType != "weight" && item.UnitType != "piece" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Товар должен быть весовым или штучным"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.DB.Create(&item).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Не удалось создать товар"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, input)
|
||||
c.JSON(http.StatusCreated, item)
|
||||
}
|
||||
|
||||
func DeleteItem(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user