From 04b1be4c5450a2d6921156356ddb4ade8a1a1f3a Mon Sep 17 00:00:00 2001 From: LeonG11 Date: Tue, 9 Jun 2026 15:42:18 +0300 Subject: [PATCH] =?UTF-8?q?fix(front,back)=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=BD=D0=B0=20=D0=B1=D0=B5=D0=BA=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9,=20=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=D0=BB=D0=BE=20=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20shop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/handlers/item_handlers.go | 13 ++++++++++++ backend/main.go | 1 + frontend/src/api/index.js | 2 ++ frontend/src/pages/About.jsx | 12 +++++++++++ frontend/src/pages/Shop.jsx | 34 ++++++++++++++++++++++++++----- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/backend/handlers/item_handlers.go b/backend/handlers/item_handlers.go index 8db1bc7..0bff0bd 100644 --- a/backend/handlers/item_handlers.go +++ b/backend/handlers/item_handlers.go @@ -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) +} diff --git a/backend/main.go b/backend/main.go index cb98e12..c6fd820 100644 --- a/backend/main.go +++ b/backend/main.go @@ -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("/") diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 2f726ca..14c6330 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -36,3 +36,5 @@ export const updateItem = (id, itemData) => axios.patch(`${API_URL}/items/${id}`, itemData); export const deleteItem = (id) => axios.delete(`${API_URL}/items/${id}`); + +export const getAllCategories = () => axios.get(`${API_URL}/getCategory`) diff --git a/frontend/src/pages/About.jsx b/frontend/src/pages/About.jsx index 14f1742..148d753 100644 --- a/frontend/src/pages/About.jsx +++ b/frontend/src/pages/About.jsx @@ -1,6 +1,18 @@ import PageLayout from "../components/PageLayout"; +import { useState, useEffect } from "react" +import * as api from '../api/index' export default function Shop() { + + const [items, setItems] = useState([]) + const [loading, setLoading] = useState(true); + + useEffect(() => { + pa + }) + + + return (
diff --git a/frontend/src/pages/Shop.jsx b/frontend/src/pages/Shop.jsx index 14f1742..efb935d 100644 --- a/frontend/src/pages/Shop.jsx +++ b/frontend/src/pages/Shop.jsx @@ -1,14 +1,38 @@ import PageLayout from "../components/PageLayout"; +import * as api from "../api/index"; +import { useState, useEffect } from "react"; export default function Shop() { + const [items, setItems] = useState([]); + const [categories, setCategories] = useState([]); + const [activeCategory, setActiveCategory] = useState("all"); + const [loading, setLoading] = useState(true); + + useEffect(() => { + Promise.all([api.getAllItems(), api.getAllCategories()]) + .then((itemsRes, categoriesRes) => { + setItems(itemsRes.data); + setCategories(categoriesRes.data); + setLoading(false); + }) + .catch((err) => { + console.error("Ошибка при загрузке товара", err); + setLoading(false); + }); + }, []); + + const filteredItems = + activeCategory === "all" + ? items + : items.fitler( + (item) => + item.category?.toLowerCase() === activeCategory.toLowerCase(), + ); + return (
-
-
-

fish fish

-
-
+
);