fix(all) Добавил раздачу картинок через бекенд

This commit is contained in:
2026-06-16 16:22:51 +03:00
parent 15efab81a4
commit 483abc80dc
23 changed files with 44 additions and 29 deletions
+1
View File
@@ -18,6 +18,7 @@ FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
COPY --from=builder /app/uploads ./uploads
EXPOSE 8090
CMD ["./main"]
+15
View File
@@ -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)
}
+2
View File
@@ -17,6 +17,8 @@ func main() {
r := gin.Default()
r.Static("/static", "./uploads")
err := godotenv.Load()
if err != nil {
log.Println("Файл .env не был найден в папке backend, использую системные переменные")
+5
View File
@@ -1,5 +1,7 @@
package models
import "time"
type Item struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
@@ -7,4 +9,7 @@ type Item struct {
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"`
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

+4
View File
@@ -21,6 +21,10 @@ server {
proxy_pass http://backend:8081;
}
location /static {
proxy_pass http://backend:8081;
}
# Сама статика React
location / {
root /usr/share/nginx/html;
+1 -16
View File
@@ -20,22 +20,7 @@ export default function CardItem({ item, onAddToCart }) {
return (
<div className="flex flex-col text-white w-full">
<div className="w-full rounded-md overflow-hidden bg-slate-800/60 flex flex-col h-100 items-center justify-center border border-slate-700/50 select-none">
<svg
className="w-12 h-12 text-slate-600 mb-2"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 002-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
<span className="text-xs text-slate-500 font-medium uppercase tracking-wider">
Изображение товара
</span>
<img src={item.avatar_url} alt={item.name} className="object-cover" />
</div>
{/* Блок с информацией о товаре */}
+4 -1
View File
@@ -4,13 +4,16 @@ export default function Contact() {
return (
<PageLayout>
<main className="px-6 md:px-16 grow w-full mb-6">
<div>
<div className="text-2xl text-white">Контакты</div>
<div className="w-full overflow-hidden rounded shadow-md ">
<iframe
src="https://yandex.ru/map-widget/v1/?um=constructor%3Aaee46827fd51e482587f99245635b92b3d473b8d2aef2b4e36f83ddfaaf77cb9&amp;source=constructor"
className="w-full h-127.5 border-0 "
className="w-full h-127.5 md:h-[340px] border-0"
title="Yandex Map"
/>
</div>
</div>
</main>
</PageLayout>
);