accounts

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAccountDoesNotExist = errors.New("Account with this id does not exist")
View Source
var ErrIDAlreadyTaken = errors.New("AccountID already taken")
View Source
var ErrInvalidName = errors.New("Name needs to be a nonempty string")
View Source
var ErrNotOwnerOfObject = errors.New("This User is not an owner of this account")
View Source
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

type AccountRepo struct {
	Lock sync.RWMutex
	// contains filtered or unexported fields
}

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

type Transaction

type Transaction struct {
	SourceID  string
	TargetID  string
	Amount    int
	Timestamp time.Time
	ID        string
}

Transaction : represents a transaction made between two Accounts (or from/to the outer world)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL