34 lines
755 B
Go
34 lines
755 B
Go
package controller
|
|
|
|
import (
|
|
"github.com/r3labs/sse/v2"
|
|
"gitlab.unjx.de/flohoss/cafe-plaetschwiesle/internal/database"
|
|
"gitlab.unjx.de/flohoss/cafe-plaetschwiesle/internal/env"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Controller struct {
|
|
orm *gorm.DB
|
|
env *env.Config
|
|
SSE *sse.Server
|
|
}
|
|
|
|
func NewController(env *env.Config) *Controller {
|
|
db := database.NewDatabaseConnection(&database.Database{
|
|
Host: env.DB_Host,
|
|
User: env.DB_User,
|
|
Password: env.DB_Password,
|
|
Database: env.DB_Database,
|
|
})
|
|
|
|
db.AutoMigrate(&Table{})
|
|
db.AutoMigrate(&Order{})
|
|
db.AutoMigrate(&OrderItem{})
|
|
db.AutoMigrate(&Bill{})
|
|
db.AutoMigrate(&BillItem{})
|
|
db.AutoMigrate(&User{})
|
|
|
|
ctrl := Controller{orm: db, env: env, SSE: sse.New()}
|
|
ctrl.setupEventChannel()
|
|
return &ctrl
|
|
}
|