bottin/handlers/seed.go
Victor Lacasse-Beaudoin 9a0bf87e7b Bump root version to v4
Remove all files from v3

Move all files from v4/ to project root
2023-05-29 18:19:31 -04:00

43 lines
976 B
Go

package handlers
import (
"net/http"
"git.agecem.com/agecem/bottin/v4/data"
"github.com/labstack/echo/v4"
"github.com/spf13/viper"
)
func PostSeed(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)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Could not establish database connection",
"error": err.Error(),
})
}
rows, err := client.Seed()
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Seed failed",
"error": err.Error(),
})
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": "Seed successful",
"data": map[string]interface{}{
"rows": rows,
},
})
}