Datenbank seeder hinzugefügt
This commit is contained in:
@@ -4,12 +4,15 @@ import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"moretcgshop/app/models"
|
||||
"moretcgshop/database/seeders"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -41,6 +44,7 @@ var sessionUser = "user-session"
|
||||
|
||||
func (server *Server) Initialize(appConfig AppConfig, dbConfig DBConfig) {
|
||||
fmt.Println("Willkommen zu " + appConfig.AppName)
|
||||
|
||||
server.initializeDB(dbConfig)
|
||||
server.initializeAppConfig(appConfig)
|
||||
server.routeInit()
|
||||
@@ -84,8 +88,26 @@ func (server *Server) Run(addr string) {
|
||||
log.Fatal(http.ListenAndServe(addr, server.Router))
|
||||
}
|
||||
|
||||
func (s Server) InitCommands(config AppConfig, config2 DBConfig) {
|
||||
func (server *Server) InitCommands(config AppConfig, dbConfig DBConfig) {
|
||||
server.initializeDB(dbConfig)
|
||||
cmdApp := cli.NewApp()
|
||||
cmdApp.Commands = []cli.Command{
|
||||
{
|
||||
Name: "db:seed",
|
||||
Action: func(c *cli.Context) error {
|
||||
err := seeders.DBSeed(server.DB)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := cmdApp.Run(os.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func MakePassword(password string) (string, error) {
|
||||
|
||||
@@ -23,7 +23,9 @@ func (server *Server) Products(w http.ResponseWriter, r *http.Request) {
|
||||
perPage := 9
|
||||
|
||||
productModel := models.Product{}
|
||||
|
||||
products, totalRows, err := productModel.GetProducts(server.DB, perPage, page)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user