Simplifier dataclient dans insert handler #21

Merged
vlbeaudoin merged 1 commit from fix/insert-dataclientfromviper into main 2023-06-03 19:34:34 -04:00
Showing only changes of commit 1ca4670375 - Show all commits

View file

@ -6,19 +6,10 @@ import (
"git.agecem.com/agecem/bottin/v5/data" "git.agecem.com/agecem/bottin/v5/data"
"git.agecem.com/agecem/bottin/v5/models" "git.agecem.com/agecem/bottin/v5/models"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/spf13/viper"
) )
func PostMembres(c echo.Context) error { func PostMembres(c echo.Context) error {
connection := data.PostgresConnection{ client, err := data.NewDataClientFromViper()
User: viper.GetString("db.user"),
Password: viper.GetString("db.password"),
Host: viper.GetString("db.host"),
Database: viper.GetString("db.database"),
Port: viper.GetInt("db.port"),
}
client, err := data.NewDataClient(connection)
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{ return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection", "message": "Could not establish database connection",
@ -58,15 +49,7 @@ func PostMembres(c echo.Context) error {
} }
func PostProgrammes(c echo.Context) error { func PostProgrammes(c echo.Context) error {
connection := data.PostgresConnection{ client, err := data.NewDataClientFromViper()
User: viper.GetString("db.user"),
Password: viper.GetString("db.password"),
Host: viper.GetString("db.host"),
Database: viper.GetString("db.database"),
Port: viper.GetInt("db.port"),
}
client, err := data.NewDataClient(connection)
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{ return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection", "message": "Could not establish database connection",