Merge branch 'feature/presencesget'

This commit is contained in:
Victor Lacasse-Beaudoin 2023-10-02 14:08:20 -04:00
commit dc65ce6c4d
4 changed files with 47 additions and 1 deletions

View file

@ -20,3 +20,7 @@ func (a *APIClient) Scan(membreID string) (response apiresponse.ScanPOST, err er
func (a *APIClient) GetDecompte() (response apiresponse.DecompteGET, err error) { func (a *APIClient) GetDecompte() (response apiresponse.DecompteGET, err error) {
return response, a.Voki.Unmarshal(http.MethodGet, "/v0/decompte", nil, true, &response) 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)
}

View file

@ -18,6 +18,7 @@ func DeclareRoutes(e *echo.Group, h *APIHandler) {
e.GET("/scan/:membre_id/", h.ScanGET) e.GET("/scan/:membre_id/", h.ScanGET)
e.POST("/scan/:membre_id/", h.ScanPOST) e.POST("/scan/:membre_id/", h.ScanPOST)
e.GET("/decompte/", h.DecompteGET) 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) 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)
}

View file

@ -1,7 +1,10 @@
// Package apiresponse provides response types for API routes // Package apiresponse provides response types for API routes
package apiresponse 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` // HealthGET is the response type for `GET /v:version/health/ http/1.1`
type HealthGET struct { type HealthGET struct {
@ -31,3 +34,11 @@ type DecompteGET struct {
Decompte int 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
}
}

View file

@ -78,3 +78,12 @@ func (d *DBClient) GetDecompte() (decompte int, err error) {
err = d.DB.Get(&decompte, "SELECT COUNT(*) FROM presences;") err = d.DB.Get(&decompte, "SELECT COUNT(*) FROM presences;")
return decompte, err 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;")
}