diff --git a/backend/Dockerfile b/backend/Dockerfile index 9570b67..317a16b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -18,6 +18,7 @@ FROM alpine:latest WORKDIR /root/ COPY --from=builder /app/main . +COPY --from=builder /app/uploads ./uploads EXPOSE 8090 CMD ["./main"] diff --git a/backend/handlers/item_handlers.go b/backend/handlers/item_handlers.go index 77246ab..f173b10 100644 --- a/backend/handlers/item_handlers.go +++ b/backend/handlers/item_handlers.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -19,6 +20,12 @@ func GetItem(c *gin.Context) { return } + if item.AvatarURL != "" { + item.AvatarURL = fmt.Sprintf("/static/items/%s", item.AvatarURL) + } else { + item.AvatarURL = fmt.Sprintf("/static/items/background.png") + } + c.JSON(http.StatusOK, item) } @@ -30,6 +37,14 @@ func GetAllItems(c *gin.Context) { return } + for i := range items { + if items[i].AvatarURL != "" { + items[i].AvatarURL = fmt.Sprintf("/static/items/%s", items[i].AvatarURL) + } else { + items[i].AvatarURL = fmt.Sprintf("/static/items/background.png") + } + } + c.JSON(http.StatusOK, items) } diff --git a/backend/main.go b/backend/main.go index 6211fa7..892b608 100644 --- a/backend/main.go +++ b/backend/main.go @@ -17,6 +17,8 @@ func main() { r := gin.Default() + r.Static("/static", "./uploads") + err := godotenv.Load() if err != nil { log.Println("Файл .env не был найден в папке backend, использую системные переменные") diff --git a/backend/models/item.go b/backend/models/item.go index d0dc299..de4cd18 100644 --- a/backend/models/item.go +++ b/backend/models/item.go @@ -1,10 +1,15 @@ package models +import "time" + type Item struct { - ID uint `gorm:"primaryKey" json:"id"` - Name string `json:"name"` - City string `json:"city"` - Unit string `json:"unit"` - Price int `json:"price"` - Category string `json:"category"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `json:"name"` + City string `json:"city"` + Unit string `json:"unit"` + Price int `json:"price"` + Category string `json:"category"` + Stock float64 `gorm:"default:0" json:"stock"` + AvatarURL string `json:"avatar_url"` + CreatedAt time.Time `json:"created_at"` } diff --git a/backend/uploads/items/background.png b/backend/uploads/items/background.png new file mode 100644 index 0000000..a4f4d93 Binary files /dev/null and b/backend/uploads/items/background.png differ diff --git a/backend/uploads/items/calamar.jpg b/backend/uploads/items/calamar.jpg new file mode 100644 index 0000000..6b99be6 Binary files /dev/null and b/backend/uploads/items/calamar.jpg differ diff --git a/backend/uploads/items/cancer.jpg b/backend/uploads/items/cancer.jpg new file mode 100644 index 0000000..ec7f44a Binary files /dev/null and b/backend/uploads/items/cancer.jpg differ diff --git a/backend/uploads/items/cancer2.jpg b/backend/uploads/items/cancer2.jpg new file mode 100644 index 0000000..3c12099 Binary files /dev/null and b/backend/uploads/items/cancer2.jpg differ diff --git a/backend/uploads/items/fish1.jpg b/backend/uploads/items/fish1.jpg new file mode 100644 index 0000000..f07f311 Binary files /dev/null and b/backend/uploads/items/fish1.jpg differ diff --git a/backend/uploads/items/fish2.png b/backend/uploads/items/fish2.png new file mode 100644 index 0000000..cbf6d4c Binary files /dev/null and b/backend/uploads/items/fish2.png differ diff --git a/backend/uploads/items/lobster.jpg b/backend/uploads/items/lobster.jpg new file mode 100644 index 0000000..6ae4a97 Binary files /dev/null and b/backend/uploads/items/lobster.jpg differ diff --git a/backend/uploads/items/logo.png b/backend/uploads/items/logo.png new file mode 100644 index 0000000..23d6c2f Binary files /dev/null and b/backend/uploads/items/logo.png differ diff --git a/backend/uploads/items/ouster.jpg b/backend/uploads/items/ouster.jpg new file mode 100644 index 0000000..0af3a3e Binary files /dev/null and b/backend/uploads/items/ouster.jpg differ diff --git a/backend/uploads/items/salmon.jpg b/backend/uploads/items/salmon.jpg new file mode 100644 index 0000000..d5a9861 Binary files /dev/null and b/backend/uploads/items/salmon.jpg differ diff --git a/backend/uploads/items/shell.jpg b/backend/uploads/items/shell.jpg new file mode 100644 index 0000000..da82705 Binary files /dev/null and b/backend/uploads/items/shell.jpg differ diff --git a/backend/uploads/items/shell2.jpg b/backend/uploads/items/shell2.jpg new file mode 100644 index 0000000..1505adf Binary files /dev/null and b/backend/uploads/items/shell2.jpg differ diff --git a/backend/uploads/items/shell3.jpg b/backend/uploads/items/shell3.jpg new file mode 100644 index 0000000..091ebe4 Binary files /dev/null and b/backend/uploads/items/shell3.jpg differ diff --git a/backend/uploads/items/shrimps.jpg b/backend/uploads/items/shrimps.jpg new file mode 100644 index 0000000..6b796c4 Binary files /dev/null and b/backend/uploads/items/shrimps.jpg differ diff --git a/backend/uploads/items/tuna.jpg b/backend/uploads/items/tuna.jpg new file mode 100644 index 0000000..4209f70 Binary files /dev/null and b/backend/uploads/items/tuna.jpg differ diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a249892..262542c 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -21,6 +21,10 @@ server { proxy_pass http://backend:8081; } + location /static { + proxy_pass http://backend:8081; + } + # Сама статика React location / { root /usr/share/nginx/html; diff --git a/frontend/src/components/CardItem.jsx b/frontend/src/components/CardItem.jsx index 46b64c6..cf0a651 100644 --- a/frontend/src/components/CardItem.jsx +++ b/frontend/src/components/CardItem.jsx @@ -20,22 +20,7 @@ export default function CardItem({ item, onAddToCart }) { return (
- - - - - Изображение товара - + {item.name}
{/* Блок с информацией о товаре */} diff --git a/frontend/src/pages/About.jsx b/frontend/src/pages/About.jsx index 21b5595..de1bfd7 100644 --- a/frontend/src/pages/About.jsx +++ b/frontend/src/pages/About.jsx @@ -5,7 +5,7 @@ export default function Shop() { return (
-
+
fish fish
diff --git a/frontend/src/pages/Contact.jsx b/frontend/src/pages/Contact.jsx index e35762e..6f5cfc1 100644 --- a/frontend/src/pages/Contact.jsx +++ b/frontend/src/pages/Contact.jsx @@ -4,12 +4,15 @@ export default function Contact() { return (
-
-