model

package
v0.0.0-...-7eeeacd Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFile

func CreateFile(ctx context.Context, value *File) error

func CreatePermission

func CreatePermission(ctx context.Context, value *Permission) error

func CreateRole

func CreateRole(ctx context.Context, value *Role) error

func CreateUser

func CreateUser(ctx context.Context, value *User) error

func DeleteFile

func DeleteFile(ctx context.Context, value *File) error

func DeletePermission

func DeletePermission(ctx context.Context, value *Permission) error

func DeleteRole

func DeleteRole(ctx context.Context, value *Role) error

func EnsureRolePermissions

func EnsureRolePermissions(tx *dbx.DB, role Role, permissions []Permission) error

func EnsureUserRole

func EnsureUserRole(tx *dbx.DB, userId, roleId string) error

func HasPermission

func HasPermission(ctx context.Context, userId, permission string) (bool, error)

func SetRolePermissions

func SetRolePermissions(ctx context.Context, id string, permissionIds []string) (bool, error)

func SetUserRoles

func SetUserRoles(ctx context.Context, id string, roleIds []string) (bool, error)

func UpdatePermission

func UpdatePermission(ctx context.Context, id string, updates map[string]any) error

func UpdateRole

func UpdateRole(ctx context.Context, id string, updates map[string]any) error

func UpdateUser

func UpdateUser(ctx context.Context, id string, updates map[string]any) error

Types

type File

type File struct {
	dbx.Metadata
	OwnerId      string `gorm:"type:varchar(32);not null;index"`
	OriginalName string `gorm:"type:varchar(255);not null"`
	StoredName   string `gorm:"type:varchar(255);not null;uniqueIndex"`
	MIMEType     string `gorm:"type:varchar(255);not null"`
	Size         int64  `gorm:"not null"`
}

func DeleteUser

func DeleteUser(ctx context.Context, id string) (File, error)

func GetFile

func GetFile(ctx context.Context, id string) (File, error)

func ReplaceAvatar

func ReplaceAvatar(ctx context.Context, user *User, value *File, actor string) (File, error)

type Permission

type Permission struct {
	dbx.Metadata
	Code string `gorm:"type:varchar(128);not null;uniqueIndex"`
	Name string `gorm:"type:varchar(128);not null"`
}

func EnsurePermission

func EnsurePermission(tx *dbx.DB, item Permission) (Permission, error)

EnsurePermission 按编码复用或创建权限,已存在时保留原有记录。

func FindPermissions

func FindPermissions(ctx context.Context, ids []string) ([]Permission, error)

func GetPermission

func GetPermission(ctx context.Context, id string) (Permission, error)

func ListPermissions

func ListPermissions(ctx context.Context, offset, limit int) ([]Permission, int64, error)

type Role

type Role struct {
	dbx.Metadata
	Code        string       `gorm:"type:varchar(64);not null;uniqueIndex"`
	Name        string       `gorm:"type:varchar(128);not null"`
	Permissions []Permission `gorm:"many2many:role_permissions"`
}

func EnsureRole

func EnsureRole(tx *dbx.DB, item Role) (Role, error)

EnsureRole 按编码复用或创建角色,已存在时保留原有记录。

func FindRoles

func FindRoles(ctx context.Context, ids []string) ([]Role, error)

func GetRole

func GetRole(ctx context.Context, id string) (Role, error)

func ListRoles

func ListRoles(ctx context.Context, offset, limit int) ([]Role, int64, error)

type RolePermission

type RolePermission struct {
	RoleId       string `gorm:"type:varchar(32);primaryKey"`
	PermissionId string `gorm:"type:varchar(32);primaryKey;index:idx_role_permissions_permission_id"`
}

type User

type User struct {
	dbx.Metadata
	Username     string  `gorm:"type:varchar(64);not null;uniqueIndex"`
	Email        string  `gorm:"type:varchar(255);not null;uniqueIndex"`
	PasswordHash string  `gorm:"type:varchar(255);not null"`
	Enabled      bool    `gorm:"not null"`
	AvatarFileId *string `gorm:"type:varchar(32);index"`
	Roles        []Role  `gorm:"many2many:user_roles"`
}

func EnsureUser

func EnsureUser(tx *dbx.DB, username string, create func() (User, error)) (User, error)

EnsureUser 按用户名复用用户,仅在记录不存在时调用 create 构造新用户。

func GetUser

func GetUser(ctx context.Context, id string) (User, error)

func GetUserByUsername

func GetUserByUsername(ctx context.Context, username string) (User, error)

func ListUsers

func ListUsers(ctx context.Context, offset, limit int) ([]User, int64, error)

type UserRole

type UserRole struct {
	UserId string `gorm:"type:varchar(32);primaryKey"`
	RoleId string `gorm:"type:varchar(32);primaryKey;index:idx_user_roles_role_id"`
}

Jump to

Keyboard shortcuts

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