forked from ebhomengo/niki
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package purchaseapp
|
|
|
|
import (
|
|
"fmt"
|
|
purchaseHTTP "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http"
|
|
purchaseHandler "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http/order"
|
|
purchaseMysql "git.gocasts.ir/ebhomengo/niki/purchaseapp/repository/mysql"
|
|
purchaseService "git.gocasts.ir/ebhomengo/niki/purchaseapp/service/order"
|
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
|
)
|
|
|
|
type Application struct {
|
|
Config Config
|
|
HTTPServer *purchaseHTTP.Server
|
|
purchaseService purchaseService.Service
|
|
PurchaseHandler *purchaseHandler.Handler
|
|
PurchaseRepo purchaseService.Repo
|
|
DB *mysql.DB
|
|
}
|
|
|
|
func SetUp() *Application {
|
|
|
|
cfg := mysql.Config{
|
|
Username: "niki",
|
|
Password: "nikiappt0lk2o20",
|
|
Port: 3306,
|
|
Host: "localhost",
|
|
DBName: "niki_db",
|
|
}
|
|
db := mysql.New(cfg)
|
|
defer func() {
|
|
if err := db.CloseStatements(); err != nil {
|
|
fmt.Printf("Error closing statements: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
orderRepo := purchaseMysql.New(db)
|
|
|
|
orderSvc := Service(orderRepo)
|
|
server := HTTPServer(orderSvc)
|
|
|
|
return &Application{
|
|
Config: Config{},
|
|
HTTPServer: server,
|
|
purchaseService: orderSvc,
|
|
PurchaseHandler: purchaseHandler.New(orderSvc),
|
|
PurchaseRepo: orderRepo,
|
|
DB: db,
|
|
}
|
|
|
|
}
|
|
|
|
func HTTPServer(orderSvc purchaseService.Service) *purchaseHTTP.Server {
|
|
return purchaseHTTP.New(orderSvc)
|
|
}
|
|
|
|
func Service(orderRepo *purchaseMysql.DB) purchaseService.Service {
|
|
return purchaseService.New(orderRepo)
|
|
}
|