-
Notifications
You must be signed in to change notification settings - Fork 1
/
balance_limit.go
48 lines (40 loc) · 1.32 KB
/
balance_limit.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
package logic
import (
"math"
"github.com/ic3network/mccs-alpha-api/internal/app/repository/pg"
"github.com/ic3network/mccs-alpha-api/internal/app/types"
)
type balanceLimit struct{}
var BalanceLimit = balanceLimit{}
// IsExceedLimit checks whether or not the account exceeds the max positive or max negative limit.
func (b balanceLimit) IsExceedLimit(accountNumber string, balance float64) (bool, error) {
limit, err := pg.BalanceLimit.FindByAccountNumber(accountNumber)
if err != nil {
return false, err
}
if balance < -(math.Abs(limit.MaxNegBal)) || balance > limit.MaxPosBal {
return true, nil
}
return false, nil
}
func (b balanceLimit) FindByAccountNumber(accountNumber string) (*types.BalanceLimit, error) {
record, err := pg.BalanceLimit.FindByAccountNumber(accountNumber)
if err != nil {
return nil, err
}
return record, nil
}
func (b balanceLimit) GetMaxPosBalance(accountNumber string) (float64, error) {
balanceLimitRecord, err := pg.BalanceLimit.FindByAccountNumber(accountNumber)
if err != nil {
return 0, err
}
return balanceLimitRecord.MaxPosBal, nil
}
func (b balanceLimit) GetMaxNegBalance(accountNumber string) (float64, error) {
balanceLimitRecord, err := pg.BalanceLimit.FindByAccountNumber(accountNumber)
if err != nil {
return 0, err
}
return math.Abs(balanceLimitRecord.MaxNegBal), nil
}