refactor: 1.修正api auth 2.帖子话题业务
This commit is contained in:
@@ -4,10 +4,12 @@ import "sundynix-go/service"
|
||||
|
||||
type ApiGroup struct {
|
||||
MyPlantApi
|
||||
TopicApi
|
||||
PostApi
|
||||
}
|
||||
|
||||
var (
|
||||
plantService = service.GroupApp.PlantServiceGroup.MyPlantService
|
||||
topicService = service.GroupApp.PlantServiceGroup.TopicService
|
||||
postService = service.GroupApp.PlantServiceGroup.PostService
|
||||
)
|
||||
|
||||
+10
-10
@@ -16,7 +16,7 @@ type MyPlantApi struct{}
|
||||
// AddPlant 添加植物
|
||||
// @Tags 我的植物
|
||||
// @Summary 添加植物
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.CreateMyPlant true "创建植物"
|
||||
@@ -42,7 +42,7 @@ func (a *MyPlantApi) AddPlant(c *gin.Context) {
|
||||
// PlantPage 植物列表
|
||||
// @Tags 我的植物
|
||||
// @Summary 植物列表
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取植物列表"
|
||||
@@ -72,7 +72,7 @@ func (a *MyPlantApi) PlantPage(c *gin.Context) {
|
||||
// PlantDetail 植物详情
|
||||
// @Tags 我的植物
|
||||
// @Summary ById植物详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取ById成功"}"
|
||||
@@ -91,7 +91,7 @@ func (a *MyPlantApi) PlantDetail(c *gin.Context) {
|
||||
// UpdatePlant 修改植物
|
||||
// @Tags 我的植物
|
||||
// @Summary 修改ById植物
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.UpdateMyPlant true "修改ById植物"
|
||||
@@ -116,7 +116,7 @@ func (a *MyPlantApi) UpdatePlant(c *gin.Context) {
|
||||
// TodayTask 今日任务
|
||||
// @Tags 我的植物
|
||||
// @Summary 今日任务
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
@@ -137,7 +137,7 @@ func (a *MyPlantApi) TodayTask(c *gin.Context) {
|
||||
// CompleteTask plantReq.CompleteMyPlant
|
||||
// @Tags 我的植物
|
||||
// @Summary 完成任务
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.CompleteTask true "完成任务"
|
||||
@@ -162,12 +162,12 @@ func (a *MyPlantApi) CompleteTask(c *gin.Context) {
|
||||
// DeletePlants
|
||||
// @Tags 我的植物
|
||||
// @Summary 删除植物
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "删除植物"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /plant/delete/ [post]
|
||||
// @Router /plant/deletePlant [post]
|
||||
func (a *MyPlantApi) DeletePlants(c *gin.Context) {
|
||||
var req request.IdsReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
@@ -186,12 +186,12 @@ func (a *MyPlantApi) DeletePlants(c *gin.Context) {
|
||||
// DeletePlans DeletePlants
|
||||
// @Tags 我的植物
|
||||
// @Summary 删除任务
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "删除植物"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /plant/deletePlant [post]
|
||||
// @Router /plant/deletePlan [post]
|
||||
func (a *MyPlantApi) DeletePlans(c *gin.Context) {
|
||||
var req request.IdsReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
|
||||
@@ -15,7 +15,7 @@ type PostApi struct{}
|
||||
// PublishPost 发布帖子
|
||||
// @Tags 帖子
|
||||
// @Summary 发布帖子
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.CreatePost true "发布帖子"
|
||||
@@ -42,7 +42,7 @@ func (a *PostApi) PublishPost(c *gin.Context) {
|
||||
// PostPage 帖子列表
|
||||
// @Tags 帖子
|
||||
// @Summary 帖子列表
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.PostPage true "分页获取帖子列表"
|
||||
@@ -73,7 +73,7 @@ func (a *PostApi) PostPage(c *gin.Context) {
|
||||
// LikePost 点赞帖子
|
||||
// @Tags 帖子
|
||||
// @Summary 点赞帖子
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "帖子id"
|
||||
// @Param type query string true "点赞类型 1 点赞 2 取消点赞"
|
||||
@@ -95,7 +95,7 @@ func (a *PostApi) LikePost(c *gin.Context) {
|
||||
// CommentPost 评论帖子
|
||||
// @Tags 帖子
|
||||
// @Summary 评论帖子
|
||||
// @Security ApiKeyAuth
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.CreateComment true "评论帖子"
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
plantReq "sundynix-go/model/plant/request"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type TopicApi struct{}
|
||||
|
||||
// AddTopic 发布话题
|
||||
// @Tags 帖子话题
|
||||
// @Summary 发布话题
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.CreateTopic true "发布话题"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
|
||||
// @Router /topic/add [post]
|
||||
func (a *TopicApi) AddTopic(c *gin.Context) {
|
||||
var req plantReq.CreateTopic
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMsg("请求参数错误", c)
|
||||
return
|
||||
}
|
||||
err := topicService.AddTopic(req)
|
||||
if err != nil {
|
||||
global.Logger.Error("添加话题失败", zap.Error(err))
|
||||
response.FailWithMsg("添加话题失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("添加话题成功", c)
|
||||
}
|
||||
|
||||
// UpdateTopic
|
||||
// @Tags 帖子话题
|
||||
// @Summary 修改话题
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body plantReq.UpdateTopic true "修改话题"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
|
||||
// @Router /topic/add [post]
|
||||
func (a *TopicApi) UpdateTopic(c *gin.Context) {
|
||||
var req plantReq.UpdateTopic
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMsg("请求参数错误", c)
|
||||
return
|
||||
}
|
||||
err := topicService.UpdateTopic(req)
|
||||
if err != nil {
|
||||
global.Logger.Error("修改话题失败", zap.Error(err))
|
||||
response.FailWithMsg("修改话题失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("修改话题成功", c)
|
||||
}
|
||||
|
||||
// TopicPage 话题列表
|
||||
// @Tags 帖子话题
|
||||
// @Summary 话题分页
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.PageInfo true "分页获取话题列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /topic/page [post]
|
||||
func (a *TopicApi) TopicPage(c *gin.Context) {
|
||||
var req request.PageInfo
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.FailWithMsg("请求参数错误", c)
|
||||
return
|
||||
}
|
||||
list, total, err := topicService.TopicPage(req)
|
||||
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)
|
||||
}
|
||||
|
||||
// TopicList 话题列表
|
||||
// @Tags 帖子话题
|
||||
// @Summary 话题列表
|
||||
// @Security BearerAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /topic/list [get]
|
||||
func (a *TopicApi) TopicList(c *gin.Context) {
|
||||
list, err := topicService.TopicList()
|
||||
if err != nil {
|
||||
global.Logger.Error("获取话题列表失败", zap.Error(err))
|
||||
response.FailWithMsg("获取话题列表失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.ListResult{
|
||||
List: list,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// TopicDetail 话题详情
|
||||
// @Tags 帖子话题
|
||||
// @Summary 话题详情
|
||||
// @Security BearerAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /topic/detail [get]
|
||||
func (a *TopicApi) TopicDetail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
topic, err := topicService.Detail(id)
|
||||
if err != nil {
|
||||
response.FailWithMsg("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(topic, c)
|
||||
|
||||
}
|
||||
|
||||
// DeleteTopic 删除植物
|
||||
// @Tags 帖子话题
|
||||
// @Summary 删除任务
|
||||
// @Security BearerAuth
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "删除话题"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /topic/delete [post]
|
||||
func (a *TopicApi) DeleteTopic(c *gin.Context) {
|
||||
var req request.IdsReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("请求参数错误", c)
|
||||
return
|
||||
}
|
||||
err = topicService.DeleteTopics(req)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除话题失败", zap.Error(err))
|
||||
response.FailWithMsg("删除话题失败", c)
|
||||
}
|
||||
response.OkWithMsg("删除话题成功", c)
|
||||
}
|
||||
Reference in New Issue
Block a user