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, использую системные переменные")
+11 -6
View File
@@ -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"`
}
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