biz

package
v0.0.0-...-d82ff1c Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SwitchActivityType

func SwitchActivityType(activityType ActivityType) string

Types

type ActivityType

type ActivityType int

生成的枚举类型 ActivityType

const (
	ActivityType_ACTIVITY_TYPE_UNSPECIFIED ActivityType = 0
	ActivityType_LOGIN                     ActivityType = 1
	ActivityType_API_CALL                  ActivityType = 2
	ActivityType_UPDATE                    ActivityType = 3
	ActivityType_CREATE                    ActivityType = 4
)

type ApiKey

type ApiKey struct {
	ID          int       `gorm:"primaryKey;autoIncrement" json:"id"`
	UserID      int       `gorm:"index" json:"user_id"`
	ApiKey      string    `gorm:"size:255;unique" json:"api_key"`
	CreatedAt   time.Time `gorm:"autoCreateTime" json:"created_at"`
	ExpiresAt   time.Time `json:"expires_at"`
	Permissions string    `json:"permissions"` // JSON 格式的权限数据
	Status      string    `gorm:"size:20" json:"status"`
}

ApiKey 表示 API 密钥表

func (*ApiKey) Toproto

func (k *ApiKey) Toproto() *pb.ApiKey

type User

type User struct {
	ID               int        `gorm:"primaryKey;autoIncrement" json:"id"`
	Username         string     `gorm:"size:255;unique" json:"username"`
	Email            string     `gorm:"size:255;unique" json:"email"`
	PasswordHash     string     `gorm:"size:255" json:"password_hash"`
	CreatedAt        time.Time  `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt        time.Time  `gorm:"autoUpdateTime" json:"updated_at"`
	Status           string     `gorm:"size:20" json:"status"`
	LastLoginAt      *time.Time `json:"last_login_at"`
	ApiKey           string     `gorm:"size:255" json:"api_key"`
	TwoFactorEnabled bool       `json:"two_factor_enabled"`
	Role             string     `gorm:"size:20" json:"role"`
}

User 表示用户表

func (*User) Toproto

func (u *User) Toproto() *pb.User

type UserActivity

type UserActivity struct {
	ID           int       `gorm:"primaryKey;autoIncrement" json:"id"`
	UserID       int       `gorm:"index" json:"user_id"`
	ActivityType string    `gorm:"size:50" json:"activity_type"`
	Details      string    `json:"details"`
	CreatedAt    time.Time `gorm:"autoCreateTime" json:"created_at"`
}

UserActivity 表示用户活动日志

func (*UserActivity) TableName

func (a *UserActivity) TableName() string

func (*UserActivity) Toproto

func (a *UserActivity) Toproto() *pb.UserActivity

type UserManagementCase

type UserManagementCase struct {
	// contains filtered or unexported fields
}

func NewUserManagementCase

func NewUserManagementCase(repo UserManagementRepo, logger log.Logger) *UserManagementCase

func (*UserManagementCase) CreateApiKey

func (uc *UserManagementCase) CreateApiKey(ctx context.Context, id int64, permissions string) (*ApiKey, error)

func (*UserManagementCase) CreateUser

func (uc *UserManagementCase) CreateUser(ctx context.Context, user *User) error

func (*UserManagementCase) DeleteUser

func (uc *UserManagementCase) DeleteUser(ctx context.Context, id int64) error

func (*UserManagementCase) GetApiKey

func (uc *UserManagementCase) GetApiKey(ctx context.Context, id int64) ([]*ApiKey, error)

func (*UserManagementCase) GetUser

func (uc *UserManagementCase) GetUser(ctx context.Context, id int64) (*User, error)

func (*UserManagementCase) RevokeApiKey

func (uc *UserManagementCase) RevokeApiKey(ctx context.Context, id int64) error

func (*UserManagementCase) UpdateUser

func (uc *UserManagementCase) UpdateUser(ctx context.Context, user *User) error

type UserManagementRepo

type UserManagementRepo interface {
	CreateUser(ctx context.Context, user *User) error
	GetUser(ctx context.Context, id int64) (*User, error)
	UpdateUser(ctx context.Context, user *User) error
	DeleteUser(ctx context.Context, id int64) error
	CreateApiKey(ctx context.Context, id int64, permissions string) (*ApiKey, error)
	GetApiKey(ctx context.Context, id int64) ([]*ApiKey, error)
	RevokeApiKey(ctx context.Context, id int64) error
}

Jump to

Keyboard shortcuts

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