Documentation ¶
Index ¶
- Constants
- Variables
- func ExecTx[T any](ctx context.Context, m TxManager, callback func(tx Tx) (T, error)) (T, error)
- func ExecTxNil(ctx context.Context, m TxManager, callback func(tx Tx) error) error
- func Field(name string, objects ...Validatable) validatableField
- func Max(c Countable, max int, object string) valitableCountable
- func MaxPrecision(a Amount) validatableMaxPrecision
- func NonZero(a Amount) validatableNonZero
- func Positive(a Amount) validatablePositive
- func ValidateFields(objects ...validatableField) error
- type Account
- type AccountContract
- type AccountRepository
- type Amount
- type AuthContext
- type Budget
- type BudgetAuthContext
- type BudgetContract
- type BudgetRepository
- type Category
- type CategoryContract
- type CategoryGroup
- type CategoryRepository
- type Countable
- type Date
- type Emptiable
- type Error
- type ID
- type Month
- type MonthCategory
- type MonthCategoryRepository
- type MonthContract
- type MonthDate
- type MonthRepository
- type Name
- type NullString
- type Password
- type PasswordHash
- type Payee
- type PayeeContract
- type PayeeRepository
- type Session
- type SessionID
- type SessionRepository
- type Transaction
- type TransactionContract
- type TransactionCreateParams
- type TransactionNotes
- type TransactionParams
- type TransactionRepository
- type TransactionUpdateParams
- type Tx
- type TxManager
- type User
- type UserContract
- type UserRepository
- type Username
- type Validatable
- type ValidatableString
Constants ¶
View Source
const ( EFORBIDDEN = "forbidden" EINTERNAL = "internal" EINVALID = "invalid" ENOTFOUND = "not_found" EUNAUTHORIZED = "unauthorized" EUNPROCESSABLE = "unprocessable" )
Variables ¶
View Source
var ( ErrorForbidden = &beansError{code: EFORBIDDEN, msg: "Forbidden"} ErrorInternal = &beansError{code: EINTERNAL, msg: "Internal error"} ErrorInvalid = &beansError{code: EINVALID, msg: "Invalid data provided"} ErrorNotFound = &beansError{code: ENOTFOUND, msg: "Not found"} ErrorUnprocessable = &beansError{code: EUNPROCESSABLE, msg: "Unprocessable request"} )
View Source
var Arithmetic amountArithmetic
Functions ¶
func Field ¶
func Field(name string, objects ...Validatable) validatableField
func MaxPrecision ¶
func MaxPrecision(a Amount) validatableMaxPrecision
func ValidateFields ¶
func ValidateFields(objects ...validatableField) error
Types ¶
type AccountContract ¶
type AccountRepository ¶
type Amount ¶
type Amount struct {
// contains filtered or unexported fields
}
func NewEmptyAmount ¶
func NewEmptyAmount() Amount
func (*Amount) Coefficient ¶
func (Amount) MarshalJSON ¶
func (*Amount) UnmarshalJSON ¶
type AuthContext ¶
type AuthContext struct {
// contains filtered or unexported fields
}
func NewAuthContext ¶
func NewAuthContext(userID ID, sessionID SessionID) *AuthContext
func (*AuthContext) SessionID ¶
func (c *AuthContext) SessionID() SessionID
func (*AuthContext) UserID ¶
func (c *AuthContext) UserID() ID
type Budget ¶
func (*Budget) UserHasAccess ¶
type BudgetAuthContext ¶
type BudgetAuthContext struct { *AuthContext // contains filtered or unexported fields }
func NewBudgetAuthContext ¶
func NewBudgetAuthContext(auth *AuthContext, budget *Budget) (*BudgetAuthContext, error)
func (*BudgetAuthContext) BudgetID ¶
func (c *BudgetAuthContext) BudgetID() ID
type BudgetContract ¶
type BudgetContract interface { // Creates a budget. Create(ctx context.Context, auth *AuthContext, name Name) (*Budget, error) // Gets a budget by the budget ID. // Ensures the user has access to the budget. Get(ctx context.Context, auth *AuthContext, id ID) (*Budget, error) // Gets all budgets accessible to the user. GetAll(ctx context.Context, auth *AuthContext) ([]*Budget, error) }
type BudgetRepository ¶
type BudgetRepository interface { // Creates a budget and assigns user to the budget. Create(ctx context.Context, tx Tx, id ID, name Name, userID ID) error // Gets budget by ID. Attaches UserIDs field. Get(ctx context.Context, id ID) (*Budget, error) GetBudgetsForUser(ctx context.Context, userID ID) ([]*Budget, error) }
type CategoryContract ¶
type CategoryContract interface { // Creates a category. CreateCategory(ctx context.Context, auth *BudgetAuthContext, groupID ID, name Name) (*Category, error) // Creates a category group. CreateGroup(ctx context.Context, auth *BudgetAuthContext, name Name) (*CategoryGroup, error) // Gets all categories and groups for a budget. GetAll(ctx context.Context, auth *BudgetAuthContext) ([]*CategoryGroup, []*Category, error) }
type CategoryRepository ¶
type CategoryRepository interface { Create(ctx context.Context, tx Tx, category *Category) error GetSingleForBudget(ctx context.Context, id ID, budgetID ID) (*Category, error) GetForBudget(ctx context.Context, budgetID ID) ([]*Category, error) CreateGroup(ctx context.Context, tx Tx, categoryGroup *CategoryGroup) error GetGroupsForBudget(ctx context.Context, budgetID ID) ([]*CategoryGroup, error) GroupExists(ctx context.Context, budgetID ID, id ID) (bool, error) }
type Date ¶
func (*Date) UnmarshalJSON ¶
type ID ¶
func BeansIDFromString ¶
func NewBeansID ¶
func NewBeansID() ID
func (ID) MarshalJSON ¶
func (*ID) UnmarshalJSON ¶
type Month ¶
type MonthCategory ¶
type MonthCategoryRepository ¶
type MonthCategoryRepository interface { Create(ctx context.Context, tx Tx, monthCategory *MonthCategory) error UpdateAmount(ctx context.Context, monthCategoryID ID, amount Amount) error // Gets categories by month. Attaches Activity, Available fields. GetForMonth(ctx context.Context, month *Month) ([]*MonthCategory, error) // Gets the month category, or creates it if it does not exist. GetOrCreate(ctx context.Context, tx Tx, monthID ID, categoryID ID) (*MonthCategory, error) // Gets the amount assigned in a month. GetAssignedInMonth(ctx context.Context, monthID ID) (Amount, error) }
type MonthContract ¶
type MonthContract interface { // Gets a month, its categories, and budgetable amount. // If the month does not exist it is created. // // Attaches the fields: CarriedOver, Income, Assigned. GetOrCreate(ctx context.Context, auth *BudgetAuthContext, date MonthDate) (*Month, []*MonthCategory, Amount, error) // Updates the given month. Update(ctx context.Context, auth *BudgetAuthContext, monthID ID, carryover Amount) error // Sets the assigned amount on a category for a month. SetCategoryAmount(ctx context.Context, auth *BudgetAuthContext, monthID ID, categoryID ID, amount Amount) error }
type MonthDate ¶
type MonthDate struct {
// contains filtered or unexported fields
}
func NewMonthDate ¶
Creates a new MonthDate and normalizes the date.
type MonthRepository ¶
type MonthRepository interface { Create(ctx context.Context, tx Tx, month *Month) error Get(ctx context.Context, id ID) (*Month, error) // Only updates the Carryover field. Update(ctx context.Context, month *Month) error GetOrCreate(ctx context.Context, tx Tx, budgetID ID, date MonthDate) (*Month, error) GetForBudget(ctx context.Context, budgetID ID) ([]*Month, error) }
type NullString ¶
type NullString struct {
// contains filtered or unexported fields
}
func NewNullString ¶
func NewNullString(string string) NullString
func NullStringFromSQL ¶
func NullStringFromSQL(s sql.NullString) NullString
func (NullString) Empty ¶
func (s NullString) Empty() bool
func (NullString) Length ¶
func (s NullString) Length() int
func (NullString) MarshalJSON ¶
func (s NullString) MarshalJSON() ([]byte, error)
func (NullString) SQLNullString ¶
func (s NullString) SQLNullString() sql.NullString
func (NullString) String ¶
func (s NullString) String() string
func (*NullString) UnmarshalJSON ¶
func (s *NullString) UnmarshalJSON(b []byte) error
type Password ¶
type Password string
func (Password) ValidatableField ¶
func (p Password) ValidatableField() validatableField
type PasswordHash ¶
type PasswordHash string
type PayeeContract ¶
type PayeeRepository ¶
type SessionRepository ¶
type Transaction ¶
type Transaction struct { ID ID AccountID ID CategoryID ID PayeeID ID Amount Amount Date Date Notes TransactionNotes // Must be explicitly loaded. Account *Account // Must be explicitly loaded. CategoryName NullString // Must be explicitly loaded. PayeeName NullString }
type TransactionContract ¶
type TransactionContract interface { // Creates a transaction. Attaches Account field. Create(ctx context.Context, auth *BudgetAuthContext, params TransactionCreateParams) (*Transaction, error) // Gets all transactions for budget. Attaches Account, CategoryName, PayeeName fields. GetAll(ctx context.Context, auth *BudgetAuthContext) ([]*Transaction, error) // Edits a transaction. Update(ctx context.Context, auth *BudgetAuthContext, params TransactionUpdateParams) error }
type TransactionCreateParams ¶
type TransactionCreateParams struct {
TransactionParams
}
type TransactionNotes ¶
type TransactionNotes struct{ NullString }
func NewTransactionNotes ¶
func NewTransactionNotes(string string) TransactionNotes
type TransactionParams ¶
type TransactionParams struct { AccountID ID CategoryID ID PayeeID ID Amount Amount Date Date Notes TransactionNotes }
func (TransactionParams) ValidateAll ¶
func (t TransactionParams) ValidateAll() error
type TransactionRepository ¶
type TransactionRepository interface { Create(ctx context.Context, transaction *Transaction) error Update(ctx context.Context, transaction *Transaction) error // Attaches Account, CategoryName, PayeeName fields to Transactions. GetForBudget(ctx context.Context, budgetID ID) ([]*Transaction, error) // Get transaction. Attaches Account field to Transaction. Get(ctx context.Context, id ID) (*Transaction, error) // Gets sum of all income transactions between the dates. GetIncomeBetween(ctx context.Context, budgetID ID, begin Date, end Date) (Amount, error) }
type TransactionUpdateParams ¶
type TransactionUpdateParams struct { ID ID TransactionParams }
func (TransactionUpdateParams) ValidateAll ¶
func (t TransactionUpdateParams) ValidateAll() error
type User ¶
type User struct { ID ID Username Username PasswordHash PasswordHash }
type UserContract ¶
type UserContract interface { // Creates a new account Register(ctx context.Context, username Username, password Password) error // Logs in and returns a session Login(ctx context.Context, username Username, password Password) (*Session, error) // Logs out and deletes the active session Logout(ctx context.Context, auth *AuthContext) error // Gets the currently authenticated user GetMe(ctx context.Context, auth *AuthContext) (*User, error) }
type UserRepository ¶
type Username ¶
type Username string
func (Username) ValidatableField ¶
func (u Username) ValidatableField() validatableField
type Validatable ¶
type Validatable interface {
Validate() error
}
func Required ¶
func Required(e Emptiable) Validatable
type ValidatableString ¶
type ValidatableString string
func (ValidatableString) Empty ¶
func (s ValidatableString) Empty() bool
func (ValidatableString) Length ¶
func (s ValidatableString) Length() int
Click to show internal directories.
Click to hide internal directories.