2023-05-25 02:21:09 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-06-02 17:46:57 -04:00
|
|
|
"git.agecem.com/agecem/bottin/v5/data"
|
2023-05-25 02:21:09 -04:00
|
|
|
"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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|