feature(request): ajouter MembrePreferedNamePUT et ProgrammesGET

This commit is contained in:
Victor Lacasse-Beaudoin 2024-06-18 23:55:55 -04:00
parent 4d338f2b03
commit 26b3134861

View file

@ -195,3 +195,81 @@ func (request MembresGETRequest) Request(v *voki.Voki) (response MembresGETRespo
return
}
var _ voki.Requester[MembrePreferedNamePUTResponse] = MembrePreferedNamePUTRequest{}
type MembrePreferedNamePUTRequest struct {
Data struct {
PreferedName string `json:"prefered_name"`
} `json:"data"`
Param struct {
MembreID string `json:"membre_id" param:"membre_id"`
} `json:"param"`
}
func (request MembrePreferedNamePUTRequest) Complete() bool {
return IsMembreID(request.Param.MembreID) && len(request.Data.PreferedName) != 0
}
func (request MembrePreferedNamePUTRequest) Request(v *voki.Voki) (response MembrePreferedNamePUTResponse, err error) {
if !request.Complete() {
err = fmt.Errorf("Incomplete MembrePreferedNamePUTRequest")
return
}
var buf bytes.Buffer
if err = json.NewEncoder(&buf).Encode(request.Data); err != nil {
return
}
statusCode, body, err := v.CallAndParse(
http.MethodPut,
"/api/v7/membre/%s/",
&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
}
var _ voki.Requester[ProgrammesGETResponse] = ProgrammesGETRequest{}
type ProgrammesGETRequest struct {
Query struct {
Limit int `json:"limit" query:"limit"`
}
}
func (request ProgrammesGETRequest) Complete() bool { return true }
func (request ProgrammesGETRequest) Request(v *voki.Voki) (response ProgrammesGETResponse, err error) {
if !request.Complete() {
err = fmt.Errorf("Incomplete ProgrammesGETRequest")
return
}
statusCode, body, err := v.CallAndParse(
http.MethodGet,
fmt.Sprintf("/api/v7/programme/?limit=%d", request.Query.Limit),
nil,
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
}