Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessRole ¶
type AccessRole int8
AccessRole represents access role type
const ( // SuperAdminRole has all permissions SuperAdminRole AccessRole = iota + 1 // AdminRole has admin specific permissions AdminRole // CompanyAdminRole can edit company specific things CompanyAdminRole // LocationAdminRole can edit location specific things LocationAdminRole // UserRole is a standard user UserRole )
type AccountDB ¶
type AccountDB interface { Create(context.Context, *User) error ChangePassword(context.Context, *User) error }
AccountDB represents account related database interface (repository)
type AuthService ¶
AuthService represents authentication service interface
type AuthToken ¶
type AuthToken struct { Token string `json:"token"` Expires string `json:"expires"` RefreshToken string `json:"refresh_token"` }
AuthToken holds authentication token details with refresh token
type AuthUser ¶
type AuthUser struct { ID int CompanyID int LocationID int Username string Email string Role AccessRole }
AuthUser represents data stored in JWT token for user
type Base ¶
type Base struct { ID int `json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at,omitempty"` }
Base contains common fields for all tables
func (*Base) BeforeInsert ¶
BeforeInsert hooks into insert operations, setting createdAt and updatedAt to current time
func (*Base) BeforeUpdate ¶
BeforeUpdate hooks into update operations, setting updatedAt to current time
type Company ¶
type Company struct { Base Name string `json:"name"` Active bool `json:"active"` Locations []Location `json:"locations,omitempty"` Owner User `json:"owner"` }
Company represents company model
type Location ¶
type Location struct { Base Name string `json:"name"` Active bool `json:"active"` Address string `json:"address"` CompanyID int `json:"company_id"` }
Location represents company location model
type RBACService ¶
type RBACService interface { EnforceRole(*gin.Context, AccessRole) bool EnforceUser(*gin.Context, int) bool EnforceCompany(*gin.Context, int) bool EnforceLocation(*gin.Context, int) bool AccountCreate(*gin.Context, int, int, int) bool IsLowerRole(*gin.Context, AccessRole) bool }
RBACService represents role-based access control service interface
type RefreshToken ¶
RefreshToken holds authentication token details
type Role ¶
type Role struct { ID int `json:"id"` AccessLevel AccessRole `json:"access_level"` Name string `json:"name"` }
Role model
type User ¶
type User struct { Base FirstName string `json:"first_name"` LastName string `json:"last_name"` Username string `json:"username"` Password string `json:"-"` Email string `json:"email"` Mobile string `json:"mobile,omitempty"` Phone string `json:"phone,omitempty"` Address string `json:"address,omitempty"` LastLogin *time.Time `json:"last_login,omitempty"` Active bool `json:"active"` Token string `json:"-"` Role *Role `json:"role,omitempty"` RoleID int `json:"-"` CompanyID int `json:"company_id"` LocationID int `json:"location_id"` }
User represents user domain model
func (*User) UpdateLastLogin ¶
func (u *User) UpdateLastLogin()
UpdateLastLogin updates last login field
type UserDB ¶
type UserDB interface { View(context.Context, int) (*User, error) FindByUsername(context.Context, string) (*User, error) FindByToken(context.Context, string) (*User, error) UpdateLogin(context.Context, *User) error List(context.Context, *ListQuery, *Pagination) ([]User, error) Delete(context.Context, *User) error Update(context.Context, *User) (*User, error) }
UserDB represents user database interface (repository)