Merge branch 'feature/decompte'
This commit is contained in:
commit
75b0819ae4
9 changed files with 126 additions and 1 deletions
|
@ -14,6 +14,9 @@ type APIClient struct {
|
|||
}
|
||||
|
||||
func (a *APIClient) Scan(membreID string) (response apiresponse.ScanPOST, err error) {
|
||||
//TODO implement api key
|
||||
return response, a.Voki.Unmarshal(http.MethodPost, fmt.Sprintf("/v0/scan/%s", membreID), nil, true, &response)
|
||||
}
|
||||
|
||||
func (a *APIClient) GetDecompte() (response apiresponse.DecompteGET, err error) {
|
||||
return response, a.Voki.Unmarshal(http.MethodGet, "/v0/decompte", nil, true, &response)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ func DeclareRoutes(e *echo.Group, h *APIHandler) {
|
|||
e.GET("/health/", h.HealthGET)
|
||||
e.GET("/scan/:membre_id/", h.ScanGET)
|
||||
e.POST("/scan/:membre_id/", h.ScanPOST)
|
||||
e.GET("/decompte/", h.DecompteGET)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -168,3 +169,26 @@ func (a *APIHandler) ScanPOST(c echo.Context) error {
|
|||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
||||
// DecompteGET is the handler for `GET /v:version/decompte/ http/1.1`
|
||||
func (a *APIHandler) DecompteGET(c echo.Context) error {
|
||||
var r apiresponse.DecompteGET
|
||||
|
||||
r.Message = "not ok"
|
||||
|
||||
decompte, err := a.DBClient.GetDecompte()
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
r.StatusCode = http.StatusInternalServerError
|
||||
r.Message = "Error during a.DBClient.GetDecompte"
|
||||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
||||
r.Data.Decompte = decompte
|
||||
|
||||
r.StatusCode = http.StatusOK
|
||||
r.Message = "ok"
|
||||
|
||||
return c.JSON(r.StatusCode, r)
|
||||
}
|
||||
|
|
|
@ -23,3 +23,11 @@ type ScanGET struct {
|
|||
type ScanPOST struct {
|
||||
response.ResponseWithError
|
||||
}
|
||||
|
||||
// DecompteGET is the response type for `GET /v:version/decompte/ http/1.1`
|
||||
type DecompteGET struct {
|
||||
response.ResponseWithError
|
||||
Data struct {
|
||||
Decompte int
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,3 +72,9 @@ func (d *DBClient) InsertPresence(presence dbstruct.Presence) (dbstruct.Presence
|
|||
|
||||
return insertedPresence, nil
|
||||
}
|
||||
|
||||
// GetDecompte returns the row count of the `presences` table and any error encountered
|
||||
func (d *DBClient) GetDecompte() (decompte int, err error) {
|
||||
err = d.DB.Get(&decompte, "SELECT COUNT(*) FROM presences;")
|
||||
return decompte, err
|
||||
}
|
||||
|
|
4
webcontent/html/decompte.html
Normal file
4
webcontent/html/decompte.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{ define "decompte-html" }}
|
||||
Décompte: {{ .Data.Decompte }}
|
||||
<button hx-get="/nothing" hx-on:click="document.getElementById('app-dialog').style.display = 'none';">fermer</button>
|
||||
{{ end }}
|
|
@ -6,6 +6,19 @@
|
|||
<title>AGECEM | Assemblée Générale</title>
|
||||
<script src="/public/js/htmx.min.js"></script>
|
||||
<script src="/public/js/membreid-selected-and-cleared.js"></script>
|
||||
<style>
|
||||
#app-dialog {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: white;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
||||
padding: 20px;
|
||||
z-index: 555;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Présences en Assemblée Générale</h2>
|
||||
|
@ -18,8 +31,15 @@
|
|||
<button type="submit">enregistrer</button>
|
||||
</form>
|
||||
|
||||
<button hx-get="/decompte" hx-target="#app-dialog" hx-on:click="document.getElementById('app-dialog').style.display = 'block';">Afficher décompte</button>
|
||||
|
||||
<div id="app-dialog" style="display: none;">
|
||||
</div>
|
||||
|
||||
<div id="app-content">
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
{{ end }}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{ define "scan-html" }}
|
||||
<h3>{{ .Message }}</h3>
|
||||
{{ if .Error }}<h3>{{ .Error }}</h3>{{ end }}
|
||||
{{ end }}
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
func DeclareRoutes(e *echo.Echo, h *WebHandler) {
|
||||
e.GET("/", h.IndexGET)
|
||||
e.POST("/scan/", h.ScanPOST)
|
||||
e.GET("/decompte/", h.DecompteGET)
|
||||
e.GET("/nothing/", h.NothingGET)
|
||||
}
|
||||
|
||||
type WebHandler struct {
|
||||
|
@ -31,6 +33,19 @@ func (w *WebHandler) IndexGET(c echo.Context) error {
|
|||
r.Message = "foo"
|
||||
r.StatusCode = http.StatusOK
|
||||
|
||||
/*
|
||||
decompteResponse, err := w.APIClient.GetDecompte()
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
r.Message = "Impossible d'obtenir le décompte"
|
||||
r.StatusCode = http.StatusInternalServerError
|
||||
|
||||
return c.Render(r.StatusCode, "index-html", r)
|
||||
}
|
||||
|
||||
r.Data.Decompte = decompteResponse.Data.Decompte
|
||||
*/
|
||||
|
||||
return c.Render(r.StatusCode, "index-html", r)
|
||||
}
|
||||
|
||||
|
@ -44,6 +59,19 @@ func (w *WebHandler) ScanPOST(c echo.Context) error {
|
|||
|
||||
r.StatusCode = http.StatusOK
|
||||
|
||||
/*
|
||||
decompteResponse, err := w.APIClient.GetDecompte()
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
r.Message = "Impossible d'obtenir le décompte"
|
||||
r.StatusCode = http.StatusInternalServerError
|
||||
|
||||
return c.Render(r.StatusCode, "index-html", r)
|
||||
}
|
||||
|
||||
r.Data.Decompte = decompteResponse.Data.Decompte
|
||||
*/
|
||||
|
||||
scanResponse, err := w.APIClient.Scan(membreID)
|
||||
r.Error = scanResponse.Error
|
||||
if err != nil {
|
||||
|
@ -54,3 +82,27 @@ func (w *WebHandler) ScanPOST(c echo.Context) error {
|
|||
|
||||
return c.Render(r.StatusCode, "scan-html", r)
|
||||
}
|
||||
|
||||
func (w *WebHandler) DecompteGET(c echo.Context) error {
|
||||
var r webresponse.DecompteGET
|
||||
|
||||
decompteResponse, err := w.APIClient.GetDecompte()
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
r.Message = "Impossible d'obtenir le décompte"
|
||||
r.StatusCode = http.StatusInternalServerError
|
||||
|
||||
return c.Render(r.StatusCode, "decompte-html", r)
|
||||
}
|
||||
|
||||
r.Data.Decompte = decompteResponse.Data.Decompte
|
||||
|
||||
r.StatusCode = http.StatusOK
|
||||
r.Message = "ok"
|
||||
|
||||
return c.Render(r.StatusCode, "decompte-html", r)
|
||||
}
|
||||
|
||||
func (w *WebHandler) NothingGET(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, nil)
|
||||
}
|
||||
|
|
|
@ -9,3 +9,10 @@ type IndexGET struct {
|
|||
type ScanPOST struct {
|
||||
response.ResponseWithError
|
||||
}
|
||||
|
||||
type DecompteGET struct {
|
||||
response.ResponseWithError
|
||||
Data struct {
|
||||
Decompte int
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue