fix: change backend hadlers, API route and uploads photo

This commit is contained in:
2026-06-24 20:47:14 +03:00
parent 2c22cee60b
commit 115f52a8f1
5 changed files with 189 additions and 10 deletions
+4 -2
View File
@@ -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})
+2 -1
View File
@@ -41,7 +41,7 @@ func main() {
api.POST("/login", handlers.Login)
protected := api.Group("/")
api.GET("/items/:id", handlers.GetItem)
api.GET("/items/", handlers.GetAllItems)
api.GET("/items", handlers.GetAllItems)
api.GET("/getCategories", handlers.GetCategories)
api.POST("/register", handlers.Register)
protected.Use(middleware.AuthRequired())
@@ -66,6 +66,7 @@ func main() {
admin.POST("/register", handlers.RegisterAdmin)
admin.GET("/orders", handlers.GetAllOrders)
admin.PATCH("/orders/:id", handlers.UpdateOrderStatus)
admin.PATCH("/items/:id/avatar", handlers.UploadItemAvatar)
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB