ft/adds docker-compose volumes prepares fileupload
- Files should be saved into subdirs
This commit is contained in:
parent
d7b4f66e38
commit
3d6d87854e
@ -7,6 +7,7 @@ RUN go build -o main main.go
|
||||
# Run stage
|
||||
FROM alpine:3.18
|
||||
WORKDIR /app
|
||||
RUN mkdir files
|
||||
COPY --from=builder /app/main .
|
||||
COPY app.env .
|
||||
ENV DB_SOURCE=postgresql://root:secret@postgres:5432/df?sslmode=disable
|
||||
|
@ -8,8 +8,8 @@ services:
|
||||
- POSTGRES_DB=df
|
||||
ports:
|
||||
- "5432:5432"
|
||||
# volumes:
|
||||
# - ./db/migration:/docker-entrypoint-initdb.d
|
||||
volumes:
|
||||
- data-volume:/var/lib/postgresql/data
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
@ -17,8 +17,13 @@ services:
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./files:/app/files/:Z
|
||||
environment:
|
||||
- DB_SOURCE=postgresql://root:secret@postgres:5432/df?sslmode=disable
|
||||
depends_on:
|
||||
- postgres
|
||||
command: [ "/app/main" ]
|
||||
|
||||
volumes:
|
||||
data-volume:
|
@ -11,6 +11,11 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// type uploadDocumentRequest struct {
|
||||
// PersonID uint64 `json:"person_id"`
|
||||
// MailID uint64 `json:"mail_id"`
|
||||
// }
|
||||
|
||||
func (server *Server) UploadDocument(ctx *gin.Context) {
|
||||
authHeader := ctx.GetHeader("authorization")
|
||||
|
||||
@ -35,13 +40,36 @@ func (server *Server) UploadDocument(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: FileUpload with POST-Values
|
||||
// bodyData, _ := io.ReadAll(ctx.Request.Body)
|
||||
// slog.Info("Document", slog.String("body", fmt.Sprintf("%#v", string(bodyData))))
|
||||
|
||||
file, err := ctx.FormFile("file")
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, errorResponse(errors.New("could not parse file")))
|
||||
return
|
||||
}
|
||||
|
||||
p := filepath.Join("./files", fmt.Sprintf("%d", account.ID), file.Filename)
|
||||
targetDir := filepath.Join("./files", fmt.Sprintf("%d", account.ID))
|
||||
|
||||
// var req *uploadDocumentRequest
|
||||
// _ = ctx.ShouldBindJSON(&req)
|
||||
|
||||
// if req != nil {
|
||||
// if req.MailID <= 0 && req.PersonID <= 0 {
|
||||
// ctx.JSON(http.StatusBadRequest, errorResponse(errors.New("document can't be assigned to both person_id AND mail_id")))
|
||||
// return
|
||||
// }
|
||||
|
||||
// if req.MailID > 0 {
|
||||
// targetDir = filepath.Join(targetDir, "mail", fmt.Sprintf("%d", req.MailID))
|
||||
// }
|
||||
// if req.PersonID > 0 {
|
||||
// targetDir = filepath.Join(targetDir, "person", fmt.Sprintf("%d", req.PersonID))
|
||||
// }
|
||||
// }
|
||||
|
||||
p := filepath.Join(targetDir, file.Filename)
|
||||
|
||||
if _, err := os.Stat(p); err != nil {
|
||||
err = ctx.SaveUploadedFile(file, p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user