-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 1.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"database/sql"
"fmt"
"log"
"github.com/pedro-mello30/bankmicroservice/domain"
"github.com/pedro-mello30/bankmicroservice/infrastructure/repository"
"github.com/pedro-mello30/bankmicroservice/usecase"
_ "github.com/lib/pq"
)
func main() {
db := setupDb()
defer db.Close()
cc := domain.NewCreditCard()
cc.Number = "1234"
cc.Name = "Pedro Mello"
cc.ExpirationMonth = 6
cc.ExpirationYear = 2022
cc.CVV = 123
cc.Limit = 10000
cc.Balance = 0
repo := repository.NewTransactionRepositoryDb(db)
err := repo.CreateCreditCard(*cc)
if err != nil {
fmt.Println(err)
}
}
func setupTransactionUseCase(db *sql.DB) usecase.UseCaseTransaction {
transactionRepository := repository.NewTransactionRepositoryDb(db)
useCase := usecase.NewUseCaseTransaction(transactionRepository)
return useCase
}
func setupDb() *sql.DB {
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
"db",
"5432",
"postgres",
"root",
"codebank",
)
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
fmt.Printf("%s", err)
log.Fatal("error connect to database")
}
return db
}