biz

package
v0.0.0-...-476383d Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: MIT Imports: 21 Imported by: 0

README

Biz

Documentation

Index

Constants

This section is empty.

Variables

ProviderSet is biz providers.

Functions

This section is empty.

Types

type AuthRepo

type AuthRepo interface {
	AccountExist(ctx context.Context, userAccount string) (bool, error)
	UserRegister(ctx context.Context, userAccount, passwordHash string) (int32, error)
	UserLogin(ctx context.Context, userAccount, passwordHash string) (*User, error)
	UserLogout(ctx context.Context) error
	SetLoginSession(ctx context.Context, userInfo *User) error
}

type AuthRepoUseCase

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

func NewAuthRepoUseCase

func NewAuthRepoUseCase(repo AuthRepo, re Recovery, tm Transaction, logger log.Logger) *AuthRepoUseCase

func (*AuthRepoUseCase) UserLogin

func (r *AuthRepoUseCase) UserLogin(ctx context.Context, userAccount, userPassword string) (*User, error)

UserLogin 登录逻辑

1. 校验用户账户和密码是否合法

  1. 非空
  2. 账户长度不小于 4 位
  3. 密码就不小于 8 位
  4. 账户不包含特殊字符
  1. 校验密码是否输入正确,要和数据库中的密文密码去对比
  2. 用户信息脱敏,隐藏敏感信息,防止数据库中的字段泄露
  3. 我们要记录用户的登录态(session),将其存到服务器上(redis) cookie
  4. 返回脱敏后的用户信息

func (*AuthRepoUseCase) UserLogout

func (r *AuthRepoUseCase) UserLogout(ctx context.Context) error

UserLogout 注销逻辑 1. 移除redis中的session即可

func (*AuthRepoUseCase) UserRegister

func (r *AuthRepoUseCase) UserRegister(ctx context.Context, userAccount, userPassword, checkPassword string) (int32, error)

UserRegister 注册逻辑设计

1. 用户在前端输入账户和密码、以及校验码(todo) 2. 校验用户的账户、密码、校验密码,是否符合要求 1. 非空 2. 账户长度 **不小于** 4 位 3. 密码就 **不小于** 8 位吧 4. 账户不能重复 5. 账户不包含特殊字符 6. 密码和校验密码相同 3. 对密码进行加密(密码千万不要直接以明文存储到数据库中) 4. 向数据库插入用户数据

type CreateTeam

type CreateTeam struct {
	Team
	Name       string `validate:"required,min=1,max=20" comment:"队伍名"`
	MaxNum     int32  `validate:"required,gt=1,lte=20" comment:"最大人数"`
	Status     int32  `validate:"required,oneof=0 1 2" comment:"状态"`
	ExpireTime string `validate:"required,datetime" comment:"过期时间"`
	UserId     int32  `validate:"required,gte=0" comment:"创建者用户id"`
}

CreateTeam 校验信息 1. 队伍人数 > 1 且 <= 20 2. 队伍标题 <= 20 3. 描述 <= 512 4. status 是否公开(int)不传默认为 0(公开) 5. 如果 status 是加密状态,一定要有密码,且密码 <= 32 (有点复杂,AddTeam里实现) 6. 超时时间 > 当前时间 (有点复杂,AddTeam里实现)

type DeleteTeam

type DeleteTeam struct {
	Id int32 `validate:"required,gte=0" comment:"id"`
}

type DeleteUser

type DeleteUser struct {
	Id int32 `validate:"required,gt=0" comment:"用户Id"`
}

type GetTeam

type GetTeam struct {
	Id int32 `validate:"required,gte=0" comment:"id"`
}

type JoinTeam

type JoinTeam struct {
	Team
	Id int32 `validate:"required,gte=0" comment:"id"`
}

type PartnerRepo

type PartnerRepo interface {
	AddTeam(ctx context.Context, team *CreateTeam) (int32, error)
	AddUserTeam(ctx context.Context, userTeam *UserTeam) (int32, error)
	DeleteTeam(ctx context.Context, teamId int32) error
	DeleteUserTeam(ctx context.Context, teamId, userId int32) error
	UpdateTeam(ctx context.Context, team *UpdateTeam) error
	GetTeam(ctx context.Context, teamId int32) (*Team, error)
	GetTeamCountByUserId(ctx context.Context, userId int32) (int64, error)
	GetTeamList(ctx context.Context, query *TeamQuery, page, pageSizer int32) ([]*TeamList, error)
	GetUserTeamListByUserId(ctx context.Context, userId int32) ([]*UserTeam, error)
	GetUserTeamCountByTeamId(ctx context.Context, teamId int32) (int64, error)
	GetTeamNextManager(ctx context.Context, teamId, userId int32) (int32, error)
}

type PartnerRepoUseCase

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

func NewPartnerRepoUseCase

func NewPartnerRepoUseCase(repo PartnerRepo, re Recovery, tm Transaction, logger log.Logger) *PartnerRepoUseCase

func (*PartnerRepoUseCase) AddTeam

func (r *PartnerRepoUseCase) AddTeam(ctx context.Context, user *User, team *CreateTeam) error

AddTeam 1. 校验用户最多创建 5 个队伍 2. add

func (*PartnerRepoUseCase) DeleteTeam

func (r *PartnerRepoUseCase) DeleteTeam(ctx context.Context, team *DeleteTeam) error

func (*PartnerRepoUseCase) GetTeam

func (r *PartnerRepoUseCase) GetTeam(ctx context.Context, team *GetTeam) (*Team, error)

func (*PartnerRepoUseCase) GetTeamList

func (r *PartnerRepoUseCase) GetTeamList(ctx context.Context, team *TeamQuery, page, pageSize int32) ([]*TeamList, error)

func (*PartnerRepoUseCase) JoinTeam

func (r *PartnerRepoUseCase) JoinTeam(ctx context.Context, team *JoinTeam, user *User) error

JoinTeam 1. 用户最多加入 5 个队伍 2. 队伍必须存在,只能加入未满、未过期的队伍 3. 不能加入自己的队伍,不能重复加入已加入的队伍(幂等性) 4. 禁止加入私有的队伍 5. 如果加入的队伍是加密的,必须密码匹配才可以 6. 新增队伍 - 用户关联信息

func (*PartnerRepoUseCase) QuitTeam

func (r *PartnerRepoUseCase) QuitTeam(ctx context.Context, team *QuitTeam, user *User) error

func (*PartnerRepoUseCase) UpdateTeam

func (r *PartnerRepoUseCase) UpdateTeam(ctx context.Context, team *UpdateTeam, userId int32, isAdmin bool) error

type QuitTeam

type QuitTeam struct {
	Team
	Id int32 `validate:"required,gte=0" comment:"id"`
}

type Recovery

type Recovery interface {
	GroupRecover(context.Context, func(ctx context.Context) error) func() error
}

type SearchUser

type SearchUser struct {
	UserName string
}

type Team

type Team struct {
	Id          int32  `validate:"omitempty,gte=0" comment:"id"`
	Name        string `validate:"omitempty,min=1,max=20" comment:"队伍名"`
	Description string `validate:"omitempty,max=512" comment:"描述"`
	MaxNum      int32  `validate:"omitempty,gt=1,lte=20" comment:"最大人数"`
	ExpireTime  string `validate:"omitempty,datetime" comment:"过期时间"`
	UserId      int32  `validate:"omitempty,gte=0" comment:"创建者用户id"`
	Status      int32  `validate:"omitempty,oneof=0 1 2" comment:"状态"`
	Password    string `validate:"omitempty,max=32" comment:"密码"`
}

type TeamList

type TeamList struct {
	Team
	UserInfo *User
}

type TeamQuery

type TeamQuery struct {
	Team
	// contains filtered or unexported fields
}

type Transaction

type Transaction interface {
	ExecTx(context.Context, func(ctx context.Context) error) error
}

type UpdateTeam

type UpdateTeam struct {
	Team
	Id int32 `validate:"required,gte=0" comment:"id"`
}

type UpdateUser

type UpdateUser struct {
	Id        int32
	UserName  string `validate:"omitempty" comment:"用户昵称"`
	AvatarUrl string `validate:"omitempty" comment:"用户头像"`
	Gender    int32  `validate:"omitempty" comment:"性别"`
	Phone     string `validate:"omitempty" comment:"手机号"`
	Email     string `validate:"omitempty" comment:"邮箱"`
}

type User

type User struct {
	Id           int32
	UserName     string
	UserAccount  string
	AvatarUrl    string
	Gender       int32
	UserPassword string
	Phone        string
	Email        string
	UserStatus   int32
	Role         int32
	CreateTime   time.Time
	Tags         string
	Profile      string
}

func (*User) DoValidate

func (i *User) DoValidate(trans ut.Translator, validate *validator.Validate) error

func (User) MarshalEasyJSON

func (v User) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (User) MarshalJSON

func (v User) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*User) UnmarshalEasyJSON

func (v *User) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*User) UnmarshalJSON

func (v *User) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type UserLogin

type UserLogin struct {
	UserAccount  string `validate:"required,min=4" comment:"用户名"`
	UserPassword string `validate:"required,min=4,max=8" comment:"用户密码"`
}

UserLogin DO对象,带简单校验

type UserRegister

type UserRegister struct {
	UserAccount   string `validate:"required,min=4" comment:"用户名"`
	UserPassword  string `validate:"required,min=4,max=8" comment:"用户密码"`
	CheckPassword string `validate:"required,min=4,max=8" comment:"重复密码"`
}

UserRegister DO对象,带简单校验

type UserRepo

type UserRepo interface {
	SearchUsers(ctx context.Context, userName string) ([]*User, error)
	SearchUsersByTags(ctx context.Context, tagList []string) ([]*User, error)
	UpdateUser(ctx context.Context, update *UpdateUser) error
	DeleteUser(ctx context.Context, userName int32) error
	GetUsersList(ctx context.Context, pageNum, pageSize int32) ([]*User, error)
	GetUserRole(ctx context.Context) (int32, int32, error)
	GetUserSession(ctx context.Context) (*User, error)
	GetCurrentUser(ctx context.Context, userId int32) (*User, error)
}

type UserTeam

type UserTeam struct {
	Id     int32
	UserId int32
	TeamId int32
}

type UserUseCase

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

func NewUserUseCase

func NewUserUseCase(repo UserRepo, re Recovery, tm Transaction, logger log.Logger, conf *conf.UserConstant) *UserUseCase

func (*UserUseCase) DeleteUser

func (r *UserUseCase) DeleteUser(ctx context.Context, userId int32) error

DeleteUser 用户删除逻辑 1. 判断是否有管理员权限 2. 根据用户id进行逻辑删除

func (*UserUseCase) GetCurrentUser

func (r *UserUseCase) GetCurrentUser(ctx context.Context) (*User, bool, error)

GetCurrentUser 当前登录用户获取逻辑 1. 判断session是否存在 2. 如果存在,从数据库中获取最新用户信息返回

func (*UserUseCase) IsAdmin

func (r *UserUseCase) IsAdmin(ctx context.Context) error

func (*UserUseCase) IsUserLogin

func (r *UserUseCase) IsUserLogin(ctx context.Context) (*User, error)

IsUserLogin 用户登录判断

func (*UserUseCase) SearchUsers

func (r *UserUseCase) SearchUsers(ctx context.Context, userName string) ([]*User, error)

SearchUsers 用户搜索逻辑 1. 判断是否有管理员权限 2. 根据用户名进行模糊查询

func (*UserUseCase) SearchUsersByTags

func (r *UserUseCase) SearchUsersByTags(ctx context.Context, tagList []string) ([]*User, error)

SearchUsersByTags 根据标签搜索用户

func (*UserUseCase) SearchUsersByTagsInCache

func (r *UserUseCase) SearchUsersByTagsInCache(ctx context.Context, tagList []string) ([]*User, error)

SearchUsersByTagsInCache 根据标签搜索用户(在内存中判断)

func (*UserUseCase) UpdateUser

func (r *UserUseCase) UpdateUser(ctx context.Context, updateUser *UpdateUser) error

UpdateUser 更新用户信息

func (*UserUseCase) UsersRecommend

func (r *UserUseCase) UsersRecommend(ctx context.Context, pageNum, pageSize int32) ([]*User, error)

UsersRecommend 用户推荐

type ValidateUseCase

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

func NewValidateUseCase

func NewValidateUseCase() *ValidateUseCase

func (*ValidateUseCase) ParamsValidate

func (u *ValidateUseCase) ParamsValidate(object interface{}) error

Jump to

Keyboard shortcuts

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