From 8cce7414ef2ef9917a0427920a2a36ea4281ca18 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Sat, 19 Aug 2023 15:49:57 -0400 Subject: [PATCH] =?UTF-8?q?D=C3=A9placer=20UploadDocumentResponse=20dans?= =?UTF-8?q?=20models/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor UploadDocumentResponse selon type models.Response Implémenter models.Response struct et models.Responder interface --- api/api.go | 16 +++------------- models/responses.go | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 models/responses.go diff --git a/api/api.go b/api/api.go index dd8c92a..310bbdc 100644 --- a/api/api.go +++ b/api/api.go @@ -11,6 +11,7 @@ import ( "net/url" "git.agecem.com/agecem/agecem-org/config" + "git.agecem.com/agecem/agecem-org/models" "github.com/spf13/viper" ) @@ -29,17 +30,6 @@ type APIOptions struct { Password string } -type UploadDocumentResponse struct { - Info UploadDocumentResponseInfo `json:"info"` - Message string `json:"message"` -} - -type UploadDocumentResponseInfo struct { - Bucket string `json:"bucket"` - Object string `json:"key"` - Size float64 `json:"size"` -} - // NewApiClientFromViper returns a pointer to a new API object, // provided the configuration options are managed by // https://git.agecem.com/agecem/agecem-org/config @@ -148,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) (UploadDocumentResponse, error) { - var response UploadDocumentResponse +func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (models.UploadDocumentResponse, error) { + var response models.UploadDocumentResponse endpoint := fmt.Sprintf("%s://%s:%d", a.Protocol, a.Host, diff --git a/models/responses.go b/models/responses.go new file mode 100644 index 0000000..b57b779 --- /dev/null +++ b/models/responses.go @@ -0,0 +1,25 @@ +package models + +type Responder interface { + Respond() Responder +} + +type Response struct { + StatusCode int `json:"status_code"` + Message string +} + +func (r Response) Respond() Responder { + return r +} + +type UploadDocumentResponse struct { + Response + Data UploadDocumentResponseData +} + +type UploadDocumentResponseData struct { + Bucket string + Object string + Size float64 +}