2017-12-06 21:09:47 -05:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aclindsa/moneygo/internal/models"
|
2017-12-07 21:05:55 -05:00
|
|
|
"time"
|
2017-12-06 21:09:47 -05:00
|
|
|
)
|
|
|
|
|
2017-12-07 20:08:43 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:05:55 -05:00
|
|
|
type SessionStore interface {
|
|
|
|
SessionExists(secret string) (bool, error)
|
|
|
|
InsertSession(session *models.Session) error
|
|
|
|
GetSession(secret string) (*models.Session, error)
|
|
|
|
DeleteSession(session *models.Session) error
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:47:55 -05:00
|
|
|
type SecurityInUseError struct {
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e SecurityInUseError) Error() string {
|
|
|
|
return e.Message
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:08:43 -05:00
|
|
|
type SecurityStore interface {
|
|
|
|
InsertSecurity(security *models.Security) error
|
|
|
|
GetSecurity(securityid int64, userid int64) (*models.Security, error)
|
|
|
|
GetSecurities(userid int64) (*[]*models.Security, error)
|
2017-12-07 20:47:55 -05:00
|
|
|
FindMatchingSecurities(security *models.Security) (*[]*models.Security, error)
|
2017-12-07 20:08:43 -05:00
|
|
|
UpdateSecurity(security *models.Security) error
|
|
|
|
DeleteSecurity(security *models.Security) error
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:05:55 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:47:55 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-12-08 21:27:03 -05:00
|
|
|
type AccountMissingError struct{}
|
|
|
|
|
|
|
|
func (ame AccountMissingError) Error() string {
|
|
|
|
return "Account missing"
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:05:55 -05:00
|
|
|
type TransactionStore interface {
|
2017-12-08 21:27:03 -05:00
|
|
|
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
|
2017-12-12 20:17:39 -05:00
|
|
|
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)
|
2017-12-08 21:27:03 -05:00
|
|
|
GetAccountTransactions(user *models.User, accountid int64, sort string, page uint64, limit uint64) (*models.AccountTransactionsList, error)
|
2017-12-07 21:05:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type ReportStore interface {
|
2017-12-09 05:56:45 -05:00
|
|
|
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
|
2017-12-07 21:05:55 -05:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:09:47 -05:00
|
|
|
type Tx interface {
|
|
|
|
Commit() error
|
|
|
|
Rollback() error
|
|
|
|
|
2017-12-07 20:08:43 -05:00
|
|
|
UserStore
|
2017-12-07 21:05:55 -05:00
|
|
|
SessionStore
|
2017-12-07 20:08:43 -05:00
|
|
|
SecurityStore
|
2017-12-07 21:05:55 -05:00
|
|
|
PriceStore
|
2017-12-07 20:47:55 -05:00
|
|
|
AccountStore
|
2017-12-07 21:05:55 -05:00
|
|
|
TransactionStore
|
|
|
|
ReportStore
|
2017-12-06 21:09:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Store interface {
|
2017-12-09 06:06:20 -05:00
|
|
|
Empty() error
|
2017-12-06 21:09:47 -05:00
|
|
|
Begin() (Tx, error)
|
|
|
|
Close() error
|
|
|
|
}
|