Documentation
¶
Index ¶
- Constants
- Variables
- type AccRepository
- type Account
- type AccountRepository
- type AccountWithRole
- type Condition
- func AccountID(id string) Condition
- func AccountIDs(ids []string) Condition
- func Disabled(v bool) Condition
- func IDs(ids []string) Condition
- func Limit(v int) Condition
- func Offset(v int) Condition
- func OrderBy(order ...Order) Condition
- func Role(v string) Condition
- func UserID(id string) Condition
- func UserIDs(ids []string) Condition
- type Interactor
- func (i *Interactor) AddMember(aid, uid, role string) error
- func (i *Interactor) Delete(id string) error
- func (i *Interactor) DeleteMemberByID(mid string) error
- func (i *Interactor) DeleteMembersByAccountID(aid string) error
- func (i *Interactor) DeleteMembersByUserID(uid string) error
- func (i *Interactor) GetAccountsListByUserID(uid string, c ...Condition) ([]*Account, error)
- func (i *Interactor) GetAccountsListWithRoleByUserID(uid string, c ...Condition) ([]*AccountWithRole, error)
- func (i *Interactor) GetByID(id string) (*Account, error)
- func (i *Interactor) GetList(c ...Condition) ([]*Account, error)
- func (i *Interactor) GetMembersList(c ...Condition) ([]*Member, error)
- func (i *Interactor) HasRole(aid, uid string, role ...string) bool
- func (i *Interactor) Insert(a *Account, uid string) error
- func (i *Interactor) Update(a *Account) error
- type MembRepository
- func (r *MembRepository) Delete(id string) error
- func (r *MembRepository) DeleteByAccountID(aid string) error
- func (r *MembRepository) DeleteByUserID(uid string) error
- func (r *MembRepository) GetByID(id string) (*Member, error)
- func (r *MembRepository) GetList(c ...Condition) ([]*Member, error)
- func (r *MembRepository) HasRole(aid, uid string, role ...string) error
- func (r *MembRepository) Insert(m *Member) error
- func (r *MembRepository) Update(m *Member) error
- type Member
- type MemberRepository
- type Order
- type QuerySection
Constants ¶
const ( RoleOwner = "owner" RoleAdmin = "admin" RoleManager = "manager" RoleUser = "user" RoleGuest = "guest" )
Predefined roles
Variables ¶
var ( ErrNotFoundAccount = errors.New("account not found") ErrNotFoundMember = errors.New("member not found") ErrNameMissed = errors.New("name is missed") ErrOwnerIDMissed = errors.New("owner id is missed") ErrNotExistedAccount = errors.New("could not update not existed account") )
Predefined accounts package errors
Functions ¶
This section is empty.
Types ¶
type AccRepository ¶
type AccRepository struct {
// contains filtered or unexported fields
}
AccRepository struct
func NewAccountRepository ¶
func NewAccountRepository(db *sql.DB, driverName, tableName string) *AccRepository
NewAccountRepository factory
func (*AccRepository) GetByID ¶
func (r *AccRepository) GetByID(id string) (*Account, error)
GetByID ...
type Account ¶
type Account struct { ID string `db:"id" json:"id"` Name string `db:"name" json:"name"` Disabled bool `db:"disabled" json:"disabled"` CreatedAt int64 `db:"created_at" json:"created_at"` UpdatedAt *int64 `db:"updated_at" json:"updated_at,omitempty,"` }
Account model structure
type AccountRepository ¶
type AccountRepository interface { GetByID(id string) (*Account, error) GetList(c ...Condition) ([]*Account, error) Insert(a *Account) error Update(a *Account) error Delete(id string) error }
AccountRepository interface
type AccountWithRole ¶
AccountWithRole is account model with role of user for each account
type Condition ¶
type Condition interface { Query() string Params() []interface{} Type() QuerySection }
Condition struct
func AccountIDs ¶
AccountIDs func add condition to select query
type Interactor ¶
type Interactor struct {
// contains filtered or unexported fields
}
Interactor struct
func NewInteractor ¶
func NewInteractor(ar AccountRepository, mr MemberRepository) *Interactor
NewInteractor factory
func (*Interactor) AddMember ¶
func (i *Interactor) AddMember(aid, uid, role string) error
AddMember member to account
func (*Interactor) Delete ¶
func (i *Interactor) Delete(id string) error
Delete account by id with all related members
func (*Interactor) DeleteMemberByID ¶
func (i *Interactor) DeleteMemberByID(mid string) error
DeleteMemberByID deletes member by member id
func (*Interactor) DeleteMembersByAccountID ¶
func (i *Interactor) DeleteMembersByAccountID(aid string) error
DeleteMembersByAccountID deletes members by account id
func (*Interactor) DeleteMembersByUserID ¶
func (i *Interactor) DeleteMembersByUserID(uid string) error
DeleteMembersByUserID deletes members by user id
func (*Interactor) GetAccountsListByUserID ¶
func (i *Interactor) GetAccountsListByUserID(uid string, c ...Condition) ([]*Account, error)
GetAccountsListByUserID returns accounts list by user id
func (*Interactor) GetAccountsListWithRoleByUserID ¶
func (i *Interactor) GetAccountsListWithRoleByUserID(uid string, c ...Condition) ([]*AccountWithRole, error)
GetAccountsListWithRoleByUserID returns accounts list with roles by user id
func (*Interactor) GetByID ¶
func (i *Interactor) GetByID(id string) (*Account, error)
GetByID fetch account by id
func (*Interactor) GetList ¶
func (i *Interactor) GetList(c ...Condition) ([]*Account, error)
GetList of accounts
func (*Interactor) GetMembersList ¶
func (i *Interactor) GetMembersList(c ...Condition) ([]*Member, error)
GetMembersList returns members list
func (*Interactor) HasRole ¶
func (i *Interactor) HasRole(aid, uid string, role ...string) bool
HasRole helper to check user role for account
type MembRepository ¶
type MembRepository struct {
// contains filtered or unexported fields
}
MembRepository struct
func NewMemberRepository ¶
func NewMemberRepository(db *sql.DB, driverName, tableName string) *MembRepository
NewMemberRepository factory
func (*MembRepository) DeleteByAccountID ¶
func (r *MembRepository) DeleteByAccountID(aid string) error
DeleteByAccountID ...
func (*MembRepository) DeleteByUserID ¶
func (r *MembRepository) DeleteByUserID(uid string) error
DeleteByUserID ...
func (*MembRepository) GetByID ¶
func (r *MembRepository) GetByID(id string) (*Member, error)
GetByID ...
func (*MembRepository) GetList ¶
func (r *MembRepository) GetList(c ...Condition) ([]*Member, error)
GetList ...
type Member ¶
type Member struct { ID string `json:"id" db:"id"` AccountID string `json:"account_id" db:"account_id"` UserID string `json:"user_id" db:"user_id"` Role string `json:"role" db:"role"` CreatedAt int64 `json:"created_at" db:"created_at"` }
Member model structure
type MemberRepository ¶
type MemberRepository interface { GetByID(id string) (*Member, error) HasRole(aid, uid string, role ...string) error GetList(c ...Condition) ([]*Member, error) Insert(m *Member) error Update(m *Member) error Delete(id string) error DeleteByAccountID(aid string) error DeleteByUserID(uid string) error }
MemberRepository interface
type Order ¶
type Order int
Order type
type QuerySection ¶
type QuerySection int
QuerySection type
const ( QsWhere QuerySection = iota + 1 QsOrderBy QsLimit QsOffset )
Predefined query section type