Merge pull request 'Fix implémentations de UploadDocument et models.NotFoundResponse()' (#140) from fix/not-found-and-v1-document-create-response into main
Reviewed-on: #140
This commit is contained in:
commit
29ad72481e
4 changed files with 17 additions and 16 deletions
|
@ -138,8 +138,8 @@ func (a *API) Call(method, route string) ([]byte, error) {
|
|||
return nil, errors.New(fmt.Sprintf("method must be 'GET' or 'DELETE', got '%s'", method))
|
||||
}
|
||||
|
||||
func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (models.UploadDocumentResponse, error) {
|
||||
var response models.UploadDocumentResponse
|
||||
func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (models.V1DocumentCreateResponse, error) {
|
||||
var response models.V1DocumentCreateResponse
|
||||
endpoint := fmt.Sprintf("%s://%s:%d",
|
||||
a.Protocol,
|
||||
a.Host,
|
||||
|
|
|
@ -127,7 +127,7 @@ func HandleV1BucketRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -153,7 +153,7 @@ func HandleV1BucketRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !exists {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
objectCh := mediaClient.MinioClient.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
||||
|
@ -208,7 +208,7 @@ func HandleV1DocumentCreate(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -255,6 +255,7 @@ func HandleV1DocumentCreate(c echo.Context) error {
|
|||
}
|
||||
|
||||
response.StatusCode = http.StatusOK
|
||||
response.Message = "ok"
|
||||
response.Data.Bucket = info.Bucket
|
||||
response.Data.Key = info.Key
|
||||
response.Data.Size = info.Size
|
||||
|
@ -282,7 +283,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -303,7 +304,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !bucket_exists {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
|
@ -311,7 +312,7 @@ func HandleV1DocumentRead(c echo.Context) error {
|
|||
if err != nil {
|
||||
if err.Error() == "The specified key does not exist." {
|
||||
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
|
@ -357,7 +358,7 @@ func HandleV1DocumentDelete(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !allowed {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -378,14 +379,14 @@ func HandleV1DocumentDelete(c echo.Context) error {
|
|||
}
|
||||
|
||||
if !bucket_exists {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||
if err != nil {
|
||||
if err.Error() == "The specified key does not exist." {
|
||||
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
|
|
|
@ -24,8 +24,8 @@ func (r SimpleResponse) Respond() Responder {
|
|||
return r
|
||||
}
|
||||
|
||||
func NotFoundResponse() SimpleResponse {
|
||||
return SimpleResponse{
|
||||
func NotFoundResponse() (int, SimpleResponse) {
|
||||
return http.StatusNotFound, SimpleResponse{
|
||||
Message: "Not Found",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func HandleFormulaires(c echo.Context) error {
|
|||
func HandlePublicDocumentation(c echo.Context) error {
|
||||
client, err := api.NewApiClientFromViper()
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
bucket := c.Param("bucket")
|
||||
|
@ -138,7 +138,7 @@ func HandlePublicDocumentation(c echo.Context) error {
|
|||
|
||||
result, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s/%s", bucket, document))
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, models.NotFoundResponse())
|
||||
return c.JSON(models.NotFoundResponse())
|
||||
}
|
||||
|
||||
// Check if result can fit inside a map containing a message
|
||||
|
@ -259,7 +259,7 @@ func HandleAdminDocumentsUploadPOST(c echo.Context) error {
|
|||
// Format response
|
||||
var info, status string
|
||||
|
||||
info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", uploadDocumentResponse.Data.Size, uploadDocumentResponse.Data.Bucket, uploadDocumentResponse.Data.Object)
|
||||
info = fmt.Sprintf("[%d] /public/documentation/%s/%s", uploadDocumentResponse.Data.Size, uploadDocumentResponse.Data.Bucket, uploadDocumentResponse.Data.Key)
|
||||
|
||||
status = uploadDocumentResponse.Message
|
||||
|
||||
|
|
Loading…
Reference in a new issue