forked from ebhomengo/niki
refactor(order): improve setUp method
This commit is contained in:
parent
c841ffb21d
commit
c5b96ee64e
|
|
@ -1,6 +1,7 @@
|
||||||
package purchaseapp
|
package purchaseapp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
purchaseHTTP "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http"
|
purchaseHTTP "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http"
|
||||||
purchaseHandler "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http/order"
|
purchaseHandler "git.gocasts.ir/ebhomengo/niki/purchaseapp/delivery/http/order"
|
||||||
|
|
@ -18,16 +19,16 @@ type Application struct {
|
||||||
DB *mysql.DB
|
DB *mysql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUp() *Application {
|
func SetUp(ctx context.Context, config Config, DB mysql.DB) *Application {
|
||||||
|
|
||||||
cfg := mysql.Config{
|
//cfg := mysql.Config{
|
||||||
Username: "niki",
|
// Username: "niki",
|
||||||
Password: "nikiappt0lk2o20",
|
// Password: "nikiappt0lk2o20",
|
||||||
Port: 3306,
|
// Port: 3306,
|
||||||
Host: "localhost",
|
// Host: "localhost",
|
||||||
DBName: "niki_db",
|
// DBName: "niki_db",
|
||||||
}
|
//}
|
||||||
db := mysql.New(cfg)
|
db := mysql.New(config.Mysql)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := db.CloseStatements(); err != nil {
|
if err := db.CloseStatements(); err != nil {
|
||||||
fmt.Printf("Error closing statements: %v\n", err)
|
fmt.Printf("Error closing statements: %v\n", err)
|
||||||
|
|
@ -38,14 +39,15 @@ func SetUp() *Application {
|
||||||
|
|
||||||
orderSvc := Service(orderRepo)
|
orderSvc := Service(orderRepo)
|
||||||
server := HTTPServer(orderSvc)
|
server := HTTPServer(orderSvc)
|
||||||
|
handler := purchaseHandler.New(orderSvc)
|
||||||
|
|
||||||
return &Application{
|
return &Application{
|
||||||
Config: Config{},
|
Config: Config{},
|
||||||
HTTPServer: server,
|
HTTPServer: server,
|
||||||
purchaseService: orderSvc,
|
purchaseService: orderSvc,
|
||||||
PurchaseHandler: purchaseHandler.New(orderSvc),
|
PurchaseHandler: handler,
|
||||||
PurchaseRepo: orderRepo,
|
PurchaseRepo: orderRepo,
|
||||||
DB: db,
|
DB: &DB,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue