bottin/client.go
Victor Lacasse-Beaudoin e847f693e0 rework: renommer champs dans entities et ajouter MembresPOST
- ajouter et tester InsertMembres
- ajouter sql/views.sql
- ajouter view `membres_for_display` -> concat names ou prefered name
- rendre plusieurs champs NOT NULL dans schema
2024-06-17 17:25:53 -04:00

60 lines
1.2 KiB
Go

package main
import (
"fmt"
"codeberg.org/vlbeaudoin/voki/v3"
)
type APIClient struct {
Voki *voki.Voki
}
func (c APIClient) GetHealth() (health string, err error) {
var request HealthGETRequest
response, err := request.Request(c.Voki)
if err != nil {
return "", err
}
if code, message := response.StatusCode(), response.Message; code >= 400 {
err = fmt.Errorf("%d: %s", code, message)
return
}
return response.Message, nil
}
func (c APIClient) InsertProgrammes(programmes ...Programme) (amountInserted int64, err error) {
var request ProgrammesPOSTRequest
request.Data.Programmes = programmes
response, err := request.Request(c.Voki)
if err != nil {
return
}
if code, message := response.StatusCode(), response.Message; code >= 400 {
err = fmt.Errorf("%d: %s", code, message)
return
}
return response.Data.ProgrammesInserted, nil
}
func (c APIClient) InsertMembres(membres ...Membre) (amountInserted int64, err error) {
var request MembresPOSTRequest
request.Data.Membres = membres
response, err := request.Request(c.Voki)
if err != nil {
return
}
if code, message := response.StatusCode(), response.Message; code >= 400 {
err = fmt.Errorf("%d: %s", code, message)
return
}
return response.Data.MembresInserted, nil
}