85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package plant
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
"sundynix-go/model/commom/response"
|
|
"sundynix-go/model/plant/request"
|
|
"sundynix-go/utils/auth"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type UserProfileApi struct{}
|
|
|
|
// UpdateProfile 修改用户信息
|
|
// @Tags 个人中心
|
|
// @Summary 修改用户信息
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.UpdateProfile true "修改用户信息"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
|
|
// @Router /profile/update [post]
|
|
func (a *UserProfileApi) UpdateProfile(c *gin.Context) {
|
|
var req request.UpdateProfile
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
userId := auth.GetUserId(c)
|
|
if err := userProfileService.UpdateProfile(req, userId); err != nil {
|
|
response.FailWithMsg("更新失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("更新成功", c)
|
|
}
|
|
|
|
// ProfileDetail 用户详情
|
|
// @Tags 个人中心
|
|
// @Summary 用户详情
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|
// @Router /profile/detail [get]
|
|
func (a *UserProfileApi) ProfileDetail(c *gin.Context) {
|
|
userId := auth.GetUserId(c)
|
|
res, err := userProfileService.ProfileDetail(userId)
|
|
if err != nil {
|
|
response.FailWithMsg("查询失败", c)
|
|
return
|
|
}
|
|
response.OkWithData(res, c)
|
|
}
|
|
|
|
// MyStars 我的收藏
|
|
// @Tags 个人中心
|
|
// @Summary 我的收藏
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.StarsPageReq true "分页获取收藏列表"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|
// @Router /profile/star [post]
|
|
func (a *UserProfileApi) MyStars(c *gin.Context) {
|
|
var req request.StarsPageReq
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
userId := auth.GetUserId(c)
|
|
list, total, err := userProfileService.MyStars(req, userId)
|
|
if err != nil {
|
|
global.Logger.Error("获取收藏失败", zap.Error(err))
|
|
response.FailWithMsg("获取收藏失败", c)
|
|
return
|
|
}
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Current,
|
|
PageSize: req.PageSize,
|
|
}, c)
|
|
}
|