46 lines
983 B
Go
46 lines
983 B
Go
package webhandlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.agecem.com/agecem/bottin/v5/data"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type Handler struct {
|
|
APIClient *data.ApiClient
|
|
}
|
|
|
|
func (h *Handler) GetIndex(c echo.Context) error {
|
|
return c.Render(http.StatusOK, "index-html", nil)
|
|
}
|
|
|
|
func (h *Handler) GetMembre(c echo.Context) error {
|
|
|
|
membreID := c.QueryParam("membre_id")
|
|
|
|
membre, err := h.APIClient.GetMembre(membreID)
|
|
if err != nil {
|
|
return c.Render(http.StatusBadRequest, "index-html", struct {
|
|
Result string
|
|
}{
|
|
Result: fmt.Sprintln("👎", err.Error()),
|
|
})
|
|
}
|
|
|
|
membreResult := fmt.Sprintf(`👍
|
|
Membre trouvéE: [%s]`, membre.ID)
|
|
|
|
if membre.PreferedName != "" {
|
|
membreResult = fmt.Sprintf("%s -> %s", membreResult, membre.PreferedName)
|
|
} else {
|
|
membreResult = fmt.Sprintf("%s -> %s, %s", membreResult, membre.LastName, membre.FirstName)
|
|
}
|
|
|
|
return c.Render(http.StatusOK, "index-html", struct {
|
|
Result string
|
|
}{
|
|
Result: membreResult,
|
|
})
|
|
}
|