Implémenter client web #19

Merged
vlbeaudoin merged 4 commits from feature/web into main 2023-06-10 00:10:26 -04:00
Showing only changes of commit 2287f00e29 - Show all commits

View file

@ -1,43 +1,11 @@
package webhandlers package webhandlers
import ( import (
"fmt"
"net/http" "net/http"
"git.agecem.com/agecem/bottin/v5/data"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func GetIndex(c echo.Context) error { func GetIndex(c echo.Context) error {
return c.Render(http.StatusOK, "index-html", nil) return c.Render(http.StatusOK, "index-html", nil)
} }
func GetMembre(c echo.Context) error {
apiClient := data.NewApiClientFromViper()
membreID := c.QueryParam("membre_id")
membre, err := 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,
})
}