Déplacer UploadDocumentResponse dans models/

Refactor UploadDocumentResponse selon type models.Response

Implémenter models.Response struct et models.Responder interface
This commit is contained in:
Victor Lacasse-Beaudoin 2023-08-19 15:49:57 -04:00
parent d4f26435e8
commit 8cce7414ef
2 changed files with 28 additions and 13 deletions

View file

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

25
models/responses.go Normal file
View file

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