Bump root version to v4
Remove all files from v3 Move all files from v4/ to project root
This commit is contained in:
parent
3c0d45fa04
commit
9a0bf87e7b
40 changed files with 423 additions and 2130 deletions
64
web/webhandlers/handlers.go
Normal file
64
web/webhandlers/handlers.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
package webhandlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin/v4/data"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetIndex(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "index-html", nil)
|
||||
}
|
||||
|
||||
func GetMembre(c echo.Context) error {
|
||||
apiClientKey := viper.GetString("web.api.key")
|
||||
apiClientHost := viper.GetString("web.api.host")
|
||||
apiClientProtocol := viper.GetString("web.api.protocol")
|
||||
apiClientPort := viper.GetInt("web.api.port")
|
||||
|
||||
/*
|
||||
log.Printf(`
|
||||
apiClientKey: %s
|
||||
apiClientHost: %s
|
||||
apiClientProtocol: %s
|
||||
apiClientPort: %d`,
|
||||
apiClientKey, apiClientHost, apiClientProtocol, apiClientPort,
|
||||
)
|
||||
*/
|
||||
|
||||
apiClient := data.NewApiClient(apiClientKey, apiClientHost, apiClientProtocol, apiClientPort)
|
||||
|
||||
membreID := c.QueryParam("membre_id")
|
||||
|
||||
/*
|
||||
// TODO
|
||||
log.Printf("Requesting membreID: [%s]", membreID)
|
||||
*/
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
Reference in a new issue