merge: requests dans request.go
This commit is contained in:
parent
53f41d64a8
commit
9e08b3f962
7 changed files with 111 additions and 141 deletions
|
@ -22,7 +22,7 @@ Téléverser plusieurs fichiers à cette route avec `curl`:
|
|||
curl <endpoint> -F 'documents=@example.pdf' -F 'documents=@example.md;type=text/markdown'
|
||||
*/
|
||||
func (h *V1Handler) V1DocumentsPOST(c echo.Context) (err error) {
|
||||
var request apirequest.V1DocumentsPOST
|
||||
var request apirequest.CreateDocumentsResponse
|
||||
var response apiresponse.V1DocumentsPOST
|
||||
|
||||
request.Params.Bucket = c.Param("bucket")
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package apirequest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vlbeaudoin/voki/v3"
|
||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
||||
)
|
||||
|
||||
var _ voki.Requester[apiresponse.V1BucketsGET] = V1BucketsGET{}
|
||||
|
||||
type V1BucketsGET struct{}
|
||||
|
||||
func NewV1BucketsGET() (request V1BucketsGET, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (request V1BucketsGET) Complete() bool { return true }
|
||||
|
||||
func (request V1BucketsGET) Request(v *voki.Voki) (response apiresponse.V1BucketsGET, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1BucketsGET request")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/bucket", nil, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[apiresponse.V1BucketGET] = V1BucketGET{}
|
||||
|
||||
type V1BucketGET struct {
|
||||
Params struct {
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
}
|
||||
|
||||
func NewV1BucketGET(bucket string) (request V1BucketGET, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1BucketGET requires non-nil bucket name")
|
||||
}
|
||||
|
||||
request.Params.Bucket = bucket
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (request V1BucketGET) Complete() bool { return request.Params.Bucket != "" }
|
||||
|
||||
func (request V1BucketGET) Request(v *voki.Voki) (response apiresponse.V1BucketGET, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1BucketGET request")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), nil, true, &response)
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package apirequest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vlbeaudoin/voki/v3"
|
||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
||||
)
|
||||
|
||||
var _ voki.Requester[apiresponse.V1SeedPOST] = V1SeedPOST{}
|
||||
|
||||
type V1SeedPOST struct{}
|
||||
|
||||
func NewV1SeedPOST() (request V1SeedPOST, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (r V1SeedPOST) Complete() bool { return true }
|
||||
|
||||
func (r V1SeedPOST) Request(v *voki.Voki) (response apiresponse.V1SeedPOST, err error) {
|
||||
if !r.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1SeedPOST")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodPost, "/v1/seed", nil, true, &response)
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package apirequest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vlbeaudoin/voki/v3"
|
||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
||||
)
|
||||
|
||||
var _ voki.Requester[apiresponse.V1SpecGET] = V1SpecGET{}
|
||||
|
||||
type V1SpecGET struct{}
|
||||
|
||||
func NewV1SpecGET() (request V1SpecGET, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (request V1SpecGET) Complete() bool { return true }
|
||||
|
||||
func (request V1SpecGET) Request(v *voki.Voki) (response apiresponse.V1SpecGET, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1SpecGET")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/spec", nil, true, &response)
|
||||
}
|
|
@ -250,7 +250,7 @@ func RunServer() {
|
|||
}
|
||||
|
||||
if err := pave.EchoRegister[
|
||||
apirequest.V1DocumentsPOST,
|
||||
apirequest.CreateDocumentsResponse,
|
||||
apiresponse.V1DocumentsPOST](groupV1, &p, "/v1", http.MethodPost, "/bucket/:bucket/many", "Upload documents to specified bucket", "V1DocumentsPOST", v1Handler.V1DocumentsPOST); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package apirequest
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -8,12 +8,59 @@ import (
|
|||
"net/http"
|
||||
|
||||
"codeberg.org/vlbeaudoin/voki/v3"
|
||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
||||
)
|
||||
|
||||
var _ voki.Requester[apiresponse.V1DocumentsPOST] = V1DocumentsPOST{}
|
||||
var _ voki.Requester[ListBucketsResponse] = ListBucketsRequest{}
|
||||
|
||||
type V1DocumentsPOST struct {
|
||||
type ListBucketsRequest struct{}
|
||||
|
||||
func NewV1BucketsGET() (request ListBucketsRequest, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (request ListBucketsRequest) Complete() bool { return true }
|
||||
|
||||
func (request ListBucketsRequest) Request(v *voki.Voki) (response ListBucketsResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1BucketsGET request")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/bucket", nil, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[ReadBucketResponse] = ReadBucketRequest{}
|
||||
|
||||
type ReadBucketRequest struct {
|
||||
Params struct {
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
}
|
||||
|
||||
func NewV1BucketGET(bucket string) (request ReadBucketRequest, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1BucketGET requires non-nil bucket name")
|
||||
}
|
||||
|
||||
request.Params.Bucket = bucket
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (request ReadBucketRequest) Complete() bool { return request.Params.Bucket != "" }
|
||||
|
||||
func (request ReadBucketRequest) Request(v *voki.Voki) (response ReadBucketResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1BucketGET request")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), nil, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[CreateDocumentsResponse] = CreateDocumentsRequest{}
|
||||
|
||||
type CreateDocumentsRequest struct {
|
||||
Data struct {
|
||||
Documents []*multipart.FileHeader `json:"documents"`
|
||||
}
|
||||
|
@ -22,7 +69,7 @@ type V1DocumentsPOST struct {
|
|||
}
|
||||
}
|
||||
|
||||
func NewV1DocumentsPOST(bucket string, documents ...*multipart.FileHeader) (request V1DocumentsPOST, err error) {
|
||||
func NewV1DocumentsPOST(bucket string, documents ...*multipart.FileHeader) (request CreateDocumentsRequest, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1DocumentsPOST requires non-nil bucket name")
|
||||
return
|
||||
|
@ -47,7 +94,7 @@ func NewV1DocumentsPOST(bucket string, documents ...*multipart.FileHeader) (requ
|
|||
return
|
||||
}
|
||||
|
||||
func (request V1DocumentsPOST) Complete() bool {
|
||||
func (request CreateDocumentsRequest) Complete() bool {
|
||||
if request.Data.Documents == nil {
|
||||
return false
|
||||
}
|
||||
|
@ -60,7 +107,7 @@ func (request V1DocumentsPOST) Complete() bool {
|
|||
return request.Params.Bucket != ""
|
||||
}
|
||||
|
||||
func (request V1DocumentsPOST) Request(v *voki.Voki) (response apiresponse.V1DocumentsPOST, err error) {
|
||||
func (request CreateDocumentsRequest) Request(v *voki.Voki) (response CreateDocumentsResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1DocumentsPOST request")
|
||||
return
|
||||
|
@ -74,20 +121,18 @@ func (request V1DocumentsPOST) Request(v *voki.Voki) (response apiresponse.V1Doc
|
|||
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s/many", request.Params.Bucket), &buf, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[apiresponse.V1DocumentPOST] = V1DocumentPOST{}
|
||||
var _ voki.Requester[CreateDocumentResponse] = CreateDocumentRequest{}
|
||||
|
||||
// Deprecated: Use V1DocumentsPOST instead
|
||||
type V1DocumentPOST struct {
|
||||
type CreateDocumentRequest struct {
|
||||
Data struct {
|
||||
Document *multipart.FileHeader `document`
|
||||
Document *multipart.FileHeader `json:"document"`
|
||||
}
|
||||
Params struct {
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated: Use NewV1DocumentsPOST instead
|
||||
func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V1DocumentPOST, err error) {
|
||||
func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request CreateDocumentRequest, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1DocumentPOST requires non-nil bucket name")
|
||||
return
|
||||
|
@ -105,11 +150,11 @@ func NewV1DocumentPOST(bucket string, document *multipart.FileHeader) (request V
|
|||
return
|
||||
}
|
||||
|
||||
func (request V1DocumentPOST) Complete() bool {
|
||||
func (request CreateDocumentRequest) Complete() bool {
|
||||
return request.Params.Bucket != "" && request.Data.Document != nil
|
||||
}
|
||||
|
||||
func (request V1DocumentPOST) Request(v *voki.Voki) (response apiresponse.V1DocumentPOST, err error) {
|
||||
func (request CreateDocumentRequest) Request(v *voki.Voki) (response CreateDocumentResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1DocumentPOST request")
|
||||
return
|
||||
|
@ -123,16 +168,16 @@ func (request V1DocumentPOST) Request(v *voki.Voki) (response apiresponse.V1Docu
|
|||
return response, v.UnmarshalIfComplete(http.MethodPost, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), &buf, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[apiresponse.V1DocumentDELETE] = V1DocumentDELETE{}
|
||||
var _ voki.Requester[DeleteDocumentResponse] = DeleteDocumentRequest{}
|
||||
|
||||
type V1DocumentDELETE struct {
|
||||
type DeleteDocumentRequest struct {
|
||||
Params struct {
|
||||
Bucket string `json:"bucket"`
|
||||
Document string `json:"document"`
|
||||
}
|
||||
}
|
||||
|
||||
func NewV1DocumentDELETE(bucket, document string) (request V1DocumentDELETE, err error) {
|
||||
func NewV1DocumentDELETE(bucket, document string) (request DeleteDocumentRequest, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1DocumentDELETE requires non-nil bucket name")
|
||||
return
|
||||
|
@ -150,11 +195,11 @@ func NewV1DocumentDELETE(bucket, document string) (request V1DocumentDELETE, err
|
|||
return
|
||||
}
|
||||
|
||||
func (request V1DocumentDELETE) Complete() bool {
|
||||
func (request DeleteDocumentRequest) Complete() bool {
|
||||
return request.Params.Bucket != "" && request.Params.Document != ""
|
||||
}
|
||||
|
||||
func (request V1DocumentDELETE) Request(v *voki.Voki) (response apiresponse.V1DocumentDELETE, err error) {
|
||||
func (request DeleteDocumentRequest) Request(v *voki.Voki) (response DeleteDocumentResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1DocumentDELETE request")
|
||||
return
|
||||
|
@ -163,9 +208,9 @@ func (request V1DocumentDELETE) Request(v *voki.Voki) (response apiresponse.V1Do
|
|||
return response, v.UnmarshalIfComplete(http.MethodDelete, fmt.Sprintf("/v1/bucket/%s/%s", request.Params.Bucket, request.Params.Document), nil, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[apiresponse.V1DocumentKeyPUT] = V1DocumentKeyPUT{}
|
||||
var _ voki.Requester[UpdateDocumentKeyResponse] = UpdateDocumentKeyRequest{}
|
||||
|
||||
type V1DocumentKeyPUT struct {
|
||||
type UpdateDocumentKeyRequest struct {
|
||||
Data struct {
|
||||
NewKey string `json:"newKey"`
|
||||
}
|
||||
|
@ -175,7 +220,7 @@ type V1DocumentKeyPUT struct {
|
|||
}
|
||||
}
|
||||
|
||||
func NewV1DocumentKeyPUT(bucket, document, newKey string) (request V1DocumentKeyPUT, err error) {
|
||||
func NewV1DocumentKeyPUT(bucket, document, newKey string) (request UpdateDocumentKeyRequest, err error) {
|
||||
if bucket == "" {
|
||||
err = fmt.Errorf("NewV1DocumentKeyPUT requires non-nil bucket name")
|
||||
return
|
||||
|
@ -199,11 +244,11 @@ func NewV1DocumentKeyPUT(bucket, document, newKey string) (request V1DocumentKey
|
|||
return
|
||||
}
|
||||
|
||||
func (request V1DocumentKeyPUT) Complete() bool {
|
||||
func (request UpdateDocumentKeyRequest) Complete() bool {
|
||||
return request.Params.Bucket != "" && request.Params.Document != "" && request.Data.NewKey != ""
|
||||
}
|
||||
|
||||
func (request V1DocumentKeyPUT) Request(v *voki.Voki) (response apiresponse.V1DocumentKeyPUT, err error) {
|
||||
func (request UpdateDocumentKeyRequest) Request(v *voki.Voki) (response UpdateDocumentKeyResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1DocumentKeyPUT request")
|
||||
return
|
||||
|
@ -216,3 +261,41 @@ func (request V1DocumentKeyPUT) Request(v *voki.Voki) (response apiresponse.V1Do
|
|||
|
||||
return response, v.UnmarshalIfComplete(http.MethodPut, fmt.Sprintf("/v1/bucket/%s/%s", request.Params.Bucket, request.Params.Document), &buf, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[ExecuteSeedResponse] = ExecuteSeedRequest{}
|
||||
|
||||
type ExecuteSeedRequest struct{}
|
||||
|
||||
func NewV1SeedPOST() (request ExecuteSeedRequest, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (r ExecuteSeedRequest) Complete() bool { return true }
|
||||
|
||||
func (r ExecuteSeedRequest) Request(v *voki.Voki) (response ExecuteSeedResponse, err error) {
|
||||
if !r.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1SeedPOST")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodPost, "/v1/seed", nil, true, &response)
|
||||
}
|
||||
|
||||
var _ voki.Requester[ReadSpecResponse] = ReadSpecRequest{}
|
||||
|
||||
type ReadSpecRequest struct{}
|
||||
|
||||
func NewV1SpecGET() (request ReadSpecRequest, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (request ReadSpecRequest) Complete() bool { return true }
|
||||
|
||||
func (request ReadSpecRequest) Request(v *voki.Voki) (response ReadSpecResponse, err error) {
|
||||
if !request.Complete() {
|
||||
err = fmt.Errorf("Incomplete V1SpecGET")
|
||||
return
|
||||
}
|
||||
|
||||
return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/spec", nil, true, &response)
|
||||
}
|
|
@ -157,7 +157,7 @@ func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *WebHandler) HandleAdminDocumentsUploadPOST(c echo.Context) error {
|
||||
var request apirequest.V1DocumentsPOST
|
||||
var request apirequest.CreateDocumentsResponse
|
||||
var response HandleAdminDocumentsUploadResponse
|
||||
|
||||
v1BucketsGET, err := h.ApiClient.ListBuckets()
|
||||
|
|
Loading…
Reference in a new issue