-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.go
40 lines (30 loc) · 1.03 KB
/
wallet.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
package service
import (
"github.com/skorolevskiy/wallet-backend-go/internal/domain"
"github.com/skorolevskiy/wallet-backend-go/internal/repository"
)
type WalletService struct {
repo repository.Wallet
}
func NewWalletService(repo repository.Wallet) *WalletService {
return &WalletService{repo: repo}
}
func (s *WalletService) CreateWallet(userId int64, wallet domain.Wallet) (int64, error) {
wallet.Balance = 0
return s.repo.CreateWallet(userId, wallet)
}
func (s *WalletService) GetAllWallets(userId int64) ([]domain.Wallet, error) {
return s.repo.GetAllWallets(userId)
}
func (s *WalletService) GetWalletById(userId, walletId int64) (domain.Wallet, error) {
return s.repo.GetWalletById(userId, walletId)
}
func (s *WalletService) UpdateWallet(userId, walletId int64, input domain.UpdateWalletInput) error {
if err := input.Validate(); err != nil {
return err
}
return s.repo.UpdateWallet(userId, walletId, input)
}
func (s *WalletService) DeleteWallet(userId, walletId int64) error {
return s.repo.DeleteWallet(userId, walletId)
}