2024-06-11 17:28:20 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-17 14:07:49 -04:00
|
|
|
"bytes"
|
2024-06-11 17:28:20 -04:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"codeberg.org/vlbeaudoin/voki/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ voki.Requester[HealthGETResponse] = HealthGETRequest{}
|
|
|
|
|
|
|
|
type HealthGETRequest struct{}
|
|
|
|
|
|
|
|
func (request HealthGETRequest) Complete() bool { return true }
|
|
|
|
|
|
|
|
func (request HealthGETRequest) Request(v *voki.Voki) (response HealthGETResponse, err error) {
|
|
|
|
if !request.Complete() {
|
|
|
|
err = fmt.Errorf("Incomplete HealthGET request")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statusCode, body, err := v.CallAndParse(
|
|
|
|
http.MethodGet,
|
|
|
|
"/api/health/",
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("%d: %s", statusCode, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
response.SetStatusCode(statusCode)
|
|
|
|
|
|
|
|
if err = json.Unmarshal(body, &response); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2024-06-17 14:07:49 -04:00
|
|
|
|
|
|
|
var _ voki.Requester[ProgrammesPOSTResponse] = ProgrammesPOSTRequest{}
|
|
|
|
|
|
|
|
type ProgrammesPOSTRequest struct {
|
|
|
|
Data struct {
|
|
|
|
Programmes []Programme
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (request ProgrammesPOSTRequest) Complete() bool {
|
|
|
|
return len(request.Data.Programmes) != 0
|
|
|
|
}
|
|
|
|
func (request ProgrammesPOSTRequest) Request(v *voki.Voki) (response ProgrammesPOSTResponse, err error) {
|
|
|
|
if !request.Complete() {
|
|
|
|
err = fmt.Errorf("Incomplete ProgrammesPOSTRequest")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err = json.NewEncoder(&buf).Encode(request.Data); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statusCode, body, err := v.CallAndParse(
|
|
|
|
http.MethodPost,
|
|
|
|
"/api/programmes/",
|
|
|
|
&buf,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("code=%d err=%s", statusCode, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
response.SetStatusCode(statusCode)
|
|
|
|
if err = json.Unmarshal(body, &response); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|