From 52f671cb030f46edd6ee7fdf19582cbb91d7bcd9 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 22 Aug 2024 12:07:40 -0400 Subject: [PATCH] merge: type responses dans response.go --- apiresponse/apiresponse.go | 19 ------- apiresponse/bucket.go | 15 ------ apiresponse/document.go | 35 ------------ apiresponse/seed.go | 8 --- apiresponse/spec.go | 8 --- response.go | 107 +++++++++++++++++++++++++++++++++++++ webhandler/webhandler.go | 10 ++-- webresponse/webresponse.go | 31 ----------- 8 files changed, 111 insertions(+), 122 deletions(-) delete mode 100644 apiresponse/apiresponse.go delete mode 100644 apiresponse/bucket.go delete mode 100644 apiresponse/document.go delete mode 100644 apiresponse/seed.go delete mode 100644 apiresponse/spec.go create mode 100644 response.go delete mode 100644 webresponse/webresponse.go diff --git a/apiresponse/apiresponse.go b/apiresponse/apiresponse.go deleted file mode 100644 index f650728..0000000 --- a/apiresponse/apiresponse.go +++ /dev/null @@ -1,19 +0,0 @@ -package apiresponse - -import ( - "codeberg.org/vlbeaudoin/voki/v3" -) - -type APIResponse struct { - voki.MessageResponse - statusCode int - Error string -} - -func (R APIResponse) StatusCode() int { - return R.statusCode -} - -func (R *APIResponse) SetStatusCode(code int) { - R.statusCode = code -} diff --git a/apiresponse/bucket.go b/apiresponse/bucket.go deleted file mode 100644 index 24313dc..0000000 --- a/apiresponse/bucket.go +++ /dev/null @@ -1,15 +0,0 @@ -package apiresponse - -type V1BucketsGET struct { - APIResponse - Data struct { - Buckets map[string]string - } -} - -type V1BucketGET struct { - APIResponse - Data struct { - Keys []string - } -} diff --git a/apiresponse/document.go b/apiresponse/document.go deleted file mode 100644 index 643e54e..0000000 --- a/apiresponse/document.go +++ /dev/null @@ -1,35 +0,0 @@ -package apiresponse - -type DataDocument struct { - Key string - Size int64 -} - -type V1DocumentsPOST struct { - APIResponse - Data struct { - Bucket string - Documents []DataDocument - } -} - -// Deprecated: Use V1DocumentsPOST instead -type V1DocumentPOST struct { - APIResponse - Data struct { - Bucket string - DataDocument - } -} - -type V1DocumentDELETE struct { - APIResponse -} - -type V1DocumentKeyPUT struct { - APIResponse - Data struct { - Bucket string - Key string - } -} diff --git a/apiresponse/seed.go b/apiresponse/seed.go deleted file mode 100644 index 623613c..0000000 --- a/apiresponse/seed.go +++ /dev/null @@ -1,8 +0,0 @@ -package apiresponse - -type V1SeedPOST struct { - APIResponse - Data struct { - Buckets []string - } -} diff --git a/apiresponse/spec.go b/apiresponse/spec.go deleted file mode 100644 index a426f9a..0000000 --- a/apiresponse/spec.go +++ /dev/null @@ -1,8 +0,0 @@ -package apiresponse - -type V1SpecGET struct { - APIResponse - Data struct { - Spec string - } -} diff --git a/response.go b/response.go new file mode 100644 index 0000000..717ff10 --- /dev/null +++ b/response.go @@ -0,0 +1,107 @@ +package main + +import ( + "codeberg.org/vlbeaudoin/voki/v3" + "git.agecem.com/agecem/agecem-org/models" +) + +type APIResponse struct { + voki.MessageResponse + statusCode int + Error string +} + +func (R APIResponse) StatusCode() int { + return R.statusCode +} + +func (R *APIResponse) SetStatusCode(code int) { + R.statusCode = code +} + +type V1BucketsGET struct { + APIResponse + Data struct { + Buckets map[string]string + } +} + +type V1BucketGET struct { + APIResponse + Data struct { + Keys []string + } +} + +type DataDocument struct { + Key string + Size int64 +} + +type V1DocumentsPOST struct { + APIResponse + Data struct { + Bucket string + Documents []DataDocument + } +} + +// Deprecated: Use V1DocumentsPOST instead +type V1DocumentPOST struct { + APIResponse + Data struct { + Bucket string + DataDocument + } +} + +type V1DocumentDELETE struct { + APIResponse +} + +type V1DocumentKeyPUT struct { + APIResponse + Data struct { + Bucket string + Key string + } +} + +type V1SeedPOST struct { + APIResponse + Data struct { + Buckets []string + } +} + +type V1SpecGET struct { + APIResponse + Data struct { + Spec string + } +} + +type HandleAdminDocumentsUploadResponse struct { + APIResponse + Data struct { + Buckets []models.Bucket + } +} + +type HandleDocumentationResponse struct { + APIResponse + Data struct { + Buckets []models.Bucket + } +} + +type UploadDocumentAPIResponse struct { + APIResponse + Data UploadDocumentResponseData +} + +type UploadDocumentResponseData struct { + Bucket string + Object string + Size float64 +} diff --git a/webhandler/webhandler.go b/webhandler/webhandler.go index 9dd8fee..7f75e63 100644 --- a/webhandler/webhandler.go +++ b/webhandler/webhandler.go @@ -10,9 +10,7 @@ import ( "codeberg.org/vlbeaudoin/voki/v3" "git.agecem.com/agecem/agecem-org/api" "git.agecem.com/agecem/agecem-org/apirequest" - "git.agecem.com/agecem/agecem-org/apiresponse" "git.agecem.com/agecem/agecem-org/models" - "git.agecem.com/agecem/agecem-org/webresponse" "github.com/labstack/echo/v4" ) @@ -53,7 +51,7 @@ func HandleVieEtudianteOrganisme(c echo.Context) error { } func (h *WebHandler) HandleDocumentation(c echo.Context) error { - var response webresponse.HandleDocumentationResponse + var response HandleDocumentationResponse v1BucketsGET, err := h.ApiClient.ListBuckets() if err != nil { @@ -68,7 +66,7 @@ func (h *WebHandler) HandleDocumentation(c echo.Context) error { for bucket, displayName := range v1BucketsGET.Data.Buckets { // TODO move call to dedicated API client method - var v1BucketReadResponse apiresponse.V1BucketGET + var v1BucketReadResponse V1BucketGET if err = h.ApiClient.Voki.Unmarshal(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket), nil, true, &v1BucketReadResponse); err != nil { response.Error = err.Error() @@ -136,7 +134,7 @@ func HandleAdmin(c echo.Context) error { } func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error { - var response webresponse.HandleAdminDocumentsUploadResponse + var response HandleAdminDocumentsUploadResponse v1BucketsGET, err := h.ApiClient.ListBuckets() if err != nil { @@ -160,7 +158,7 @@ func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error { func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error { var request apirequest.V1DocumentsPOST - var response webresponse.HandleAdminDocumentsUploadResponse + var response HandleAdminDocumentsUploadResponse v1BucketsGET, err := h.ApiClient.ListBuckets() if err != nil { diff --git a/webresponse/webresponse.go b/webresponse/webresponse.go deleted file mode 100644 index a529e80..0000000 --- a/webresponse/webresponse.go +++ /dev/null @@ -1,31 +0,0 @@ -package webresponse - -import ( - "git.agecem.com/agecem/agecem-org/apiresponse" - "git.agecem.com/agecem/agecem-org/models" -) - -type HandleAdminDocumentsUploadResponse struct { - apiresponse.APIResponse - Data struct { - Buckets []models.Bucket - } -} - -type HandleDocumentationResponse struct { - apiresponse.APIResponse - Data struct { - Buckets []models.Bucket - } -} - -type UploadDocumentAPIResponse struct { - apiresponse.APIResponse - Data UploadDocumentResponseData -} - -type UploadDocumentResponseData struct { - Bucket string - Object string - Size float64 -}