fix(front,back) Добавил на бек выгрузку категорий, начало разработки shop

This commit is contained in:
2026-06-09 15:42:18 +03:00
parent ea70e6914e
commit 04b1be4c54
5 changed files with 57 additions and 5 deletions
+13
View File
@@ -88,3 +88,16 @@ func DeleteItem(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Товар успешно удален"})
}
func GetCategories(c *gin.Context) {
var item models.Item
var categories []string
err := database.DB.Model(&item).Where("category IS NOT NULL AND category != ''").Distinct().Pluck("category", &categories).Error
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, categories)
}
+1
View File
@@ -44,6 +44,7 @@ func main() {
protected.DELETE("/items/:id", handlers.DeleteItem)
protected.PATCH("/items/:id", handlers.UpdateItem)
protected.POST("/items", handlers.AddItem)
protected.GET("/getCategories", handlers.GetCategories)
}
admin := protected.Group("/")