model

package
v0.0.0-...-32f8f0d Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGeneric is used for testing purposes and for errors handled later in the callstack
	ErrGeneric = errors.New("generic error")

	// ErrBadRequest (400) is returned for bad request (validation)
	ErrBadRequest = echo.NewHTTPError(400)

	// ErrUnauthorized (401) is returned when user is not authorized
	ErrUnauthorized = echo.ErrUnauthorized
)

Functions

This section is empty.

Types

type AccessRole

type AccessRole int

AccessRole represents access role type

const (
	// SuperAdminRole has all permissions
	SuperAdminRole AccessRole = 100

	// AdminRole has admin specific permissions
	AdminRole AccessRole = 110

	// CompanyAdminRole can edit company specific things
	CompanyAdminRole AccessRole = 120

	// LocationAdminRole can edit location specific things
	LocationAdminRole AccessRole = 130

	// UserRole is a standard user
	UserRole AccessRole = 200
)

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" pg:",soft_delete"`
}

Base contains common fields for all tables

func (*Base) BeforeInsert

func (b *Base) BeforeInsert(_ orm.DB) error

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

func (*Base) BeforeUpdate

func (b *Base) BeforeUpdate(_ orm.DB) error

BeforeUpdate hooks into update operations, setting updatedAt to current time

type Category

type Category struct {
	Base
	Name       string   `json:"name,omitempty"`
	Title      string   `json:"title,omitempty"`
	Content    string   `json:"content,omitempty"`
	MenuOrder  int8     `json:"menu_order,omitempty"`
	Slug       string   `json:"slug,omitempty"`
	LanguageID int8     `json:"language_id"`
	Language   Language `json:"language"`
	Tags       string   `json:"tags"`
	LocalizeID string   `json:"localize_id"`

	Posts []Post `pg:"fk:category_id" json:"posts,omitempty"`
}

Category represents topic for english lesson model

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 Configure

type Configure struct {
	ID    int    `json:"id"`
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
}

Configure represents topic for english lesson model

type Language

type Language struct {
	ID            int    `json:"id"`
	Name          string `json:"name,omitempty"`
	Culture       string `json:"culture,omitempty"`
	UniqueSeoCode string `json:"unique_seo_code,omitempty"`
	FlagImageURL  string `json:"flag_image_url,omitempty"`
	Rtl           bool   `json:"rl,omitempty"`
	IsEnable      bool   `json:"is_enable,omitempty"`
	Posts         []Post `pg:"fk:language_id"  json:"post,omitempty"`
}

Language represents topic for english lesson 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
	Name    string `json:"name"`
	Active  bool   `json:"active"`
	Address string `json:"address"`

	CompanyID int `json:"company_id"`
}

Location represents company location model

type Logger

type Logger interface {
	// source, msg, error, params
	Log(echo.Context, string, string, error, map[string]interface{})
}

Logger represents logging interface

type Media

type Media struct {
	ID             int    `json:"id"`
	Name           string `json:"name,omitempty"`
	MimeType       string `json:"mimeType,omitempty"`
	SeoFilename    string `json:"seo_file_name,omitempty"`
	AltAttribute   string `json:"alt,omitempty"`
	TitleAttribute bool   `json:"title,omitempty"`
	URL            bool   `json:"url,omitempty"`
}

Media represents topic for english lesson model

type Pagination

type Pagination struct {
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`
}

Pagination holds paginations data

type PaginationReq

type PaginationReq struct {
	Limit int `query:"limit"`
	Page  int `query:"page" validate:"min=0"`
}

PaginationReq holds pagination http fields and tags

func (*PaginationReq) Transform

func (p *PaginationReq) Transform() *Pagination

Transform checks and converts http pagination into database pagination model

type Post

type Post struct {
	Base
	Author         int        `json:"user_id,omitempty"`
	ParentID       int        `json:"parent_id,omitempty"`
	Name           string     `json:"name,omitempty"`
	Title          string     `json:"title,omitempty"`
	Content        string     `json:"content,omitempty"`
	Status         PostStatus `sql:"default:100" json:"status,omitempty"`
	AllowComment   bool       `json:"allow_comment,omitempty"`
	Password       string     `json:"password,omitempty"`
	GUID           string     `json:"guid,omitempty"`
	MenuOrder      int8       `json:"menu_order,omitempty"`
	Type           PostType   `sql:"default:100" json:"type,omitempty"`
	MineType       string     `json:"mine_type,omitempty"`
	CommentCount   int16      `json:"comment_count,omitempty"`
	Slug           string     `json:"slug,omitempty"`
	LanguageID     int8       `json:"language_id"`
	Language       Language   `json:"language"`
	CategoryID     int        `json:"category_id"`
	Category       Category   `json:"category"`
	Tags           string     `json:"tags"`
	LocalizePostID string     `json:"localize_post_id"`

	PostMetas []PostMeta `pg:"fk:post_id" json:"post_metas,omitempty"`
}

Post represents topic for english lesson model

type PostMeta

type PostMeta struct {
	Base
	PostID int   `json:"post_id,omitempty"`
	Post   Post  `json:"post,omitempty"`
	Key    int8  `json:"key,omitempty"`
	Value  int16 `json:"value,omitempty"`
}

PostMeta represents topic for english lesson model

type PostStatus

type PostStatus int

PostStatus represents type of topic

const (

	// Darft is a new word need to learn
	Darft PostStatus = 100
	// Pending is a new word need to learn
	Pending PostStatus = 110
	// Publish is a new word need to learn
	Publish PostStatus = 120
	// Inherit is a new word need to learn
	Inherit PostStatus = 130
)

type PostType

type PostType int

PostType represents type of topic

const (

	// Page is a new word need to learn
	Page PostType = 100
	// Revision is a new word need to learn
	Revision PostType = 110
	// Blog is a new word need to learn
	Blog PostType = 120
	// Attachment is a new word need to learn
	Attachment PostType = 130
)

type RBACService

type RBACService interface {
	User(echo.Context) *AuthUser
	EnforceRole(echo.Context, AccessRole) error
	EnforceUser(echo.Context, int) error
	EnforceCompany(echo.Context, int) error
	EnforceLocation(echo.Context, int) error
	AccountCreate(echo.Context, AccessRole, int, int) error
	IsLowerRole(echo.Context, AccessRole) error
}

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          AccessRole `json:"id"`
	AccessLevel AccessRole `json:"access_level"`
	Name        string     `json:"name"`
}

Role model

type Tag

type Tag struct {
	ID   int    `json:"id"`
	Name string `json:"name,omitempty"`
	Type string `json:"name,omitempty"`
}

Tag represents topic for english lesson model

type Topic

type Topic struct {
	Base
	Name         string        `json:"name"`
	Description  string        `json:"description"`
	Type         TopicType     `json:"type"`
	TopicDetails []TopicDetail `pg:"fk:topic_id" json:"topic_details,omitempty"`
}

Topic represents topic for english lesson model

type TopicDetail

type TopicDetail struct {
	Base
	Name        string `json:"name"`
	Description string `json:"description"`
	TopicID     int    `json:"topic_id,omitempty"`
	Topic       Topic  `json:"topic,omitempty"`
}

Topic detail represents topic for english lesson model

type TopicType

type TopicType int

TopicType represents type of topic

const (
	// Vocabulary is a new word need to learn
	Vocabulary TopicType = 100

	// Reading is a new topic need to read
	Reading TopicType = 110
)

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"`

	Active bool `json:"active"`

	LastLogin          time.Time `json:"last_login,omitempty"`
	LastPasswordChange time.Time `json:"last_password_change,omitempty"`

	Token string `json:"-"`

	Role *Role `json:"role,omitempty"`

	RoleID     AccessRole `json:"-"`
	CompanyID  int        `json:"company_id"`
	LocationID int        `json:"location_id"`
}

User represents user domain model

func (*User) ChangePassword

func (u *User) ChangePassword(hash string)

ChangePassword updates user's password related fields

func (*User) UpdateLastLogin

func (u *User) UpdateLastLogin(token string)

UpdateLastLogin updates last login field

type UserDetail

type UserDetail struct {
	Base
	Name          string      `json:"name"`
	Description   string      `json:"description"`
	UserID        int         `json:"user_id,omitempty"`
	User          User        `json:"user,omitempty"`
	TopicDetailID int         `json:"topic_detail_id,omitempty"`
	TopicDetail   TopicDetail `json:"topic_detail,omitempty"`
	Point         int         `sql:", default:0" json:"point,omitempty"`
	StudyCount    int         `sql:", default:0" json:"study_count,omitempty"`
	RecentStudy   time.Time   `json:"recent_study,omitempty"`
}

UserDetail detail represents topic for english lesson model

Jump to

Keyboard shortcuts

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