/
balance_mock.go
63 lines (53 loc) · 1.36 KB
/
balance_mock.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
56
57
58
59
60
61
62
63
package bitflyer
import (
"errors"
"github.com/Fukkatsuso/cryptocurrency-trading-bot/dashboard/domain/model"
"github.com/Fukkatsuso/cryptocurrency-trading-bot/dashboard/domain/repository"
)
type bitflyerBalanceMockRepository struct {
}
func NewBitFlyerBalanceMockRepository() repository.BalanceRepository {
return &bitflyerBalanceMockRepository{}
}
func (bbr *bitflyerBalanceMockRepository) FetchAll() ([]model.Balance, error) {
balances := []Balance{
{
CurrencyCode: "JPY",
Amount: 10000,
Available: 10000,
},
{
CurrencyCode: "BTC",
Amount: 0,
Available: 0,
},
{
CurrencyCode: "ETH",
Amount: 0.01,
Available: 0.01,
},
{
CurrencyCode: "XRP",
Amount: 0,
Available: 0,
},
}
// ドメインモデルに移し替える
domainModelBalances := make([]model.Balance, len(balances))
for i, balance := range balances {
domainModelBalances[i] = *balance.toDomainModelBalance()
}
return domainModelBalances, nil
}
func (bbr *bitflyerBalanceMockRepository) FetchByCurrencyCode(currencyCode string) (*model.Balance, error) {
balances, err := bbr.FetchAll()
if err != nil {
return nil, errors.New("cannot fetch balance")
}
for _, balance := range balances {
if balance.CurrencyCode() == currencyCode {
return &balance, nil
}
}
return nil, errors.New("invalid currencyCode")
}