Merge pull request 'Simplifier dataclient dans insert handler' (#21) from fix/insert-dataclientfromviper into main

Reviewed-on: #21
This commit is contained in:
Victor Lacasse-Beaudoin 2023-06-03 18:34:33 -05:00
commit e492e82960

View file

@ -6,19 +6,10 @@ import (
"git.agecem.com/agecem/bottin/v5/data"
"git.agecem.com/agecem/bottin/v5/models"
"github.com/labstack/echo/v4"
"github.com/spf13/viper"
)
func PostMembres(c echo.Context) error {
connection := data.PostgresConnection{
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)
client, err := data.NewDataClientFromViper()
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection",
@ -58,15 +49,7 @@ func PostMembres(c echo.Context) error {
}
func PostProgrammes(c echo.Context) error {
connection := data.PostgresConnection{
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)
client, err := data.NewDataClientFromViper()
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection",