Merge pull request 'fix: update voki requests/responses à v3' (#199) from vlbeaudoin/fix/voki-versions-mismatch into main

Reviewed-on: https://git.agecem.com///agecem/agecem-org/pulls/199
This commit is contained in:
Victor Lacasse-Beaudoin 2024-08-21 13:40:04 -04:00
commit 2928e22610
20 changed files with 169 additions and 175 deletions

View file

@ -9,7 +9,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"codeberg.org/vlbeaudoin/voki" "codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/agecem/agecem-org/apirequest" "git.agecem.com/agecem/agecem-org/apirequest"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
"git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/config"

View file

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"codeberg.org/vlbeaudoin/pave" "codeberg.org/vlbeaudoin/pave/v2"
"git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/config"
"git.agecem.com/agecem/agecem-org/media" "git.agecem.com/agecem/agecem-org/media"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/agecem/agecem-org/apirequest" "git.agecem.com/agecem/agecem-org/apirequest"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@ -17,9 +18,9 @@ func (h *V1Handler) V1BucketsGET(c echo.Context) error {
if !request.Complete() { if !request.Complete() {
response.Message = "Incomplete V1BucketsGET request received" response.Message = "Incomplete V1BucketsGET request received"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
var buckets = make(map[string]string) var buckets = make(map[string]string)
@ -27,11 +28,10 @@ func (h *V1Handler) V1BucketsGET(c echo.Context) error {
for bucket_name, bucket_display_name := range h.Config.Server.Documents.Buckets { for bucket_name, bucket_display_name := range h.Config.Server.Documents.Buckets {
exists, err := h.MediaClient.MinioClient.BucketExists(context.Background(), bucket_name) exists, err := h.MediaClient.MinioClient.BucketExists(context.Background(), bucket_name)
if err != nil { if err != nil {
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during minio#BucketExists" response.Message = "Error during minio#BucketExists"
// response.Error = err.Error() response.SetStatusCode(http.StatusInternalServerError)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if exists { if exists {
@ -39,11 +39,11 @@ func (h *V1Handler) V1BucketsGET(c echo.Context) error {
} }
} }
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
response.Message = "Buckets list successful" response.Message = "Buckets list successful"
response.Data.Buckets = buckets response.Data.Buckets = buckets
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
func (h *V1Handler) V1BucketGET(c echo.Context) error { func (h *V1Handler) V1BucketGET(c echo.Context) error {
@ -54,9 +54,9 @@ func (h *V1Handler) V1BucketGET(c echo.Context) error {
if !request.Complete() { if !request.Complete() {
response.Message = "Incomplete V1BucketGET request received" response.Message = "Incomplete V1BucketGET request received"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
allowed := false allowed := false
@ -67,7 +67,8 @@ func (h *V1Handler) V1BucketGET(c echo.Context) error {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -76,33 +77,34 @@ func (h *V1Handler) V1BucketGET(c echo.Context) error {
exists, err := h.MediaClient.MinioClient.BucketExists(ctx, request.Params.Bucket) exists, err := h.MediaClient.MinioClient.BucketExists(ctx, request.Params.Bucket)
if err != nil { if err != nil {
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during minio#BucketExists" response.Message = "Error during minio#BucketExists"
response.SetStatusCode(http.StatusInternalServerError)
response.Error = err.Error() response.Error = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if !exists { if !exists {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
objectCh := h.MediaClient.MinioClient.ListObjects(ctx, request.Params.Bucket, minio.ListObjectsOptions{}) objectCh := h.MediaClient.MinioClient.ListObjects(ctx, request.Params.Bucket, minio.ListObjectsOptions{})
for object := range objectCh { for object := range objectCh {
if object.Err != nil { if object.Err != nil {
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during minio#ListObjects" response.Message = "Error during minio#ListObjects"
response.SetStatusCode(http.StatusInternalServerError)
//TODO make sure this is safe //TODO make sure this is safe
//response.Error = object.Err.Error() //response.Error = object.Err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
response.Data.Keys = append(response.Data.Keys, object.Key) response.Data.Keys = append(response.Data.Keys, object.Key)
} }
response.StatusCode = http.StatusOK
response.Message = "V1BucketRead ok" response.Message = "V1BucketRead ok"
response.SetStatusCode(http.StatusOK)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/agecem/agecem-org/apirequest" "git.agecem.com/agecem/agecem-org/apirequest"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
@ -34,28 +35,29 @@ func (h *V1Handler) V1DocumentsPOST(c echo.Context) (err error) {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
form, err := c.MultipartForm() form, err := c.MultipartForm()
if err != nil { if err != nil {
response.Message = fmt.Sprintf("Téléversement invalide: %s", err) response.Message = fmt.Sprintf("Téléversement invalide: %s", err)
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if form == nil { if form == nil {
response.Message = "MultipartForm pointe vers une addresse mémoire nil" response.Message = "MultipartForm pointe vers une addresse mémoire nil"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if len(form.File) == 0 { if len(form.File) == 0 {
response.Message = "Veuillez sélectionner au moins 1 document à téléverser" response.Message = "Veuillez sélectionner au moins 1 document à téléverser"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
for inputName, inputFileHeaders := range form.File { for inputName, inputFileHeaders := range form.File {
@ -66,21 +68,23 @@ func (h *V1Handler) V1DocumentsPOST(c echo.Context) (err error) {
if request.Data.Documents == nil { if request.Data.Documents == nil {
response.Message = "Impossible d'obtenir les documents depuis le formulaire" response.Message = "Impossible d'obtenir les documents depuis le formulaire"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if !request.Complete() { if !request.Complete() {
response.Message = "Requête V1DocumentsPOST incomplète reçue" response.Message = "Requête V1DocumentsPOST incomplète reçue"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
response.StatusCode, response.Message = h.MediaClient.UploadFormFiles(request.Params.Bucket, request.Data.Documents) var code int
code, response.Message = h.MediaClient.UploadFormFiles(request.Params.Bucket, request.Data.Documents)
response.SetStatusCode(code)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// V1DocumentPOST permet d'ajouter un object dans un bucket, par multipart/form-data // V1DocumentPOST permet d'ajouter un object dans un bucket, par multipart/form-data
@ -92,11 +96,11 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
request.Data.Document, err = c.FormFile("document") request.Data.Document, err = c.FormFile("document")
if err != nil { if err != nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Error during HandleV1DocumentCreate's echo#Context.FormFile" response.Message = "Error during HandleV1DocumentCreate's echo#Context.FormFile"
response.Error = err.Error() response.Error = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
allowed := false allowed := false
@ -107,14 +111,15 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
if !request.Complete() { if !request.Complete() {
response.Message = "Incomplete V1DocumentPOST request received" response.Message = "Incomplete V1DocumentPOST request received"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -123,11 +128,11 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
src, err := request.Data.Document.Open() src, err := request.Data.Document.Open()
if err != nil { if err != nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Error during form_file.Open()" response.Message = "Error during form_file.Open()"
response.Error = err.Error() response.Error = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
defer src.Close() defer src.Close()
@ -135,20 +140,20 @@ func (h *V1Handler) V1DocumentPOST(c echo.Context) (err error) {
ContentType: request.Data.Document.Header.Get("Content-Type"), ContentType: request.Data.Document.Header.Get("Content-Type"),
}) })
if err != nil { if err != nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Error during minio#PutObject" response.Message = "Error during minio#PutObject"
//response.Error = err.Error() //response.Error = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
response.Message = "ok" response.Message = "ok"
response.Data.Bucket = info.Bucket response.Data.Bucket = info.Bucket
response.Data.Key = info.Key response.Data.Key = info.Key
response.Data.Size = info.Size response.Data.Size = info.Size
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// V1DocumentGET permet de lire le contenu d'un fichier et protentiellement de le télécharger // V1DocumentGET permet de lire le contenu d'un fichier et protentiellement de le télécharger
@ -164,7 +169,8 @@ func (h *V1Handler) V1DocumentGET(c echo.Context) error {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -177,7 +183,8 @@ func (h *V1Handler) V1DocumentGET(c echo.Context) error {
} }
if !bucket_exists { if !bucket_exists {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{}) document_info, err := h.MediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
@ -185,7 +192,8 @@ func (h *V1Handler) V1DocumentGET(c echo.Context) error {
if err != nil { if err != nil {
if err.Error() == "The specified key does not exist." { if err.Error() == "The specified key does not exist." {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
return c.JSON(http.StatusInternalServerError, map[string]interface{}{ return c.JSON(http.StatusInternalServerError, map[string]interface{}{
@ -223,14 +231,15 @@ func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
if !request.Complete() { if !request.Complete() {
response.Message = "Incomplete V1DocumentDELETE request received" response.Message = "Incomplete V1DocumentDELETE request received"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -243,21 +252,23 @@ func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
} }
if !bucket_exists { if !bucket_exists {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
document_info, err := h.MediaClient.MinioClient.StatObject(ctx, request.Params.Bucket, request.Params.Document, minio.StatObjectOptions{}) document_info, err := h.MediaClient.MinioClient.StatObject(ctx, request.Params.Bucket, request.Params.Document, minio.StatObjectOptions{})
if err != nil { if err != nil {
if err.Error() == "The specified key does not exist." { if err.Error() == "The specified key does not exist." {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
//response.Error = err.Error() //response.Error = err.Error()
response.Message = "Error during minio#StatObject" response.Message = "Error during minio#StatObject"
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
//TODO Add error validation //TODO Add error validation
@ -267,15 +278,15 @@ func (h *V1Handler) V1DocumentDELETE(c echo.Context) error {
if err != nil { if err != nil {
//response.Error = err.Error() //response.Error = err.Error()
response.Message = "Error during minio#RemoveObject" response.Message = "Error during minio#RemoveObject"
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
response.Message = "Document deleted" response.Message = "Document deleted"
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// V1DocumentKeyPUT // V1DocumentKeyPUT
@ -289,25 +300,25 @@ func (h *V1Handler) V1DocumentKeyPUT(c echo.Context) (err error) {
var newKey string var newKey string
err = c.Bind(&newKey) err = c.Bind(&newKey)
if err != nil { if err != nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = err.Error() response.Message = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
request, err = apirequest.NewV1DocumentKeyPUT(bucket, document, newKey) request, err = apirequest.NewV1DocumentKeyPUT(bucket, document, newKey)
if err != nil { if err != nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = err.Error() response.Message = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if !request.Complete() { if !request.Complete() {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Incomplete V1DocumentKeyPUT request received" response.Message = "Incomplete V1DocumentKeyPUT request received"
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
var allowed bool var allowed bool
@ -318,7 +329,8 @@ func (h *V1Handler) V1DocumentKeyPUT(c echo.Context) (err error) {
} }
if !allowed { if !allowed {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -330,7 +342,8 @@ func (h *V1Handler) V1DocumentKeyPUT(c echo.Context) (err error) {
} }
if !bucketExists { if !bucketExists {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
// Check source object exists // Check source object exists
@ -338,13 +351,14 @@ func (h *V1Handler) V1DocumentKeyPUT(c echo.Context) (err error) {
if _, err := h.MediaClient.MinioClient.StatObject(ctx, request.Params.Bucket, request.Params.Document, minio.StatObjectOptions{}); err != nil { if _, err := h.MediaClient.MinioClient.StatObject(ctx, request.Params.Bucket, request.Params.Document, minio.StatObjectOptions{}); err != nil {
if err.Error() == "The specified key does not exist." { if err.Error() == "The specified key does not exist." {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
response.Message = fmt.Sprintf("Could not obtain information on %s/%s", request.Params.Bucket, request.Params.Document) response.Message = fmt.Sprintf("Could not obtain information on %s/%s", request.Params.Bucket, request.Params.Document)
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// Copy object to newKey // Copy object to newKey
@ -353,34 +367,34 @@ func (h *V1Handler) V1DocumentKeyPUT(c echo.Context) (err error) {
minio.CopyDestOptions{Bucket: request.Params.Bucket, Object: request.Data.NewKey}, minio.CopyDestOptions{Bucket: request.Params.Bucket, Object: request.Data.NewKey},
minio.CopySrcOptions{Bucket: request.Params.Bucket, Object: request.Params.Document}, minio.CopySrcOptions{Bucket: request.Params.Bucket, Object: request.Params.Document},
); err != nil { ); err != nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Impossible de copier un document pour le renommer" response.Message = "Impossible de copier un document pour le renommer"
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// Verify copy was successful // Verify copy was successful
if _, err := h.MediaClient.MinioClient.StatObject(ctx, if _, err := h.MediaClient.MinioClient.StatObject(ctx,
request.Params.Bucket, request.Data.NewKey, minio.GetObjectOptions{}); err != nil { request.Params.Bucket, request.Data.NewKey, minio.GetObjectOptions{}); err != nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Copie de document ne semble pas avoir fonctionnée" response.Message = "Copie de document ne semble pas avoir fonctionnée"
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
// Delete old file // Delete old file
if err := h.MediaClient.MinioClient.RemoveObject(ctx, if err := h.MediaClient.MinioClient.RemoveObject(ctx,
request.Params.Bucket, request.Params.Document, minio.RemoveObjectOptions{}); err != nil { request.Params.Bucket, request.Params.Document, minio.RemoveObjectOptions{}); err != nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Erreur pendant tentative de supprimer document source" response.Message = "Erreur pendant tentative de supprimer document source"
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
//TODO cleanup //TODO cleanup
// Return result // Return result
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
response.Message = "Document renommé avec succès" response.Message = "Document renommé avec succès"
response.Data.Bucket = request.Params.Bucket response.Data.Bucket = request.Params.Bucket
response.Data.Key = request.Data.NewKey response.Data.Key = request.Data.NewKey
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }

View file

@ -15,11 +15,11 @@ func (h *V1Handler) V1SeedPOST(c echo.Context) error {
new_buckets, err := h.MediaClient.Seed() new_buckets, err := h.MediaClient.Seed()
response.Data.Buckets = new_buckets response.Data.Buckets = new_buckets
if err != nil { if err != nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Error during mediaClient.Seed()" response.Message = "Error during mediaClient.Seed()"
response.Error = err.Error() response.Error = err.Error()
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
if len(new_buckets) == 0 { if len(new_buckets) == 0 {
@ -29,7 +29,7 @@ func (h *V1Handler) V1SeedPOST(c echo.Context) error {
response.Message = "Buckets successfully created" response.Message = "Buckets successfully created"
} }
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }

View file

@ -18,9 +18,9 @@ func (h *V1Handler) V1SpecGET(c echo.Context) error {
if !request.Complete() { if !request.Complete() {
response.Message = "Incomplete V1SpecGET request received" response.Message = "Incomplete V1SpecGET request received"
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }
response.Data.Spec = fmt.Sprintf("# pave spec for agecem-org %s\n", version.Version()) response.Data.Spec = fmt.Sprintf("# pave spec for agecem-org %s\n", version.Version())
@ -30,7 +30,7 @@ func (h *V1Handler) V1SpecGET(c echo.Context) error {
} }
response.Message = "ok" response.Message = "ok"
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
return c.JSON(response.StatusCode, response) return c.JSON(response.StatusCode(), response)
} }

View file

@ -4,12 +4,11 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki" "codeberg.org/vlbeaudoin/voki/v3"
"codeberg.org/vlbeaudoin/voki/request"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
) )
var _ request.Requester[apiresponse.V1BucketsGET] = V1BucketsGET{} var _ voki.Requester[apiresponse.V1BucketsGET] = V1BucketsGET{}
type V1BucketsGET struct{} type V1BucketsGET struct{}
@ -28,7 +27,7 @@ func (request V1BucketsGET) Request(v *voki.Voki) (response apiresponse.V1Bucket
return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/bucket", nil, true, &response) return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/bucket", nil, true, &response)
} }
var _ request.Requester[apiresponse.V1BucketGET] = V1BucketGET{} var _ voki.Requester[apiresponse.V1BucketGET] = V1BucketGET{}
type V1BucketGET struct { type V1BucketGET struct {
Params struct { Params struct {

View file

@ -7,12 +7,11 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki" "codeberg.org/vlbeaudoin/voki/v3"
"codeberg.org/vlbeaudoin/voki/request"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
) )
var _ request.Requester[apiresponse.V1DocumentsPOST] = V1DocumentsPOST{} var _ voki.Requester[apiresponse.V1DocumentsPOST] = V1DocumentsPOST{}
type V1DocumentsPOST struct { type V1DocumentsPOST struct {
Data struct { Data struct {
@ -75,7 +74,7 @@ func (request V1DocumentsPOST) Request(v *voki.Voki) (response apiresponse.V1Doc
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s/many", request.Params.Bucket), &buf, true, &response) return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s/many", request.Params.Bucket), &buf, true, &response)
} }
var _ request.Requester[apiresponse.V1DocumentPOST] = V1DocumentPOST{} var _ voki.Requester[apiresponse.V1DocumentPOST] = V1DocumentPOST{}
// Deprecated: Use V1DocumentsPOST instead // Deprecated: Use V1DocumentsPOST instead
type V1DocumentPOST struct { type V1DocumentPOST struct {
@ -124,7 +123,7 @@ func (request V1DocumentPOST) Request(v *voki.Voki) (response apiresponse.V1Docu
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), &buf, true, &response) return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), &buf, true, &response)
} }
var _ request.Requester[apiresponse.V1DocumentDELETE] = V1DocumentDELETE{} var _ voki.Requester[apiresponse.V1DocumentDELETE] = V1DocumentDELETE{}
type V1DocumentDELETE struct { type V1DocumentDELETE struct {
Params struct { Params struct {
@ -164,7 +163,7 @@ func (request V1DocumentDELETE) Request(v *voki.Voki) (response apiresponse.V1Do
return response, v.UnmarshalIfComplete(http.MethodDelete, fmt.Sprintf("/v1/bucket/%s/%s", request.Params.Bucket, request.Params.Document), nil, true, &response) return response, v.UnmarshalIfComplete(http.MethodDelete, fmt.Sprintf("/v1/bucket/%s/%s", request.Params.Bucket, request.Params.Document), nil, true, &response)
} }
var _ request.Requester[apiresponse.V1DocumentKeyPUT] = V1DocumentKeyPUT{} var _ voki.Requester[apiresponse.V1DocumentKeyPUT] = V1DocumentKeyPUT{}
type V1DocumentKeyPUT struct { type V1DocumentKeyPUT struct {
Data struct { Data struct {

View file

@ -4,12 +4,11 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki" "codeberg.org/vlbeaudoin/voki/v3"
"codeberg.org/vlbeaudoin/voki/request"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
) )
var _ request.Requester[apiresponse.V1SeedPOST] = V1SeedPOST{} var _ voki.Requester[apiresponse.V1SeedPOST] = V1SeedPOST{}
type V1SeedPOST struct{} type V1SeedPOST struct{}

View file

@ -4,12 +4,11 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/voki" "codeberg.org/vlbeaudoin/voki/v3"
"codeberg.org/vlbeaudoin/voki/request"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
) )
var _ request.Requester[apiresponse.V1SpecGET] = V1SpecGET{} var _ voki.Requester[apiresponse.V1SpecGET] = V1SpecGET{}
type V1SpecGET struct{} type V1SpecGET struct{}

View file

@ -1,37 +1,19 @@
package apiresponse package apiresponse
import ( import (
"net/http" "codeberg.org/vlbeaudoin/voki/v3"
"codeberg.org/vlbeaudoin/voki/response"
) )
type Response struct { type APIResponse struct {
response.ResponseWithError voki.MessageResponse
statusCode int
Error string
} }
type SimpleResponse struct { func (R APIResponse) StatusCode() int {
Message string return R.statusCode
} }
func (r SimpleResponse) Respond() response.Responder { func (R *APIResponse) SetStatusCode(code int) {
return r R.statusCode = code
}
func NotFoundResponse() (int, SimpleResponse) {
return http.StatusNotFound, SimpleResponse{
Message: "Not Found",
}
}
func NotImplementedResponse() (int, SimpleResponse) {
return http.StatusNotImplemented, SimpleResponse{
Message: "Not Implemented",
}
}
func InternalServerErrorResponse() (int, SimpleResponse) {
return http.StatusInternalServerError, SimpleResponse{
Message: "Internal Server Error",
}
} }

View file

@ -1,14 +1,14 @@
package apiresponse package apiresponse
type V1BucketsGET struct { type V1BucketsGET struct {
Response APIResponse
Data struct { Data struct {
Buckets map[string]string Buckets map[string]string
} }
} }
type V1BucketGET struct { type V1BucketGET struct {
Response APIResponse
Data struct { Data struct {
Keys []string Keys []string
} }

View file

@ -6,7 +6,7 @@ type DataDocument struct {
} }
type V1DocumentsPOST struct { type V1DocumentsPOST struct {
Response APIResponse
Data struct { Data struct {
Bucket string Bucket string
Documents []DataDocument Documents []DataDocument
@ -15,7 +15,7 @@ type V1DocumentsPOST struct {
// Deprecated: Use V1DocumentsPOST instead // Deprecated: Use V1DocumentsPOST instead
type V1DocumentPOST struct { type V1DocumentPOST struct {
Response APIResponse
Data struct { Data struct {
Bucket string Bucket string
DataDocument DataDocument
@ -23,11 +23,11 @@ type V1DocumentPOST struct {
} }
type V1DocumentDELETE struct { type V1DocumentDELETE struct {
Response APIResponse
} }
type V1DocumentKeyPUT struct { type V1DocumentKeyPUT struct {
Response APIResponse
Data struct { Data struct {
Bucket string Bucket string
Key string Key string

View file

@ -1,7 +1,7 @@
package apiresponse package apiresponse
type V1SeedPOST struct { type V1SeedPOST struct {
Response APIResponse
Data struct { Data struct {
Buckets []string Buckets []string
} }

View file

@ -1,7 +1,7 @@
package apiresponse package apiresponse
type V1SpecGET struct { type V1SpecGET struct {
Response APIResponse
Data struct { Data struct {
Spec string Spec string
} }

View file

@ -13,7 +13,7 @@ import (
"io" "io"
"net/http" "net/http"
"codeberg.org/vlbeaudoin/pave" "codeberg.org/vlbeaudoin/pave/v2"
"codeberg.org/vlbeaudoin/serpents" "codeberg.org/vlbeaudoin/serpents"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"

5
go.mod
View file

@ -3,9 +3,9 @@ module git.agecem.com/agecem/agecem-org
go 1.23.0 go 1.23.0
require ( require (
codeberg.org/vlbeaudoin/pave v1.1.1 codeberg.org/vlbeaudoin/pave/v2 v2.0.0
codeberg.org/vlbeaudoin/serpents v1.1.0 codeberg.org/vlbeaudoin/serpents v1.1.0
codeberg.org/vlbeaudoin/voki v1.7.2 codeberg.org/vlbeaudoin/voki/v3 v3.0.0
github.com/labstack/echo/v4 v4.12.0 github.com/labstack/echo/v4 v4.12.0
github.com/minio/minio-go/v7 v7.0.75 github.com/minio/minio-go/v7 v7.0.75
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
@ -13,7 +13,6 @@ require (
) )
require ( require (
codeberg.org/vlbeaudoin/voki/v2 v2.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect github.com/go-ini/ini v1.67.0 // indirect

10
go.sum
View file

@ -1,11 +1,9 @@
codeberg.org/vlbeaudoin/pave v1.1.1 h1:9Yb87vbBd+bNL3DYrJEQ3tiw8trSrFfkAZqVwVG6pHk= codeberg.org/vlbeaudoin/pave/v2 v2.0.0 h1:hfB5KnqMMu17g5QBWgLvWOsqidrYaohRfu2LflmTrb0=
codeberg.org/vlbeaudoin/pave v1.1.1/go.mod h1:n+xUdWwcUjiic4+DzUMPYFiDNNkmYT4UYvLRXTdV3Kw= codeberg.org/vlbeaudoin/pave/v2 v2.0.0/go.mod h1:TsTfP6IA+3Ph33vLZigeJWS5vgBPgkW1tfs3zFPfycU=
codeberg.org/vlbeaudoin/serpents v1.1.0 h1:U9f2+2D1yUVHx90yePi2ZOLRLG/Wkoob4JXDIVyoBwA= codeberg.org/vlbeaudoin/serpents v1.1.0 h1:U9f2+2D1yUVHx90yePi2ZOLRLG/Wkoob4JXDIVyoBwA=
codeberg.org/vlbeaudoin/serpents v1.1.0/go.mod h1:3bE/R0ToABwcUJtS1VcGEBa86K5FYhrZGAbFl2qL8kQ= codeberg.org/vlbeaudoin/serpents v1.1.0/go.mod h1:3bE/R0ToABwcUJtS1VcGEBa86K5FYhrZGAbFl2qL8kQ=
codeberg.org/vlbeaudoin/voki v1.7.2 h1:9sMuOCuJ0t4hhZgr/rbRswHvyXN4CuizGJaB/Exmd90= codeberg.org/vlbeaudoin/voki/v3 v3.0.0 h1:XdF/UTe9YUNj3hYrAyEvdmIMDYLL8SkqTwPkqw1yJ2c=
codeberg.org/vlbeaudoin/voki v1.7.2/go.mod h1:5XTLx/KiW/OfiupF3o7PAAAU/UhsPdKSrVMmtHbmkPI= codeberg.org/vlbeaudoin/voki/v3 v3.0.0/go.mod h1:+6LMXosAu2ijNKV04sMwkeujpH+cghZU1fydqj2y95g=
codeberg.org/vlbeaudoin/voki/v2 v2.1.0 h1:pXav77QGMHvMF1RyvkEwK3VKBdQh3ATmgh48TXX0tlU=
codeberg.org/vlbeaudoin/voki/v2 v2.1.0/go.mod h1:TVdOLAxB94EJkylt5dleJlTkBzuxau8Xwd4TANQIR7U=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View file

@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"sort" "sort"
"codeberg.org/vlbeaudoin/voki/v3"
"git.agecem.com/agecem/agecem-org/api" "git.agecem.com/agecem/agecem-org/api"
"git.agecem.com/agecem/agecem-org/apirequest" "git.agecem.com/agecem/agecem-org/apirequest"
"git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/apiresponse"
@ -58,9 +59,9 @@ func (h *WebHandler) HandleDocumentation(c echo.Context) error {
if err != nil { if err != nil {
response.Error = err.Error() response.Error = err.Error()
response.Message = v1BucketsGET.Message response.Message = v1BucketsGET.Message
response.StatusCode = v1BucketsGET.StatusCode response.SetStatusCode(v1BucketsGET.StatusCode())
return c.Render(response.StatusCode, "documentation-html", response) return c.Render(response.StatusCode(), "documentation-html", response)
} }
//TODO check v1BucketsGET StatusCode and Error //TODO check v1BucketsGET StatusCode and Error
@ -72,7 +73,7 @@ func (h *WebHandler) HandleDocumentation(c echo.Context) error {
if err = h.ApiClient.Voki.Unmarshal(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket), nil, true, &v1BucketReadResponse); err != nil { if err = h.ApiClient.Voki.Unmarshal(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket), nil, true, &v1BucketReadResponse); err != nil {
response.Error = err.Error() response.Error = err.Error()
response.Message = "Error during json.Unmarshal /v1/bucket/:bucket" response.Message = "Error during json.Unmarshal /v1/bucket/:bucket"
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
return c.Render(http.StatusOK, "documentation-html", response) return c.Render(http.StatusOK, "documentation-html", response)
} }
@ -86,12 +87,12 @@ func (h *WebHandler) HandleDocumentation(c echo.Context) error {
sort.SliceStable(response.Data.Buckets, func(i, j int) bool { return response.Data.Buckets[i].Name < response.Data.Buckets[j].Name }) sort.SliceStable(response.Data.Buckets, func(i, j int) bool { return response.Data.Buckets[i].Name < response.Data.Buckets[j].Name })
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
//response.Message = "HandleDocumentation ok" //response.Message = "HandleDocumentation ok"
// TODO render .Message // TODO render .Message
return c.Render(http.StatusOK, "documentation-html", response) return c.Render(http.StatusOK, "documentation-html", response)
//return c.Render(response.StatusCode, "documentation-html", response.Data.Buckets) //return c.Render(response.StatusCode(), "documentation-html", response.Data.Buckets)
} }
func HandleFormulaires(c echo.Context) error { func HandleFormulaires(c echo.Context) error {
@ -109,13 +110,15 @@ func (h *WebHandler) HandlePublicDocumentation(c echo.Context) error {
response, err := h.ApiClient.Voki.Call(http.MethodGet, unescaped, nil, true) response, err := h.ApiClient.Voki.Call(http.MethodGet, unescaped, nil, true)
if err != nil { if err != nil {
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
} }
defer response.Body.Close() defer response.Body.Close()
switch response.StatusCode { switch response.StatusCode {
case http.StatusNotFound: case http.StatusNotFound:
return c.JSON(apiresponse.NotFoundResponse()) response := voki.ResponseNotFound{}
return c.JSON(response.StatusCode(), response)
case http.StatusInternalServerError: case http.StatusInternalServerError:
return c.JSON(http.StatusInternalServerError, map[string]string{"message": "Internal Server Error"}) return c.JSON(http.StatusInternalServerError, map[string]string{"message": "Internal Server Error"})
} }
@ -137,11 +140,11 @@ func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error {
v1BucketsGET, err := h.ApiClient.ListBuckets() v1BucketsGET, err := h.ApiClient.ListBuckets()
if err != nil { if err != nil {
response.StatusCode = v1BucketsGET.StatusCode response.SetStatusCode(v1BucketsGET.StatusCode())
response.Error = err.Error() response.Error = err.Error()
response.Message = v1BucketsGET.Message response.Message = v1BucketsGET.Message
return c.Render(response.StatusCode, "admin-upload-html", nil) return c.Render(response.StatusCode(), "admin-upload-html", nil)
} }
for bucketName, displayName := range v1BucketsGET.Data.Buckets { for bucketName, displayName := range v1BucketsGET.Data.Buckets {
@ -150,9 +153,9 @@ func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error {
DisplayName: displayName, DisplayName: displayName,
}) })
} }
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error { func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
@ -161,11 +164,11 @@ func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
v1BucketsGET, err := h.ApiClient.ListBuckets() v1BucketsGET, err := h.ApiClient.ListBuckets()
if err != nil { if err != nil {
response.StatusCode = v1BucketsGET.StatusCode response.SetStatusCode(v1BucketsGET.StatusCode())
response.Message = v1BucketsGET.Message response.Message = v1BucketsGET.Message
response.Error = err.Error() response.Error = err.Error()
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
for bucketName, displayName := range v1BucketsGET.Data.Buckets { for bucketName, displayName := range v1BucketsGET.Data.Buckets {
@ -179,26 +182,26 @@ func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
form, err := c.MultipartForm() form, err := c.MultipartForm()
if err != nil { if err != nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Impossible de téléverser" response.Message = "Impossible de téléverser"
response.Error = err.Error() response.Error = err.Error()
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
if form == nil { if form == nil {
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = "Formulaire pointe vers une addresse mémoire nulle" response.Message = "Formulaire pointe vers une addresse mémoire nulle"
response.Error = "Formulaire pointe vers une addresse mémoire nulle" response.Error = "Formulaire pointe vers une addresse mémoire nulle"
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
if len(form.File) == 0 { if len(form.File) == 0 {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Veuillez sélectionner au moins 1 fichier à téléverser" response.Message = "Veuillez sélectionner au moins 1 fichier à téléverser"
response.Error = "Input 'documents' ne contient aucun fichier" response.Error = "Input 'documents' ne contient aucun fichier"
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
for inputName, inputFileHeaders := range form.File { for inputName, inputFileHeaders := range form.File {
@ -209,26 +212,26 @@ func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
} }
if request.Data.Documents == nil { if request.Data.Documents == nil {
response.StatusCode = http.StatusBadRequest response.SetStatusCode(http.StatusBadRequest)
response.Message = "Impossible d'obtenir les documents depuis le formulaire" response.Message = "Impossible d'obtenir les documents depuis le formulaire"
response.Error = "Impossible d'obtenir les documents depuis le formulaire" response.Error = "Impossible d'obtenir les documents depuis le formulaire"
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
uploadDocumentsResponse, err := h.ApiClient.UploadDocuments(request.Params.Bucket, request.Data.Documents...) uploadDocumentsResponse, err := h.ApiClient.UploadDocuments(request.Params.Bucket, request.Data.Documents...)
if err != nil { if err != nil {
//TODO figure out pourquoi `err` n'est jamais `nil` //TODO figure out pourquoi `err` n'est jamais `nil`
response.StatusCode = uploadDocumentsResponse.StatusCode response.SetStatusCode(uploadDocumentsResponse.StatusCode())
response.Message = uploadDocumentsResponse.Message response.Message = uploadDocumentsResponse.Message
response.Error = fmt.Sprintf("%s. Détails: %s", err.Error(), uploadDocumentsResponse.Error) response.Error = fmt.Sprintf("%s. Détails: %s", err.Error(), uploadDocumentsResponse.Error)
/* /*
response.StatusCode = http.StatusInternalServerError response.SetStatusCode(http.StatusInternalServerError)
response.Message = fmt.Sprintf("api.(*API).UploadDocuments: %s", err) response.Message = fmt.Sprintf("api.(*API).UploadDocuments: %s", err)
response.Error = err.Error() response.Error = err.Error()
*/ */
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }
//TODO figure out pourquoi on se rend jamais ici //TODO figure out pourquoi on se rend jamais ici
@ -246,8 +249,8 @@ func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
status = fmt.Sprintf("%s. Erreur: %s", status, errMsg) status = fmt.Sprintf("%s. Erreur: %s", status, errMsg)
} }
response.StatusCode = http.StatusOK response.SetStatusCode(http.StatusOK)
response.Message = fmt.Sprintf("%s \n %s", status, info) response.Message = fmt.Sprintf("%s \n %s", status, info)
return c.Render(response.StatusCode, "admin-upload-html", response) return c.Render(response.StatusCode(), "admin-upload-html", response)
} }

View file

@ -6,21 +6,21 @@ import (
) )
type HandleAdminDocumentsUploadResponse struct { type HandleAdminDocumentsUploadResponse struct {
apiresponse.Response apiresponse.APIResponse
Data struct { Data struct {
Buckets []models.Bucket Buckets []models.Bucket
} }
} }
type HandleDocumentationResponse struct { type HandleDocumentationResponse struct {
apiresponse.Response apiresponse.APIResponse
Data struct { Data struct {
Buckets []models.Bucket Buckets []models.Bucket
} }
} }
type UploadDocumentResponse struct { type UploadDocumentAPIResponse struct {
apiresponse.Response apiresponse.APIResponse
Data UploadDocumentResponseData Data UploadDocumentResponseData
} }