Ajouter et implémenter PresencesGET
This commit is contained in:
parent
75b0819ae4
commit
29b4d0da31
4 changed files with 47 additions and 1 deletions
|
@ -20,3 +20,7 @@ func (a *APIClient) Scan(membreID string) (response apiresponse.ScanPOST, err er
|
|||
func (a *APIClient) GetDecompte() (response apiresponse.DecompteGET, err error) {
|
||||
return response, a.Voki.Unmarshal(http.MethodGet, "/v0/decompte", nil, true, &response)
|
||||
}
|
||||
|
||||
func (a *APIClient) GetPresences() (response apiresponse.PresencesGET, err error) {
|
||||
return response, a.Voki.Unmarshal(http.MethodGet, "/v0/presences", nil, true, &response)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ func DeclareRoutes(e *echo.Group, h *APIHandler) {
|
|||
e.GET("/scan/:membre_id/", h.ScanGET)
|
||||
e.POST("/scan/:membre_id/", h.ScanPOST)
|
||||
e.GET("/decompte/", h.DecompteGET)
|
||||
e.GET("/presences/", h.PresencesGET)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -192,3 +193,24 @@ func (a *APIHandler) DecompteGET(c echo.Context) error {
|
|||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
||||
// PresencesGET is the handler for `GET /v:version/presences/ http/1.1`
|
||||
func (a *APIHandler) PresencesGET(c echo.Context) error {
|
||||
var r apiresponse.PresencesGET
|
||||
|
||||
presences, err := a.DBClient.GetPresences()
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
r.StatusCode = http.StatusInternalServerError
|
||||
r.Message = "Error during a.DBClient.GetPresences"
|
||||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
||||
r.Data.Presences = presences
|
||||
|
||||
r.StatusCode = http.StatusOK
|
||||
r.Message = "ok"
|
||||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
// Package apiresponse provides response types for API routes
|
||||
package apiresponse
|
||||
|
||||
import "codeberg.org/vlbeaudoin/voki/response"
|
||||
import (
|
||||
"codeberg.org/vlbeaudoin/voki/response"
|
||||
"git.agecem.com/agecem/bottin-ag/dbstruct"
|
||||
)
|
||||
|
||||
// HealthGET is the response type for `GET /v:version/health/ http/1.1`
|
||||
type HealthGET struct {
|
||||
|
@ -31,3 +34,11 @@ type DecompteGET struct {
|
|||
Decompte int
|
||||
}
|
||||
}
|
||||
|
||||
// PresencesGET is the response type for `GET /v:version/presences/ http/1.1`
|
||||
type PresencesGET struct {
|
||||
response.ResponseWithError
|
||||
Data struct {
|
||||
Presences []dbstruct.Presence
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,3 +78,12 @@ func (d *DBClient) GetDecompte() (decompte int, err error) {
|
|||
err = d.DB.Get(&decompte, "SELECT COUNT(*) FROM presences;")
|
||||
return decompte, err
|
||||
}
|
||||
|
||||
/*
|
||||
GetPresences returns all rows in the `presences` table and any error encountered
|
||||
|
||||
Can be used to export the database content at the end of the event.
|
||||
*/
|
||||
func (d *DBClient) GetPresences() (presences []dbstruct.Presence, err error) {
|
||||
return presences, d.DB.Select(&presences, "SELECT * FROM presences;")
|
||||
}
|
||||
|
|
Reference in a new issue