🎨 新增讲师关注功能

This commit is contained in:
2025-09-06 21:47:31 +08:00
parent 90bd42d488
commit 7bcc2370bd
7 changed files with 230 additions and 1 deletions

View File

@@ -109,7 +109,7 @@ func (*AppUserApi) WechatLogin(ctx *gin.Context) {
user, err := appUserService.WechatLogin(info)
if err != nil {
r.FailWithMessage("登录失败", ctx)
r.FailWithMessage("登录失败:"+err.Error(), ctx)
return
}
// 生成token
@@ -395,3 +395,84 @@ func (a *AppUserApi) GetTeacherList(context *gin.Context) {
PageSize: p.PageSize,
}, "获取讲师列表成功", context)
}
// GetFollowTeacherList 获取关注的讲师列表
func (a *AppUserApi) GetFollowTeacherList(context *gin.Context) {
var p common.PageInfo
if err := context.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("参数错误,获取关注的讲师列表失败", zap.Error(err))
r.FailWithMessage("参数错误,获取关注的讲师列表失败", context)
return
}
id := user_jwt.GetUserID(context)
if id == 0 {
global.GVA_LOG.Error("获取用户ID失败")
r.FailWithMessage("获取用户ID失败", context)
return
}
teachers, total, err := appUserService.GetFollowTeacherList(id, p)
if err != nil {
global.GVA_LOG.Error("获取关注的讲师列表失败", zap.Error(err))
r.FailWithMessage("获取关注的讲师列表失败", context)
return
}
r.OkWithDetailed(
r.PageResult{
List: teachers,
Total: total,
Page: p.Page,
PageSize: p.PageSize,
}, "获取关注的讲师列表成功", context)
}
// FollowTeacher 关注讲师
func (a *AppUserApi) FollowTeacher(context *gin.Context) {
var p app.Follow
if err := context.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("参数错误,关注讲师失败", zap.Error(err))
r.FailWithMessage("参数错误,关注讲师失败", context)
return
}
id := user_jwt.GetUserID(context)
if id == 0 {
global.GVA_LOG.Error("获取用户ID失败")
r.FailWithMessage("获取用户ID失败", context)
return
}
p.UserId = id
if err := appUserService.FollowTeacher(p); err != nil {
global.GVA_LOG.Error("关注讲师失败", zap.Error(err))
r.FailWithMessage("关注讲师失败", context)
return
}
r.OkWithMessage("关注讲师成功", context)
}
// GetFollowStatus 获取用户关注讲师状态
func (a *AppUserApi) GetFollowStatus(ctx *gin.Context) {
userId := user_jwt.GetUserID(ctx)
if userId == 0 {
r.FailWithMessage("获取用户ID失败", ctx)
return
}
teacherIdStr := ctx.Query("teacherId")
if teacherIdStr == "" {
r.FailWithMessage("缺少参数: teacherId", ctx)
return
}
teacherId, err := strconv.ParseUint(teacherIdStr, 10, 64)
if err != nil {
r.FailWithMessage("teacherId参数格式错误", ctx)
return
}
followed, err := appUserService.IsFollowTeacher(uint(userId), uint(teacherId))
if err != nil {
global.GVA_LOG.Error("获取关注状态失败", zap.Error(err))
r.FailWithMessage("获取关注状态失败", ctx)
return
}
r.OkWithDetailed(followed, "获取关注状态成功", ctx)
}