fix(all) Добавил раздачу картинок через бекенд
@@ -18,6 +18,7 @@ FROM alpine:latest
|
||||
WORKDIR /root/
|
||||
|
||||
COPY --from=builder /app/main .
|
||||
COPY --from=builder /app/uploads ./uploads
|
||||
|
||||
EXPOSE 8090
|
||||
CMD ["./main"]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ func main() {
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
r.Static("/static", "./uploads")
|
||||
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Println("Файл .env не был найден в папке backend, использую системные переменные")
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 9.8 MiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 741 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 328 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 279 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 52 KiB |