-
Notifications
You must be signed in to change notification settings - Fork 39
/
store.go
123 lines (102 loc) · 3.76 KB
/
store.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package store
import (
"github.com/aclindsa/moneygo/internal/models"
"time"
)
type UserStore interface {
UsernameExists(username string) (bool, error)
InsertUser(user *models.User) error
GetUser(userid int64) (*models.User, error)
GetUserByUsername(username string) (*models.User, error)
UpdateUser(user *models.User) error
DeleteUser(user *models.User) error
}
type SessionStore interface {
SessionExists(secret string) (bool, error)
InsertSession(session *models.Session) error
GetSession(secret string) (*models.Session, error)
DeleteSession(session *models.Session) error
}
type SecurityInUseError struct {
Message string
}
func (e SecurityInUseError) Error() string {
return e.Message
}
type SecurityStore interface {
InsertSecurity(security *models.Security) error
GetSecurity(securityid int64, userid int64) (*models.Security, error)
GetSecurities(userid int64) (*[]*models.Security, error)
FindMatchingSecurities(security *models.Security) (*[]*models.Security, error)
UpdateSecurity(security *models.Security) error
DeleteSecurity(security *models.Security) error
}
type PriceStore interface {
PriceExists(price *models.Price) (bool, error)
InsertPrice(price *models.Price) error
GetPrice(priceid, securityid int64) (*models.Price, error)
GetPrices(securityid int64) (*[]*models.Price, error)
GetLatestPrice(security, currency *models.Security, date *time.Time) (*models.Price, error)
GetEarliestPrice(security, currency *models.Security, date *time.Time) (*models.Price, error)
UpdatePrice(price *models.Price) error
DeletePrice(price *models.Price) error
}
type ParentAccountMissingError struct{}
func (pame ParentAccountMissingError) Error() string {
return "Parent account missing"
}
type TooMuchNestingError struct{}
func (tmne TooMuchNestingError) Error() string {
return "Too much account nesting"
}
type CircularAccountsError struct{}
func (cae CircularAccountsError) Error() string {
return "Would result in circular account relationship"
}
type AccountStore interface {
InsertAccount(account *models.Account) error
GetAccount(accountid int64, userid int64) (*models.Account, error)
GetAccounts(userid int64) (*[]*models.Account, error)
FindMatchingAccounts(account *models.Account) (*[]*models.Account, error)
UpdateAccount(account *models.Account) error
DeleteAccount(account *models.Account) error
}
type AccountMissingError struct{}
func (ame AccountMissingError) Error() string {
return "Account missing"
}
type TransactionStore interface {
SplitExists(s *models.Split) (bool, error)
InsertTransaction(t *models.Transaction, user *models.User) error
GetTransaction(transactionid int64, userid int64) (*models.Transaction, error)
GetTransactions(userid int64) (*[]*models.Transaction, error)
UpdateTransaction(t *models.Transaction, user *models.User) error
DeleteTransaction(t *models.Transaction, user *models.User) error
GetAccountBalance(user *models.User, accountid int64) (*models.Amount, error)
GetAccountBalanceDate(user *models.User, accountid int64, date *time.Time) (*models.Amount, error)
GetAccountBalanceDateRange(user *models.User, accountid int64, begin, end *time.Time) (*models.Amount, error)
GetAccountTransactions(user *models.User, accountid int64, sort string, page uint64, limit uint64) (*models.AccountTransactionsList, error)
}
type ReportStore interface {
InsertReport(report *models.Report) error
GetReport(reportid int64, userid int64) (*models.Report, error)
GetReports(userid int64) (*[]*models.Report, error)
UpdateReport(report *models.Report) error
DeleteReport(report *models.Report) error
}
type Tx interface {
Commit() error
Rollback() error
UserStore
SessionStore
SecurityStore
PriceStore
AccountStore
TransactionStore
ReportStore
}
type Store interface {
Empty() error
Begin() (Tx, error)
Close() error
}