model

package
v0.0.0-...-b033284 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Models []interface{}

Models hold registered models in-memory

Functions

func Register

func Register(m interface{})

Register is used for registering models

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 AccountRepo

type AccountRepo interface {
	Create(*User) (*User, error)
	CreateAndVerify(*User) (*Verification, error)
	CreateWithMobile(*User) error
	ChangePassword(*User) error
	FindVerificationToken(string) (*Verification, error)
	DeleteVerificationToken(*Verification) error
}

AccountRepo represents account database interface (the repository)

type AuthService

type AuthService interface {
	User(*gin.Context) *AuthUser
}

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 {
	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

func (b *Base) BeforeInsert(ctx context.Context) (context.Context, error)

BeforeInsert hooks into insert operations, setting createdAt and updatedAt to current time

func (*Base) BeforeUpdate

func (b *Base) BeforeUpdate(ctx context.Context) (context.Context, error)

BeforeUpdate hooks into update operations, setting updatedAt to current time

func (*Base) Delete

func (b *Base) Delete()

Delete sets deleted_at time 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 ListQuery

type ListQuery struct {
	Query string
	ID    int
}

ListQuery holds company/location data used for list db queries

type Location

type Location struct {
	Base
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Active    bool   `json:"active"`
	Address   string `json:"address"`
	CompanyID int    `json:"company_id"`
}

Location represents company location model

type Pagination

type Pagination struct {
	Limit  int
	Offset int
}

Pagination holds pagination's data

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

type RefreshToken struct {
	Token   string `json:"token"`
	Expires string `json:"expires"`
}

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 RoleRepo

type RoleRepo interface {
	CreateRoles() error
}

RoleRepo represents the database interface

type User

type User struct {
	Base
	ID          int        `json:"id"`
	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"`
	CountryCode string     `json:"country_code,omitempty"`
	Address     string     `json:"address,omitempty"`
	LastLogin   *time.Time `json:"last_login,omitempty"`
	Verified    bool       `json:"verified"`
	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) Delete

func (u *User) Delete()

Delete updates the deleted_at field

func (*User) Update

func (u *User) Update()

Update updates the updated_at field

func (*User) UpdateLastLogin

func (u *User) UpdateLastLogin()

UpdateLastLogin updates last login field

type UserRepo

type UserRepo interface {
	View(int) (*User, error)
	FindByUsername(string) (*User, error)
	FindByEmail(string) (*User, error)
	FindByMobile(string, string) (*User, error)
	FindByToken(string) (*User, error)
	UpdateLogin(*User) error
	List(*ListQuery, *Pagination) ([]User, error)
	Update(*User) (*User, error)
	Delete(*User) error
}

UserRepo represents user database interface (the repository)

type Verification

type Verification struct {
	Base
	ID     int    `json:"id"`
	Token  string `json:"token"`
	UserID int    `json:"user_id"`
}

Verification stores randomly generated tokens that can be redeemed

Jump to

Keyboard shortcuts

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