model

package
v0.0.0-...-b4bec84 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPageNum default page num.
	DefaultPageNum = 15
)

Functions

func FormatPage

func FormatPage(db *gorm.DB, page *Page) *gorm.DB

func GenRoleID

func GenRoleID() (string, error)

func GenUserID

func GenUserID() (string, error)

Types

type Page

type Page struct {
	PageNum      int    `json:"page_num"`
	PageSize     int    `json:"page_size"`
	OrderBy      string `json:"order_by"`
	IsDescending bool   `json:"is_descending"` // false:ascending;true:descending
}

type Role

type Role struct {
	ID          string `json:"id" gorm:"primaryKey"`
	Name        string `json:"name" gorm:"type:varchar(128);not null;uniqueIndex:role_tenant"`
	TenantID    string `json:"tenant_id" gorm:"type:varchar(32);default:'';uniqueIndex:role_tenant"`
	Description string `json:"description" gorm:"type:varchar(256);default:''"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (*Role) BeforeCreate

func (dao *Role) BeforeCreate(_ *gorm.DB) error

func (*Role) Create

func (dao *Role) Create(db *gorm.DB) error

func (*Role) Delete

func (dao *Role) Delete(db *gorm.DB, where map[string]any) (affected int64, err error)

func (*Role) IsExisted

func (dao *Role) IsExisted(db *gorm.DB, where map[string]any) (bool, error)

func (*Role) List

func (dao *Role) List(db *gorm.DB, where map[string]any, page *Page, keywords string) (total int64, roles []*Role, err error)

func (Role) TableName

func (Role) TableName() string

func (*Role) Update

func (dao *Role) Update(db *gorm.DB, where map[string]any, updates map[string]any) (affected int64, err error)

type Tenant

type Tenant struct {
	ID        string `json:"id" gorm:"primaryKey;type:varchar(32);comment:租户ID"`
	Title     string `json:"title" gorm:"type:varchar(128);comment:租户标题; not null;index"`
	Remark    string `json:"remark" gorm:"type:varchar(255);comment:备注"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*Tenant) Create

func (o *Tenant) Create(db *gorm.DB) (err error)

func (*Tenant) Delete

func (o *Tenant) Delete(db *gorm.DB) error

func (*Tenant) Existed

func (o *Tenant) Existed(db *gorm.DB) (existed bool)

func (*Tenant) List

func (o *Tenant) List(db *gorm.DB, where map[string]any, page *Page, keywords string) (total int64, tenants []*Tenant, err error)

func (Tenant) TableName

func (Tenant) TableName() string

func (*Tenant) Update

func (o *Tenant) Update(db *gorm.DB, where map[string]any, updates map[string]any) (affected int64, err error)

type User

type User struct {
	ID         string    `json:"id" gorm:"primaryKey"`
	ExternalID string    `json:"external_id" gorm:"type:varchar(128);default:'';uniqueIndex:user_tenant"`
	TenantID   string    `json:"tenant_id" gorm:"type:varchar(32);column:tenant_id;not null;uniqueIndex:user_tenant"`
	UserName   string    `json:"username" gorm:"type:varchar(64);column:username;not null;uniqueIndex:user_tenant"` // nolint
	Password   string    `json:"-" gorm:"type:varchar(128);column:password;not null"`
	NickName   string    `json:"nick_name" gorm:"type:varchar(128);comment:昵称"`
	Avatar     string    `json:"avatar" gorm:"type:varchar(255);comment:头像"`
	Email      string    `json:"email" gorm:"type:varchar(128);column:email;comment:邮箱"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

func AuthenticateUser

func AuthenticateUser(db *gorm.DB, tenantID, username, password string) (*User, error)

func MappingFromExternal

func MappingFromExternal(db *gorm.DB, externalID, name, email, tenantID string) (*User, error)

func (*User) BeforeCreate

func (u *User) BeforeCreate(_ *gorm.DB) error

func (*User) CountInTenant

func (u *User) CountInTenant(db *gorm.DB, tenantID string) (int64, error)

func (*User) Create

func (u *User) Create(db *gorm.DB) error

func (*User) Delete

func (u *User) Delete(db *gorm.DB) error

func (*User) DeleteAllInTenant

func (u *User) DeleteAllInTenant(db *gorm.DB, tenantID string) error

func (*User) Encrypt

func (u *User) Encrypt() (err error)

func (*User) Existed

func (u *User) Existed(db *gorm.DB) (existed bool, err error)

func (*User) FirstOrAssignCreate

func (u *User) FirstOrAssignCreate(db *gorm.DB, where User, assign User) error

func (*User) QueryByCondition

func (u *User) QueryByCondition(db *gorm.DB, condition map[string]any, page *Page, keyWords string) (total int64, users []*User, err error)

QueryByCondition query by condition (todo fix page).

func (User) TableName

func (User) TableName() string

func (*User) Update

func (u *User) Update(db *gorm.DB, tenantID, userID string, updates map[string]any) error

Jump to

Keyboard shortcuts

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