Ajouter models/ pour type Bucket #109

Merged
vlbeaudoin merged 8 commits from refactor/models into main 2023-08-19 20:31:38 -04:00
2 changed files with 28 additions and 13 deletions
Showing only changes of commit 8cce7414ef - Show all commits

View file

@ -11,6 +11,7 @@ import (
"net/url" "net/url"
"git.agecem.com/agecem/agecem-org/config" "git.agecem.com/agecem/agecem-org/config"
"git.agecem.com/agecem/agecem-org/models"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -29,17 +30,6 @@ type APIOptions struct {
Password string 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, // NewApiClientFromViper returns a pointer to a new API object,
// provided the configuration options are managed by // provided the configuration options are managed by
// https://git.agecem.com/agecem/agecem-org/config // 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)) 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) { func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (models.UploadDocumentResponse, error) {
var response UploadDocumentResponse var response models.UploadDocumentResponse
endpoint := fmt.Sprintf("%s://%s:%d", endpoint := fmt.Sprintf("%s://%s:%d",
a.Protocol, a.Protocol,
a.Host, 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
}