Documentation
¶
Index ¶
- Constants
- Variables
- func InitTables(db *gorm.DB) error
- type ActivityDAO
- type Api
- type ApiDAO
- type Check
- type CheckDAO
- type Comment
- type CommentDAO
- type CommentSearch
- type Interactive
- type InteractiveDAO
- type Job
- type JobDAO
- type LotteryDraw
- type LotteryDrawDAO
- type Menu
- type MenuDAO
- type Participant
- type PermissionDAO
- type Plate
- type PlateDAO
- type Post
- type PostDAO
- type PostSearch
- type Profile
- type PubPost
- type RankingParameter
- type RankingParameterDAO
- type ReadEvent
- type RecentActivity
- type Relation
- type RelationCount
- type RelationDAO
- type Role
- type RoleDAO
- type SearchDAO
- type SecondKillEvent
- type SmsDAO
- type User
- type UserCollectionBiz
- type UserDAO
- type UserLikeBiz
- type UserSearch
- type VCodeSmsLog
Constants ¶
View Source
const ( StatusLiked = 1 StatusUnliked = 0 StatusCollection = 1 StatusUnCollection = 0 )
View Source
const ( FollowStatus uint8 = iota // 关注 ShieldStatus // 屏蔽 BlockStatus // 拉黑 )
View Source
const ( PostIndex = "post_index" UserIndex = "user_index" LogsIndex = "logs_index" CommentIndex = "comment_index" )
Variables ¶
View Source
var ( ErrRecordNotFound = gorm.ErrRecordNotFound ErrLikeNotFound = errors.New("用户未点赞,无法取消") ErrLikeAlready = errors.New("点赞已取消,请勿重复操作") ErrCollectNotFound = errors.New("用户未收藏,无法取消") ErrCollectAlready = errors.New("收藏已取消,请勿重复操作") )
View Source
var ( ErrMenuNotFound = errors.New("菜单不存在") ErrInvalidMenu = errors.New("无效的菜单参数") )
View Source
var ( ErrPostNotFound = errors.New("post not found") ErrInvalidParams = errors.New("invalid parameters") ErrPlateNotFound = errors.New("plate not found") )
View Source
var ( // ErrCodeDuplicateUsernameNumber 表示用户名重复的错误码 ErrCodeDuplicateUsernameNumber uint16 = 1062 // ErrDuplicateUsername 表示用户名重复错误 ErrDuplicateUsername = errors.New("用户名已存在") // ErrUserNotFound 表示用户未找到错误 ErrUserNotFound = errors.New("用户不存在") )
View Source
var ErrDataNotFound = gorm.ErrRecordNotFound
ErrDataNotFound 定义一个全局的记录未找到错误
Functions ¶
Types ¶
type ActivityDAO ¶
type ActivityDAO interface {
GetRecentActivity(ctx context.Context) ([]RecentActivity, error)
SetRecentActivity(ctx context.Context, mr RecentActivity) error
}
func NewActivityDAO ¶
func NewActivityDAO(db *gorm.DB, l *zap.Logger) ActivityDAO
type Api ¶
type Api struct {
ID int `json:"id" gorm:"primaryKey;column:id;comment:主键ID"`
Name string `json:"name" gorm:"column:name;type:varchar(50);not null;comment:API名称"`
Path string `json:"path" gorm:"column:path;type:varchar(255);not null;comment:API路径"`
Method int `json:"method" gorm:"column:method;type:tinyint(1);not null;comment:HTTP请求方法(1:GET,2:POST,3:PUT,4:DELETE)"`
Description string `json:"description" gorm:"column:description;type:varchar(500);comment:API描述"`
Version string `json:"version" gorm:"column:version;type:varchar(20);default:v1;comment:API版本"`
Category int `json:"category" gorm:"column:category;type:tinyint(1);not null;comment:API分类(1:系统,2:业务)"`
IsPublic int `json:"is_public" gorm:"column:is_public;type:tinyint(1);default:0;comment:是否公开(0:否,1:是)"`
CreateTime int64 `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:创建时间"`
UpdateTime int64 `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
IsDeleted int `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否删除(0:否,1:是)"`
}
type ApiDAO ¶
type Check ¶
type Check struct {
ID int64 `gorm:"primaryKey;autoIncrement"` // 审核ID
PostID uint `gorm:"not null"` // 帖子ID
Content string `gorm:"type:text;not null"` // 审核内容
Title string `gorm:"size:255;not null"` // 审核标签
BizId int64 `gorm:"index:idx_biz_type_id"` // 业务ID: Note:为了让审核模块复用(即既能审核帖子又能审核评论),其中1:表示帖子业务,2:表示评论业务
PlateID int64 `gorm:"index"`
Uid int64 `gorm:"column:uid;index"` // 提交审核的用户ID
Status uint8 `gorm:"default:0"` // 审核状态
Remark string `gorm:"type:text"` // 审核备注
CreatedAt int64 `gorm:"column:created_at;type:bigint;not null"` // 创建时间
UpdatedAt int64 `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间
}
type CheckDAO ¶
type CheckDAO interface {
Create(ctx context.Context, check Check) (int64, error)
UpdateStatus(ctx context.Context, check Check) error
FindAll(ctx context.Context, pagination domain.Pagination) ([]Check, error)
FindByID(ctx context.Context, checkId int64) (Check, error)
FindByPostId(ctx context.Context, postId uint) (Check, error)
}
type Comment ¶
type Comment struct {
Id int64 `gorm:"autoIncrement;primaryKey"` // 评论ID
UserId int64 `gorm:"index:idx_user_id"` // 发表评论的用户ID
Biz string `gorm:"index:idx_biz_type_id"` // 业务类型
BizId int64 `gorm:"index:idx_biz_type_id"` // 业务ID
Content string `gorm:"column:content;type:text"` // 评论内容
PostId int64 `gorm:"index:idx_post_id"` // 帖子ID,用于多级评论
RootId sql.NullInt64 `gorm:"column:root_id;index"` // 根评论ID
PID sql.NullInt64 `gorm:"column:pid;index;default:1"` // 父评论ID
ParentComment *Comment `gorm:"ForeignKey:PID;AssociationForeignKey:ID;constraint:OnDelete:CASCADE"` // 父评论
CreatedAt int64 `gorm:"autoCreateTime"` // 创建时间
UpdatedAt int64 `gorm:"autoUpdateTime"` // 更新时间
Status uint8 `gorm:"default:0"` // 评论状态 和domain/post.go中的Status对应
}
Comment 评论模型定义
type CommentDAO ¶
type CommentDAO interface {
CreateComment(ctx context.Context, comment Comment) (int64, error)
DeleteCommentById(ctx context.Context, commentId int64) error
FindCommentsByPostId(ctx context.Context, postId int64, minId, limit int64) ([]Comment, error)
GetMoreCommentsReply(ctx context.Context, rootId, maxId, limit int64) ([]Comment, error)
FindRepliesByRid(ctx context.Context, rid int64, id int64, limit int64) ([]Comment, error)
FindTopCommentsByPostId(ctx context.Context, postId int64) (Comment, error)
FindCommentByCommentId(ctx context.Context, commentId int64) (Comment, error)
UpdateComment(ctx context.Context, comment Comment) error
}
CommentDAO 评论数据访问接口定义
func NewCommentDAO ¶
func NewCommentDAO(db *gorm.DB, l *zap.Logger) CommentDAO
NewCommentDAO 创建新的评论服务
type CommentSearch ¶
type Interactive ¶
type Interactive struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
BizID uint `gorm:"index"`
ReadCount int64 `gorm:"column:read_count"`
LikeCount int64 `gorm:"column:like_count"`
CollectCount int64 `gorm:"column:collect_count"`
UpdateTime int64 `gorm:"column:updated_at;type:bigint;not null;index"`
CreateTime int64 `gorm:"column:created_at;type:bigint"`
}
Interactive 互动信息结构体
type InteractiveDAO ¶
type InteractiveDAO interface {
IncrReadCnt(ctx context.Context, postId uint) error
InsertLikeInfo(ctx context.Context, lb UserLikeBiz) error
DeleteLikeInfo(ctx context.Context, lb UserLikeBiz) error
InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
GetLikeInfo(ctx context.Context, postId uint, uid int64) (UserLikeBiz, error)
GetCollectInfo(ctx context.Context, postId uint, uid int64) (UserCollectionBiz, error)
Get(ctx context.Context, postId uint) (Interactive, error)
GetByIds(ctx context.Context, postIds []uint) ([]Interactive, error)
}
func NewInteractiveDAO ¶
func NewInteractiveDAO(db *gorm.DB, l *zap.Logger) InteractiveDAO
type Job ¶
type Job struct {
Id int64 `gorm:"primaryKey,autoIncrement"` // 任务ID,主键,自增
Name string `gorm:"type:varchar(128);unique"` // 任务名称,唯一
Executor string `gorm:"type:varchar(255)"` // 执行者,执行该任务的实体
Expression string `gorm:"type:varchar(255)"` // 调度表达式,用于描述任务的调度时间
Cfg string `gorm:"type:text"` // 配置,任务的具体配置信息
Status int `gorm:"type:int"` // 任务状态,用于标识任务当前的状态(如启用、禁用等)
Version int `gorm:"type:int"` // 版本号,用于乐观锁控制并发更新
NextTime int64 `gorm:"index"` // 下次执行时间,Unix时间戳
CreateTime int64 `gorm:"column:created_at;type:bigint;not null"` // 创建时间,Unix时间戳
UpdatedTime int64 `gorm:"column:updated_at;type:bigint;not null"` // 更新时间,Unix时间戳
}
type JobDAO ¶
type JobDAO interface {
Preempt(ctx context.Context) (Job, error)
Release(ctx context.Context, jobId int64) error
UpdateTime(ctx context.Context, id int64) error
UpdateNextTime(ctx context.Context, id int64, t time.Time) error
}
JobDAO 定义了任务数据访问对象接口
type LotteryDraw ¶
type LotteryDraw struct {
ID int `gorm:"primaryKey;autoIncrement"` // 抽奖活动的唯一标识符
Name string `gorm:"column:name;not null"` // 抽奖活动名称
Description string `gorm:"column:description;type:text"` // 抽奖活动描述
StartTime int64 `gorm:"column:start_time;not null"` // 活动开始时间(UNIX 时间戳)
EndTime int64 `gorm:"column:end_time;not null"` // 活动结束时间(UNIX 时间戳)
Status string `gorm:"column:status;type:varchar(20)"` // 活动状态
CreatedAt int64 `gorm:"column:created_at;autoCreateTime"` // 创建时间(UNIX 时间戳)
UpdatedAt int64 `gorm:"column:updated_at;autoUpdateTime"` // 更新时间(UNIX 时间戳)
Participants []Participant `gorm:"foreignKey:LotteryID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 参与者列表
}
LotteryDraw 数据库中的抽奖活动模型
type LotteryDrawDAO ¶
type LotteryDrawDAO interface {
CreateLotteryDraw(ctx context.Context, model LotteryDraw) error
GetLotteryDrawByID(ctx context.Context, id int) (LotteryDraw, error)
ListLotteryDraws(ctx context.Context, status string, pagination domain.Pagination) ([]LotteryDraw, error)
ExistsLotteryDrawByName(ctx context.Context, name string) (bool, error)
HasUserParticipatedInLottery(ctx context.Context, id int, userID int64) (bool, error)
CreateSecondKillEvent(ctx context.Context, model SecondKillEvent) error
GetSecondKillEventByID(ctx context.Context, id int) (SecondKillEvent, error)
ListSecondKillEvents(ctx context.Context, status string, pagination domain.Pagination) ([]SecondKillEvent, error)
ExistsSecondKillEventByName(ctx context.Context, name string) (bool, error)
HasUserParticipatedInSecondKill(ctx context.Context, id int, userID int64) (bool, error)
AddParticipant(ctx context.Context, model Participant) error
ListPendingLotteryDraws(ctx context.Context, currentTime int64) ([]LotteryDraw, error)
UpdateLotteryDrawStatus(ctx context.Context, id int, status string) error
ListPendingSecondKillEvents(ctx context.Context, currentTime int64) ([]SecondKillEvent, error)
UpdateSecondKillEventStatus(ctx context.Context, id int, status string) error
ListActiveLotteryDraws(ctx context.Context, currentTime int64) ([]LotteryDraw, error)
ListActiveSecondKillEvents(ctx context.Context, currentTime int64) ([]SecondKillEvent, error)
}
func NewLotteryDrawDAO ¶
func NewLotteryDrawDAO(db *gorm.DB, l *zap.Logger) LotteryDrawDAO
type Menu ¶
type Menu struct {
ID int `json:"id" gorm:"primaryKey;column:id;comment:菜单ID"`
Name string `json:"name" gorm:"column:name;type:varchar(50);not null;comment:菜单显示名称"`
ParentID int `json:"parent_id" gorm:"column:parent_id;default:0;comment:上级菜单ID,0表示顶级菜单"`
Path string `json:"path" gorm:"column:path;type:varchar(255);not null;comment:前端路由访问路径"`
Component string `json:"component" gorm:"column:component;type:varchar(255);not null;comment:前端组件文件路径"`
Icon string `json:"icon" gorm:"column:icon;type:varchar(50);default:'';comment:菜单显示图标"`
SortOrder int `json:"sort_order" gorm:"column:sort_order;default:0;comment:菜单显示顺序,数值越小越靠前"`
RouteName string `json:"route_name" gorm:"column:route_name;type:varchar(50);not null;comment:前端路由名称,需唯一"`
Hidden int `json:"hidden" gorm:"column:hidden;type:tinyint(1);default:0;comment:菜单是否隐藏(0:显示 1:隐藏)"`
CreateTime int64 `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:记录创建时间戳"`
UpdateTime int64 `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:记录最后更新时间戳"`
IsDeleted int `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:逻辑删除标记(0:未删除 1:已删除)"`
Children []*Menu `json:"children" gorm:"-"` // 子菜单列表,不映射到数据库
}
type MenuDAO ¶
type MenuDAO interface {
CreateMenu(ctx context.Context, menu *Menu) error
GetMenuById(ctx context.Context, id int) (*Menu, error)
UpdateMenu(ctx context.Context, menu *Menu) error
DeleteMenu(ctx context.Context, id int) error
ListMenus(ctx context.Context, page, pageSize int) ([]*Menu, int, error)
GetMenuTree(ctx context.Context) ([]*Menu, error)
}
type Participant ¶
type Participant struct {
ID string `gorm:"primaryKey;column:id;type:char(36)"` // 参与记录的唯一标识符 (UUID)
LotteryID *int `gorm:"column:lottery_id"` // 抽奖活动ID,可为null
SecondKillID *int `gorm:"column:second_kill_id"` // 秒杀活动ID,可为null
UserID int64 `gorm:"column:user_id;not null"` // 参与者的用户ID
ParticipatedAt int64 `gorm:"column:participated_at;not null"` // 参与时间(UNIX 时间戳)
}
Participant 数据库中的参与者记录模型
type PermissionDAO ¶
type PermissionDAO interface {
AssignRole(ctx context.Context, roleId int, menuIds []int, apiIds []int) error
AssignRoleToUser(ctx context.Context, userId int, roleIds []int, menuIds []int, apiIds []int) error
AssignRoleToUsers(ctx context.Context, userIds []int, roleIds []int, menuIds []int, apiIds []int) error
RemoveUserPermissions(ctx context.Context, userId int) error
RemoveRolePermissions(ctx context.Context, roleId int) error
RemoveUsersPermissions(ctx context.Context, userIds []int) error
}
func NewPermissionDAO ¶
type Plate ¶
type Plate struct {
ID int64 `gorm:"primaryKey;autoIncrement"` // 板块ID
Name string `gorm:"size:255;not null;uniqueIndex"` // 板块名称
Description string `gorm:"type:text"` // 板块描述
CreateTime int64 `gorm:"column:created_at;type:bigint"` // 创建时间
UpdatedTime int64 `gorm:"column:updated_at;type:bigint"` // 更新时间
DeletedTime int64 `gorm:"column:deleted_at;type:bigint"` // 删除时间
Deleted bool `gorm:"column:deleted;default:false"` // 是否删除
Uid int64 `gorm:"index"` // 板主id
Posts []Post `gorm:"foreignKey:PlateID"` // 帖子关系
}
type PlateDAO ¶
type Post ¶
type Post struct {
gorm.Model
Title string `gorm:"size:255;not null"` // 帖子标题
Content string `gorm:"type:text;not null"` // 帖子内容
Status uint8 `gorm:"default:0"` // 帖子状态
Uid int64 `gorm:"column:uid;index"` // 作者ID
Slug string `gorm:"size:100;uniqueIndex"` // 唯一标识
CategoryID int64 `gorm:"index"` // 分类ID
PlateID int64 `gorm:"index"` // 板块ID
Plate Plate `gorm:"foreignKey:PlateID"` // 关联板块
Tags string `gorm:"type:varchar(255);default:''"` // 标签
CommentCount int64 `gorm:"default:0"` // 评论数
IsSubmit bool `gorm:"default:false"` // 是否提交审核
}
type PostDAO ¶
type PostDAO interface {
Insert(ctx context.Context, post Post) (uint, error)
Update(ctx context.Context, post Post) error
UpdateStatus(ctx context.Context, postId uint, uid int64, status uint8) error
GetById(ctx context.Context, postId uint, uid int64) (Post, error)
GetPubById(ctx context.Context, postId uint) (PubPost, error)
ListPub(ctx context.Context, pagination domain.Pagination) ([]PubPost, error)
List(ctx context.Context, pagination domain.Pagination) ([]Post, error)
Delete(ctx context.Context, postId uint, uid int64) error
ListAll(ctx context.Context, pagination domain.Pagination) ([]Post, error)
GetPost(ctx context.Context, postId uint) (Post, error)
GetPostsCount(ctx context.Context) (int64, error)
GetPostsByPlate(ctx context.Context, plateId int64, pagination domain.Pagination) ([]Post, error)
}
type PostSearch ¶
type PostSearch struct {
Id uint `json:"id"`
Title string `json:"title"`
AuthorId int64 `json:"author_id"`
Status uint8 `json:"status"`
Content string `json:"content"`
Tags string `json:"tags"`
}
PostSearch 定义帖子搜索模型
type Profile ¶
type Profile struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
UserID int64 `gorm:"not null;index"`
RealName string `gorm:"size:50"`
Avatar string `gorm:"type:text"`
About string `gorm:"type:text"`
Birthday string `gorm:"column:birthday;type:varchar(10)"`
Email string `gorm:"type:varchar(100)"`
Phone *string `gorm:"type:varchar(15);uniqueIndex"`
}
Profile 用户资料信息模型
type PubPost ¶
type PubPost struct {
gorm.Model
Title string `gorm:"size:255;not null"` // 帖子标题
Content string `gorm:"type:text;not null"` // 帖子内容
Status uint8 `gorm:"default:0"` // 帖子状态
Uid int64 `gorm:"column:uid;index"` // 作者ID
Slug string `gorm:"size:100;uniqueIndex"` // 唯一标识
CategoryID int64 `gorm:"index"` // 分类ID
PlateID int64 `gorm:"index"` // 板块ID
Plate Plate `gorm:"foreignKey:PlateID"` // 关联板块
Tags string `gorm:"type:varchar(255);default:''"` // 标签
CommentCount int64 `gorm:"default:0"` // 评论数
}
type RankingParameter ¶
type RankingParameter struct {
gorm.Model
ID uint `gorm:"primaryKey" json:"id"` // 主键 ID
Alpha float64 `gorm:"not null;default:1.0" json:"alpha"` // 默认值 1.0
Beta float64 `gorm:"not null;default:10.0" json:"beta"` // 默认值 10.0
Gamma float64 `gorm:"not null;default:20.0" json:"gamma"` // 默认值 20.0
Lambda float64 `gorm:"not null;default:1.2" json:"lambda"` // 默认值 1.2
// CreatedAt 和 UpdatedAt 可根据需要自动填充
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
type RankingParameterDAO ¶
type RankingParameterDAO interface {
Insert(ctx context.Context, rankingParameter RankingParameter) (uint, error) // Note:为了保证可以看到历史参数的内容,只以追加的形式插入,不进行更新
FindLastParameter(ctx context.Context) (RankingParameter, error) // Note: 查找最后一次插入的参数
}
func NewRankingParameterDAO ¶
func NewRankingParameterDAO(db *gorm.DB, l *zap.Logger) RankingParameterDAO
type RecentActivity ¶
type Relation ¶
type Relation struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement"` // 主键ID
FollowerID int64 `gorm:"column:follower_id;uniqueIndex:follower_id_followee_id"` // 关注者ID
FolloweeID int64 `gorm:"column:followee_id;uniqueIndex:follower_id_followee_id"` // 被关注者ID
Status uint8 `gorm:"column:status"` // 关系类型
Deleted bool `gorm:"column:deleted"` // 删除标志
CreatedAt int64 `gorm:"column:created_at"` // 创建时间
UpdatedAt int64 `gorm:"column:updated_at"` // 更新时间
}
Relation 存储用户的关注数据
type RelationCount ¶
type RelationCount struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement"` // 主键ID
UserID int64 `gorm:"column:user_id;unique"` // 用户ID
FollowerCount int64 `gorm:"column:follower_count"` // 粉丝数量
FolloweeCount int64 `gorm:"column:followee_count"` // 关注数量
CreatedAt int64 `gorm:"column:created_at"` // 创建时间
UpdatedAt int64 `gorm:"column:updated_at"` // 更新时间
}
RelationCount 存储用户的粉丝和关注数量
type RelationDAO ¶
type RelationDAO interface {
ListFollowerRelations(ctx context.Context, followerID int64, pagination domain.Pagination) ([]Relation, error)
ListFolloweeRelations(ctx context.Context, followeeID int64, pagination domain.Pagination) ([]Relation, error)
FollowUser(ctx context.Context, followerID, followeeID int64) error
CancelFollowUser(ctx context.Context, followerID, followeeID int64) error
UpdateStatus(ctx context.Context, followerID, followeeID int64, status bool) error
FollowCount(ctx context.Context, userID int64) (RelationCount, error)
}
RelationDAO 定义了与用户关系相关的接口
func NewRelationDAO ¶
func NewRelationDAO(db *gorm.DB, l *zap.Logger) RelationDAO
NewRelationDAO 创建RelationDAO实例
type Role ¶
type Role struct {
ID int `json:"id" gorm:"primaryKey;column:id;comment:主键ID"`
Name string `json:"name" gorm:"column:name;type:varchar(50);not null;unique;comment:角色名称"`
Description string `json:"description" gorm:"column:description;type:varchar(255);comment:角色描述"`
RoleType int `json:"role_type" gorm:"column:role_type;type:tinyint(1);not null;comment:角色类型(1:系统角色,2:自定义角色)"`
IsDefault int `json:"is_default" gorm:"column:is_default;type:tinyint(1);default:0;comment:是否为默认角色(0:否,1:是)"`
CreateTime int64 `json:"create_time" gorm:"column:create_time;autoCreateTime;comment:创建时间"`
UpdateTime int64 `json:"update_time" gorm:"column:update_time;autoUpdateTime;comment:更新时间"`
IsDeleted int `json:"is_deleted" gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否删除(0:否,1:是)"`
Menus []*Menu `json:"menus" gorm:"-"`
Apis []*Api `json:"apis" gorm:"-"`
}
type RoleDAO ¶
type RoleDAO interface {
CreateRole(ctx context.Context, role *Role, menuIds []int, apiIds []int) error
GetRoleById(ctx context.Context, id int) (*Role, error)
UpdateRole(ctx context.Context, role *Role) error
DeleteRole(ctx context.Context, id int) error
ListRoles(ctx context.Context, page, pageSize int) ([]*Role, int, error)
GetRole(ctx context.Context, roleId int) (*Role, error)
GetUserRole(ctx context.Context, userId int) (*Role, error)
}
func NewRoleDAO ¶
type SearchDAO ¶
type SearchDAO interface {
CreatePostIndex(ctx context.Context, properties ...interface{}) error
CreateCommentIndex(ctx context.Context, properties ...interface{}) error
CreateUserIndex(ctx context.Context, properties ...interface{}) error
CreateLogsIndex(ctx context.Context) error
SearchPosts(ctx context.Context, keywords []string) ([]PostSearch, error)
SearchUsers(ctx context.Context, keywords []string) ([]UserSearch, error)
SearchComments(ctx context.Context, keywords []string) ([]CommentSearch, error)
ListAllPostsWithAuthorId(ctx context.Context, authorid string) ([]PostSearch, error)
IsExistsPost(ctx context.Context, postid string) (bool, error)
IsExistsUser(ctx context.Context, userid string) (bool, error)
IsExistsComment(ctx context.Context, commentid string) (bool, error)
InputUser(ctx context.Context, user UserSearch) error
InputPost(ctx context.Context, post PostSearch) error
InputComment(ctx context.Context, comment CommentSearch) error
BulkInputPosts(ctx context.Context, posts []PostSearch) error
BulkInputUsers(ctx context.Context, users []UserSearch) error
BulkInputLogs(ctx context.Context, event []ReadEvent) error
DeleteUserIndex(ctx context.Context, userId int64) error
DeletePostIndex(ctx context.Context, postId uint) error
DeleteCommentIndex(ctx context.Context, commentId uint) error
}
func NewSearchDAO ¶
func NewSearchDAO(client *elasticsearch.TypedClient, l *zap.Logger) SearchDAO
NewSearchDAO 创建并返回一个新的 SearchDAO 实例
type SecondKillEvent ¶
type SecondKillEvent struct {
ID int `gorm:"primaryKey;autoIncrement"` // 秒杀活动的唯一标识符
Name string `gorm:"column:name;not null"` // 秒杀活动名称
Description string `gorm:"column:description;type:text"` // 秒杀活动描述
StartTime int64 `gorm:"column:start_time;not null"` // 活动开始时间(UNIX 时间戳)
EndTime int64 `gorm:"column:end_time;not null"` // 活动结束时间(UNIX 时间戳)
Status string `gorm:"column:status;type:varchar(20)"` // 活动状态
CreatedAt int64 `gorm:"column:created_at;autoCreateTime"` // 创建时间(UNIX 时间戳)
UpdatedAt int64 `gorm:"column:updated_at;autoUpdateTime"` // 更新时间(UNIX 时间戳)
Participants []Participant `gorm:"foreignKey:SecondKillID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // 参与者列表
}
SecondKillEvent 数据库中的秒杀活动模型
type SmsDAO ¶
type SmsDAO interface {
Insert(ctx context.Context, log VCodeSmsLog) error
FindFailedLogs(ctx context.Context) ([]VCodeSmsLog, error) //查找当前时刻以前,发送失败的logs,后续需要重新发送
Update(ctx context.Context, log VCodeSmsLog) error
}
type User ¶
type User struct {
ID int64 `gorm:"primarykey;autoIncrement"`
CreateTime int64 `gorm:"column:created_at;type:bigint;not null"`
UpdatedTime int64 `gorm:"column:updated_at;type:bigint;not null"`
DeletedTime int64 `gorm:"column:deleted_at;type:bigint;index"`
Username string `gorm:"column:username;type:varchar(100);uniqueIndex;not null"`
PasswordHash string `gorm:"not null"`
Deleted bool `gorm:"column:deleted;default:false;not null"`
Profile Profile `gorm:"foreignKey:UserID;references:ID"`
Roles string `gorm:"column:roles;type:json;comment:用户角色ID列表"`
}
User 用户模型
type UserCollectionBiz ¶
type UserCollectionBiz struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
Uid int64 `gorm:"index"`
BizID uint `gorm:"index"`
Status int `gorm:"column:status"`
UpdateTime int64 `gorm:"column:updated_at;type:bigint;not null;index"`
CreateTime int64 `gorm:"column:created_at;type:bigint"`
Deleted bool `gorm:"column:deleted;default:false"`
}
UserCollectionBiz 用户收藏业务结构体
type UserDAO ¶
type UserDAO interface {
CreateUser(ctx context.Context, u User) error
FindByID(ctx context.Context, id int64) (User, error)
FindByUsername(ctx context.Context, username string) (User, error)
FindByPhone(ctx context.Context, phone string) (User, error)
UpdatePasswordByUsername(ctx context.Context, username string, newPassword string) error
DeleteUser(ctx context.Context, username string, uid int64) error
UpdateProfile(ctx context.Context, profile domain.Profile) error
GetProfileByUserID(ctx context.Context, userId int64) (domain.Profile, error)
ListUser(ctx context.Context, pagination domain.Pagination) ([]domain.UserWithProfile, error)
UpdateProfileAdmin(ctx context.Context, profile domain.Profile) error
}
type UserLikeBiz ¶
type UserLikeBiz struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
Uid int64 `gorm:"index"`
BizID uint `gorm:"index"`
Status int `gorm:"type:int"`
UpdateTime int64 `gorm:"column:updated_at;type:bigint;not null;index"`
CreateTime int64 `gorm:"column:created_at;type:bigint"`
Deleted bool `gorm:"column:deleted;default:false"`
}
UserLikeBiz 用户点赞业务结构体
type UserSearch ¶
type UserSearch struct {
Id int64 `json:"id"`
Nickname string `json:"nickname"`
Birthday time.Time `json:"birthday"`
Email string `json:"email"`
Phone string `json:"phone"`
About string `json:"about"`
}
UserSearch 定义用户搜索模型
type VCodeSmsLog ¶
type VCodeSmsLog struct {
Id int64 `gorm:"column:id;primaryKey;autoIncrement"` // 自增ID
SmsId int64 `gorm:"column:sms_id"` // 短信类型ID
SmsType string `gorm:"column:sms_type"` // 短信类型
Mobile string `gorm:"column:mobile"` // 手机号
VCode string `gorm:"column:v_code"` // 验证码
Driver string `gorm:"column:driver"` // 服务商类型
Status int64 `gorm:"column:status"` // 发送状态,1为成功,0为失败
StatusCode string `gorm:"column:status_code"` // 状态码
CreateTime int64 `gorm:"column:created_at;type:bigint;not null"` // 创建时间
UpdatedTime int64 `gorm:"column:updated_at;type:bigint;not null;index"` // 更新时间
DeletedTime int64 `gorm:"column:deleted_at;type:bigint;index"` // 删除时间
}
VCodeSmsLog 表示用户认证操作的日志记录
Click to show internal directories.
Click to hide internal directories.