merge: type responses dans response.go

This commit is contained in:
Victor Lacasse-Beaudoin 2024-08-22 12:07:40 -04:00
parent 2928e22610
commit 52f671cb03
8 changed files with 111 additions and 122 deletions

View file

@ -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
}

View file

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

View file

@ -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
}
}

View file

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

View file

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

107
response.go Normal file
View file

@ -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
}

View file

@ -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 {

View file

@ -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
}