Documentation ¶
Index ¶
- Variables
- type Account
- type AccountController
- func (controller *AccountController) DeleteAccount(ctx *gin.Context)
- func (controller *AccountController) DoTransaction(ctx *gin.Context)
- func (controller *AccountController) GetAccount(ctx *gin.Context)
- func (controller *AccountController) GetAccounts(ctx *gin.Context)
- func (controller *AccountController) GivePermissionToUser(ctx *gin.Context)
- func (controller *AccountController) NewAccount(ctx *gin.Context)
- func (controller *AccountController) UpdateAccount(ctx *gin.Context)
- type AccountOwner
- type AccountRepo
- func (ar *AccountRepo) BackupTo(bkpDest string) error
- func (ar *AccountRepo) DeleteInstance(accID string) error
- func (ar *AccountRepo) GetAllAccounts() ([]*Account, error)
- func (ar *AccountRepo) GetInstance(accID string) (*Account, error)
- func (ar *AccountRepo) GetTransactions() ([]*Transaction, error)
- func (ar *AccountRepo) GetTransactionsPages(from, to *time.Time) ([]*Transaction, error)
- func (ar *AccountRepo) SaveInstance(acc *Account) error
- func (ar *AccountRepo) SaveTransaction(trans *Transaction) error
- type AccountService
- func (service *AccountService) Add(new *Account, userID string, perm permissions.PermissionType, ...) error
- func (service *AccountService) CreateAdd(name, userID string, perm permissions.PermissionType, ...) (*Account, error)
- func (service *AccountService) DeleteAccount(accID, userID string) error
- func (service *AccountService) GetAccount(accID, userID string) (*Account, error)
- func (service *AccountService) GetAccounts(userID string) ([]*Account, error)
- func (service *AccountService) GetTransactions(accID, userID string, from, to *time.Time) ([]*Transaction, error)
- func (service *AccountService) GivePermissionToUser(accID, ownerID, newOwnerID string, perm permissions.PermissionType) error
- func (service *AccountService) Transaction(SourceID, TargetID, userID string, amount int) error
- func (service *AccountService) UpdateAccount(accID, userID string, aDiff int) (*Account, error)
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ErrAccountDoesNotExist = errors.New("Account with this id does not exist")
var ErrIDAlreadyTaken = errors.New("AccountID already taken")
var ErrInvalidName = errors.New("Name needs to be a nonempty string")
var ErrNotOwnerOfObject = errors.New("This User is not an owner of this account")
var ErrTxSourceTargetSame = errors.New("The source and the target of the transaction is the same")
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { Value int `json:"Value"` ID string `json:"ID"` Owner AccountOwner `json:"Owner"` }
Account : represents the Accouts of Floors/Roomates/etc
type AccountController ¶
type AccountController struct {
// contains filtered or unexported fields
}
AccountController is the controller for accounts
func NewAccountController ¶
func NewAccountController(accService *AccountService) *AccountController
NewAccountController creates a new AccountController and initializes the service
func (*AccountController) DeleteAccount ¶
func (controller *AccountController) DeleteAccount(ctx *gin.Context)
DeleteAccount deletes the account identified by the ID in the query
func (*AccountController) DoTransaction ¶
func (controller *AccountController) DoTransaction(ctx *gin.Context)
DoTransaction executes a transaction between the accounts identified by their IDs in the query
func (*AccountController) GetAccount ¶
func (controller *AccountController) GetAccount(ctx *gin.Context)
GetAccount returns the account identified by the ID in the query
func (*AccountController) GetAccounts ¶
func (controller *AccountController) GetAccounts(ctx *gin.Context)
GetAccounts gets all existing accounts, that the logged in account is allowed to see
func (*AccountController) GivePermissionToUser ¶
func (controller *AccountController) GivePermissionToUser(ctx *gin.Context)
GivePermissionToUser allows an other user to see/alter this account
func (*AccountController) NewAccount ¶
func (controller *AccountController) NewAccount(ctx *gin.Context)
NewAccount creates a new account and chooses a new ID
func (*AccountController) UpdateAccount ¶
func (controller *AccountController) UpdateAccount(ctx *gin.Context)
UpdateAccount updates the the account identified by the ID int the query
type AccountOwner ¶
type AccountOwner struct {
Name string `json:"Name"`
}
type AccountRepo ¶
func NewAccountRepo ¶
func NewAccountRepo(dir string) (*AccountRepo, error)
func (*AccountRepo) BackupTo ¶
func (ar *AccountRepo) BackupTo(bkpDest string) error
func (*AccountRepo) DeleteInstance ¶
func (ar *AccountRepo) DeleteInstance(accID string) error
func (*AccountRepo) GetAllAccounts ¶
func (ar *AccountRepo) GetAllAccounts() ([]*Account, error)
func (*AccountRepo) GetInstance ¶
func (ar *AccountRepo) GetInstance(accID string) (*Account, error)
func (*AccountRepo) GetTransactions ¶
func (ar *AccountRepo) GetTransactions() ([]*Transaction, error)
func (*AccountRepo) GetTransactionsPages ¶
func (ar *AccountRepo) GetTransactionsPages(from, to *time.Time) ([]*Transaction, error)
func (*AccountRepo) SaveInstance ¶
func (ar *AccountRepo) SaveInstance(acc *Account) error
func (*AccountRepo) SaveTransaction ¶
func (ar *AccountRepo) SaveTransaction(trans *Transaction) error
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
AccountService is a service for accessing accounts
func NewAccountService ¶
func NewAccountService(repo *AccountRepo, perms *permissions.Permissions) *AccountService
NewAccountService creates a AccountService and initializes the Data
func (*AccountService) Add ¶
func (service *AccountService) Add(new *Account, userID string, perm permissions.PermissionType, perms ...permissions.PermissionType) error
Adds a new Account and sets the permissions
func (*AccountService) CreateAdd ¶
func (service *AccountService) CreateAdd(name, userID string, perm permissions.PermissionType, perms ...permissions.PermissionType) (*Account, error)
Creates a new Account and adds it to the repo
func (*AccountService) DeleteAccount ¶
func (service *AccountService) DeleteAccount(accID, userID string) error
DeleteAccount deletes the account if the user has Delete permissions
func (*AccountService) GetAccount ¶
func (service *AccountService) GetAccount(accID, userID string) (*Account, error)
GetAccount returns the account if the user has permission to read it
func (*AccountService) GetAccounts ¶
func (service *AccountService) GetAccounts(userID string) ([]*Account, error)
GetAccounts returns all accounts the user is allowed to read
func (*AccountService) GetTransactions ¶
func (service *AccountService) GetTransactions(accID, userID string, from, to *time.Time) ([]*Transaction, error)
GetTransactions gets all transactions concerning this account (or all the user has access to if accID == "")
func (*AccountService) GivePermissionToUser ¶
func (service *AccountService) GivePermissionToUser(accID, ownerID, newOwnerID string, perm permissions.PermissionType) error
GivePermissionToUser lets the newOwner access this account
func (*AccountService) Transaction ¶
func (service *AccountService) Transaction(SourceID, TargetID, userID string, amount int) error
Transaction updates the accounts if the user has Update permsissions on both accounts and saves the transaction
func (*AccountService) UpdateAccount ¶
func (service *AccountService) UpdateAccount(accID, userID string, aDiff int) (*Account, error)
UpdateAccount updates the account with the difference and returns the account with the new values