🎨 优化用户和分类相关接口,新增banner接口
This commit is contained in:
96
api/v1/app/banner.go
Normal file
96
api/v1/app/banner.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/model/app"
|
||||
common "git.echol.cn/loser/lckt/model/common/request"
|
||||
"git.echol.cn/loser/lckt/model/common/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type BannerApi struct{}
|
||||
|
||||
// Create 新建Banner
|
||||
func (b *BannerApi) Create(ctx *gin.Context) {
|
||||
var p app.Banner
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
response.FailWithMessage("参数错误", ctx)
|
||||
return
|
||||
}
|
||||
if err := bannerService.CreateBanner(p); err != nil {
|
||||
response.FailWithMessage("创建失败: "+err.Error(), ctx)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", ctx)
|
||||
}
|
||||
|
||||
// Delete 删除Banner
|
||||
func (b *BannerApi) Delete(ctx *gin.Context) {
|
||||
var p app.Banner
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
response.FailWithMessage("参数错误", ctx)
|
||||
return
|
||||
}
|
||||
if err := bannerService.DeleteBanner(p.ID); err != nil {
|
||||
response.FailWithMessage("删除失败: "+err.Error(), ctx)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", ctx)
|
||||
}
|
||||
|
||||
// Update 更新Banner
|
||||
func (b *BannerApi) Update(ctx *gin.Context) {
|
||||
var p app.Banner
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
response.FailWithMessage("参数错误", ctx)
|
||||
return
|
||||
}
|
||||
if err := bannerService.UpdateBanner(p); err != nil {
|
||||
response.FailWithMessage("更新失败: "+err.Error(), ctx)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", ctx)
|
||||
}
|
||||
|
||||
// GetList 获取Banner列表
|
||||
func (b *BannerApi) GetList(ctx *gin.Context) {
|
||||
var p common.PageInfo
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
response.FailWithMessage("参数错误", ctx)
|
||||
return
|
||||
}
|
||||
list, total, err := bannerService.GetBannerList(p.Page, p.PageSize)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取列表失败: "+err.Error(), ctx)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: p.Page,
|
||||
PageSize: p.PageSize,
|
||||
}, ctx)
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取Banner
|
||||
func (b *BannerApi) GetByID(ctx *gin.Context) {
|
||||
var p common.GetById
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
response.FailWithMessage("参数错误", ctx)
|
||||
return
|
||||
}
|
||||
banner, err := bannerService.GetBannerByID(p.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), ctx)
|
||||
return
|
||||
}
|
||||
response.OkWithData(banner, ctx)
|
||||
}
|
||||
|
||||
func (b *BannerApi) GetIndexBanners(context *gin.Context) {
|
||||
list, err := bannerService.GetBannerIndex()
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取首页Banner失败: "+err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, context)
|
||||
}
|
12
api/v1/app/enter.go
Normal file
12
api/v1/app/enter.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package app
|
||||
|
||||
import "git.echol.cn/loser/lckt/service"
|
||||
|
||||
type ApiGroup struct {
|
||||
AppUserApi
|
||||
BannerApi
|
||||
}
|
||||
|
||||
var userService = service.ServiceGroupApp.UserServiceGroup.UserService
|
||||
var appUserService = service.ServiceGroupApp.AppServiceGroup.AppUserService
|
||||
var bannerService = service.ServiceGroupApp.AppServiceGroup.BannerService
|
195
api/v1/app/user.go
Normal file
195
api/v1/app/user.go
Normal file
@@ -0,0 +1,195 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
r "git.echol.cn/loser/lckt/model/common/response"
|
||||
"git.echol.cn/loser/lckt/model/user/request"
|
||||
"git.echol.cn/loser/lckt/utils"
|
||||
"git.echol.cn/loser/lckt/utils/user_jwt"
|
||||
"git.echol.cn/loser/lckt/utils/wechat"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AppUserApi struct{}
|
||||
|
||||
// SendCode 发送验证码
|
||||
func (*AppUserApi) SendCode(ctx *gin.Context) {
|
||||
var p request.SendCodeReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,发送验证码失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
if err := userService.SendCode(p); err != nil {
|
||||
r.FailWithMessage("发送验证码失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithMessage("发送验证码成功", ctx)
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
func (*AppUserApi) Login(ctx *gin.Context) {
|
||||
var p request.CodeLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if result, _ := global.GVA_REDIS.Get(ctx, fmt.Sprintf("VerifyCode:%s", p.Phone)).Result(); result != p.Code {
|
||||
global.GVA_LOG.Error("验证码错误", zap.String("phone", p.Phone))
|
||||
r.FailWithMessage("验证码错误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := appUserService.Login(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("登录失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = global.GVA_REDIS.Get(ctx, user.Phone).Result(); errors.Is(err, redis.Nil) {
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
} else if err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// WechatLogin 微信登录
|
||||
func (*AppUserApi) WechatLogin(ctx *gin.Context) {
|
||||
var p request.CodeLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
//Todo 待完善微信登录
|
||||
info := wechat.GetUserInfo(p.Code)
|
||||
if info == nil {
|
||||
r.FailWithMessage("获取用户信息失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := appUserService.WechatLogin(info)
|
||||
if err != nil {
|
||||
r.FailWithMessage("登录失败", ctx)
|
||||
return
|
||||
}
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
if _, err = global.GVA_REDIS.Get(ctx, user.Phone).Result(); errors.Is(err, redis.Nil) {
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
func (*AppUserApi) GetUserInfo(ctx *gin.Context) {
|
||||
id := user_jwt.GetUserID(ctx)
|
||||
if id == 0 {
|
||||
global.GVA_LOG.Error("获取用户ID失败")
|
||||
r.FailWithMessage("获取用户ID失败", ctx)
|
||||
return
|
||||
}
|
||||
user, err := appUserService.GetUserInfo(id)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取用户信息失败", zap.Error(err))
|
||||
r.FailWithMessage("获取用户信息失败", ctx)
|
||||
return
|
||||
}
|
||||
r.OkWithDetailed(user, "获取用户信息成功", ctx)
|
||||
}
|
||||
|
||||
// PwdLogin 密码登录
|
||||
func (*AppUserApi) PwdLogin(ctx *gin.Context) {
|
||||
var p request.PwdLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
user, err := appUserService.PwdLogin(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("手机号或密码错误!", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
}
|
@@ -186,3 +186,13 @@ func (catApi *CategoryApi) GetCategoryPublic(c *gin.Context) {
|
||||
"info": "不需要鉴权的类别接口信息",
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
func (catApi *CategoryApi) GetCategoryListPublic(context *gin.Context) {
|
||||
list, err := catService.GetIndexCategoryList()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取类别列表失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取类别列表失败:"+err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, context)
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/api/v1/app"
|
||||
"git.echol.cn/loser/lckt/api/v1/article"
|
||||
"git.echol.cn/loser/lckt/api/v1/bot"
|
||||
"git.echol.cn/loser/lckt/api/v1/category"
|
||||
@@ -16,10 +17,11 @@ var ApiGroupApp = new(ApiGroup)
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
AppApiGroup app.ApiGroup
|
||||
CategoryApiGroup category.ApiGroup
|
||||
BotApiGroup bot.ApiGroup
|
||||
ArticleApiGroup article.ApiGroup
|
||||
UserApiGroup user.APPUserApi
|
||||
UserApiGroup user.UserApi
|
||||
VipApiGroup vip.ApiGroup
|
||||
NoticeApiGroup notice.ApiGroup
|
||||
}
|
||||
|
@@ -2,6 +2,6 @@ package user
|
||||
|
||||
import "git.echol.cn/loser/lckt/service"
|
||||
|
||||
type ApiGroup struct{ APPUserApi }
|
||||
type ApiGroup struct{ UserApi }
|
||||
|
||||
var userService = service.ServiceGroupApp.UserServiceGroup.UserService
|
||||
|
@@ -1,141 +1,18 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
common "git.echol.cn/loser/lckt/model/common/request"
|
||||
r "git.echol.cn/loser/lckt/model/common/response"
|
||||
"git.echol.cn/loser/lckt/model/user/request"
|
||||
"git.echol.cn/loser/lckt/utils"
|
||||
"git.echol.cn/loser/lckt/utils/user_jwt"
|
||||
"git.echol.cn/loser/lckt/utils/wechat"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
type APPUserApi struct{}
|
||||
|
||||
// SendCode 发送验证码
|
||||
func (*APPUserApi) SendCode(ctx *gin.Context) {
|
||||
var p request.SendCodeReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,发送验证码失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
if err := userService.SendCode(p); err != nil {
|
||||
r.FailWithMessage("发送验证码失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithMessage("发送验证码成功", ctx)
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
func (*APPUserApi) Login(ctx *gin.Context) {
|
||||
var p request.CodeLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if result, _ := global.GVA_REDIS.Get(ctx, fmt.Sprintf("VerifyCode:%s", p.Phone)).Result(); result != p.Code {
|
||||
global.GVA_LOG.Error("验证码错误", zap.String("phone", p.Phone))
|
||||
r.FailWithMessage("验证码错误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userService.Login(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("登录失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = global.GVA_REDIS.Get(ctx, user.Phone).Result(); err == redis.Nil {
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
} else if err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// WechatLogin 微信登录
|
||||
func (*APPUserApi) WechatLogin(ctx *gin.Context) {
|
||||
var p request.CodeLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
//Todo 待完善微信登录
|
||||
info := wechat.GetUserInfo(p.Code)
|
||||
if info == nil {
|
||||
r.FailWithMessage("获取用户信息失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userService.WechatLogin(info)
|
||||
if err != nil {
|
||||
r.FailWithMessage("登录失败", ctx)
|
||||
return
|
||||
}
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
if _, err = global.GVA_REDIS.Get(ctx, user.Phone).Result(); err == redis.Nil {
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
}
|
||||
}
|
||||
type UserApi struct{}
|
||||
|
||||
// GetUserList 获取用户列表
|
||||
func (*APPUserApi) GetUserList(ctx *gin.Context) {
|
||||
func (*UserApi) GetUserList(ctx *gin.Context) {
|
||||
var p request.GetUserListReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
@@ -156,7 +33,7 @@ func (*APPUserApi) GetUserList(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// SetBalance 设置用户余额
|
||||
func (*APPUserApi) SetBalance(ctx *gin.Context) {
|
||||
func (*UserApi) SetBalance(ctx *gin.Context) {
|
||||
var p request.SetBalanceReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
@@ -170,50 +47,8 @@ func (*APPUserApi) SetBalance(ctx *gin.Context) {
|
||||
r.OkWithMessage("设置用户余额成功", ctx)
|
||||
}
|
||||
|
||||
// PwdLogin 密码登录
|
||||
func (*APPUserApi) PwdLogin(ctx *gin.Context) {
|
||||
var p request.PwdLoginReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
global.GVA_LOG.Error("参数错误,登录失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userService.PwdLogin(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("手机号或密码错误!", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成token
|
||||
token, claims, err := user_jwt.LoginToken(user)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取token失败!", zap.Error(err))
|
||||
r.FailWithMessage("获取token失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// 此处过期时间等于jwt过期时间
|
||||
dr, err := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer := dr
|
||||
if err := global.GVA_REDIS.Set(ctx, user.Phone, token, timer).Err(); err != nil {
|
||||
global.GVA_LOG.Error("设置登录状态失败!", zap.Error(err))
|
||||
r.FailWithMessage("设置登录状态失败", ctx)
|
||||
return
|
||||
}
|
||||
user_jwt.SetToken(ctx, token, int(claims.RegisteredClaims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
r.OkWithDetailed(gin.H{
|
||||
"User": user,
|
||||
"Token": token,
|
||||
"ExpiresAt": claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
}, "登录成功", ctx)
|
||||
}
|
||||
|
||||
// Register 注册-后台用
|
||||
func (*APPUserApi) Register(ctx *gin.Context) {
|
||||
func (*UserApi) Register(ctx *gin.Context) {
|
||||
var p request.RegisterReq
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), ctx)
|
||||
@@ -230,7 +65,7 @@ func (*APPUserApi) Register(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// SetUserStatus 设置用户状态
|
||||
func (*APPUserApi) SetUserStatus(ctx *gin.Context) {
|
||||
func (*UserApi) SetUserStatus(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
if id == "" {
|
||||
r.FailWithMessage("参数错误", ctx)
|
||||
@@ -245,7 +80,7 @@ func (*APPUserApi) SetUserStatus(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// GetUserById 根据id获取用户信息
|
||||
func (*APPUserApi) GetUserById(ctx *gin.Context) {
|
||||
func (*UserApi) GetUserById(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
if id == "" {
|
||||
r.FailWithMessage("参数错误", ctx)
|
||||
@@ -258,3 +93,24 @@ func (*APPUserApi) GetUserById(ctx *gin.Context) {
|
||||
}
|
||||
r.OkWithDetailed(user, "获取用户信息成功", ctx)
|
||||
}
|
||||
|
||||
func (a *UserApi) GetTeachers(context *gin.Context) {
|
||||
var p common.PageInfo
|
||||
if err := context.ShouldBind(&p); err != nil {
|
||||
r.FailWithMessage(err.Error(), context)
|
||||
global.GVA_LOG.Error("参数错误,获取教师列表失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
teachers, total, err := userService.GetTeachers(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取教师列表失败", context)
|
||||
return
|
||||
}
|
||||
r.OkWithDetailed(r.PageResult{
|
||||
List: teachers,
|
||||
Total: total,
|
||||
Page: p.Page,
|
||||
PageSize: p.PageSize,
|
||||
}, "讲师列表获取成功", context)
|
||||
}
|
||||
|
Reference in New Issue
Block a user