Merged in feature/import (pull request #157)
Feature/import * importstart * pp * tests * importtests * 100GB * lint * passtests * utc * awsprofile * doublequotes * host
This commit is contained in:
@@ -2,11 +2,47 @@ package queryapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
documentupload "queryorchestration/internal/document/upload"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (s *Controllers) UploadDocument(ctx echo.Context, clientId ClientID) error {
|
||||
form, err := ctx.MultipartForm()
|
||||
if err != nil {
|
||||
slog.Error("unable to get form data", "error", err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "unable to get form data")
|
||||
}
|
||||
|
||||
files := form.File["file"]
|
||||
if len(files) == 0 {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "missing file")
|
||||
} else if len(files) > 1 {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "too many files")
|
||||
}
|
||||
file := files[0]
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "unable to read file")
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
err = s.svc.DocumentUpload.Upload(ctx.Request().Context(), documentupload.File{
|
||||
ClientID: clientId,
|
||||
Content: src,
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("unable to get form data", "error", err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "unable to upload file")
|
||||
}
|
||||
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Controllers) ListDocumentsByClientId(ctx echo.Context, clientId ClientID) error {
|
||||
documents, err := s.svc.Document.ListByClient(ctx.Request().Context(), clientId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user