refactor(order): improve setUp method

This commit is contained in:
Sahar Mokarrami 2026-04-05 13:02:19 +03:30
parent c841ffb21d
commit c5b96ee64e
1 changed files with 13 additions and 11 deletions

View File

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