fix: change backend hadlers, API route and uploads photo
This commit is contained in:
@@ -73,6 +73,8 @@ func UpdateItem(c *gin.Context) {
|
||||
UnitType: input.UnitType,
|
||||
City: input.City,
|
||||
Price: input.Price,
|
||||
Category: input.Category,
|
||||
Stock: input.Stock,
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, item)
|
||||
@@ -156,14 +158,14 @@ func UploadItemAvatar(c *gin.Context) {
|
||||
|
||||
resized := imaging.Resize(img, 1200, 0, imaging.Lanczos)
|
||||
uniqueName := uuid.New().String() + ".jpg"
|
||||
dstPath := filepath.Join("./uploads/items", uniqueName)
|
||||
dstPath := filepath.Join("./uploads/items/", uniqueName)
|
||||
|
||||
if err := imaging.Save(resized, dstPath, imaging.JPEGQuality(82)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Не удалось сохранить фотографию"})
|
||||
return
|
||||
}
|
||||
|
||||
item.AvatarURL = "/uploads/items" + uniqueName
|
||||
item.AvatarURL = uniqueName
|
||||
database.DB.Save(&item)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"avatar_url": item.AvatarURL})
|
||||
|
||||
Reference in New Issue
Block a user