diff --git a/api/v1/plant/level_config.go b/api/v1/plant/level_config.go index 772807c..f22594d 100644 --- a/api/v1/plant/level_config.go +++ b/api/v1/plant/level_config.go @@ -15,7 +15,7 @@ type LevelConfigApi struct{} // @Tags 等级配置 // @Summary 添加等级配置 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateLevelConf true "添加等级配置" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" @@ -40,7 +40,7 @@ func (a *LevelConfigApi) AddLevelConfig(c *gin.Context) { // @Tags 等级配置 // @Summary 修改等级配置 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.UpdateLevelConf true "修改等级配置" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" diff --git a/api/v1/plant/my_plant.go b/api/v1/plant/my_plant.go index 93266c0..e9bf384 100644 --- a/api/v1/plant/my_plant.go +++ b/api/v1/plant/my_plant.go @@ -17,7 +17,7 @@ type MyPlantApi struct{} // @Tags 我的植物 // @Summary 添加植物 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateMyPlant true "创建植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" @@ -43,7 +43,7 @@ func (a *MyPlantApi) AddPlant(c *gin.Context) { // @Tags 我的植物 // @Summary 植物列表 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.PageInfo true "分页获取植物列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" @@ -92,7 +92,7 @@ func (a *MyPlantApi) PlantDetail(c *gin.Context) { // @Tags 我的植物 // @Summary 修改ById植物 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.UpdateMyPlant true "修改ById植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改ById成功"}" @@ -117,7 +117,7 @@ func (a *MyPlantApi) UpdatePlant(c *gin.Context) { // @Tags 我的植物 // @Summary 今日任务 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /plant/todayTask [get] @@ -138,7 +138,7 @@ func (a *MyPlantApi) TodayTask(c *gin.Context) { // @Tags 我的植物 // @Summary 完成任务 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CompleteTask true "完成任务" // @Success 200 {string} string "{"success":true,"data":{},"msg":"完成任务"}" @@ -163,7 +163,7 @@ func (a *MyPlantApi) CompleteTask(c *gin.Context) { // @Tags 我的植物 // @Summary 删除植物 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.IdsReq true "删除植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" @@ -187,7 +187,7 @@ func (a *MyPlantApi) DeletePlants(c *gin.Context) { // @Tags 我的植物 // @Summary 删除任务 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.IdsReq true "删除植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" @@ -211,7 +211,7 @@ func (a *MyPlantApi) DeletePlans(c *gin.Context) { // @Tags 我的植物 // @Summary 添加养护事项 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateCarePlan true "添加养护事项" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" @@ -255,7 +255,7 @@ func (a *MyPlantApi) DeletePlan(c *gin.Context) { // @Tags 我的植物 // @Summary 添加成长记录 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateGrowthRecord true "添加成长记录" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" diff --git a/api/v1/plant/ocr.go b/api/v1/plant/ocr.go index f46510b..478bfd9 100644 --- a/api/v1/plant/ocr.go +++ b/api/v1/plant/ocr.go @@ -42,7 +42,7 @@ func (o *OcrApi) ClassifyPlant(c *gin.Context) { // @tags 识别相关 // @Summary 我的植物识别记录 // @Security ApiKeyAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.PageInfo true "分页" // @Success 200 {object} response.Response{msg=string} "识别记录" diff --git a/api/v1/plant/post.go b/api/v1/plant/post.go index e5ef13d..2e5cc75 100644 --- a/api/v1/plant/post.go +++ b/api/v1/plant/post.go @@ -16,7 +16,7 @@ type PostApi struct{} // @Tags 帖子 // @Summary 发布帖子 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreatePost true "发布帖子" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}" @@ -43,7 +43,7 @@ func (a *PostApi) PublishPost(c *gin.Context) { // @Tags 帖子 // @Summary 帖子列表 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.PostPage true "分页获取帖子列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" @@ -74,7 +74,7 @@ func (a *PostApi) PostPage(c *gin.Context) { // @Tags 帖子 // @Summary 我的发布 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.PostPage true "分页获取帖子列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" @@ -127,7 +127,7 @@ func (a *PostApi) LikePost(c *gin.Context) { // @Tags 帖子 // @Summary 评论帖子 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateComment true "评论帖子" // @Success 200 {string} string "{"success":true,"data":{},"msg":"评论成功"}" diff --git a/api/v1/plant/topic.go b/api/v1/plant/topic.go index a83169b..dcd7e5f 100644 --- a/api/v1/plant/topic.go +++ b/api/v1/plant/topic.go @@ -16,7 +16,7 @@ type TopicApi struct{} // @Tags 帖子话题 // @Summary 发布话题 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateTopic true "发布话题" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}" @@ -40,7 +40,7 @@ func (a *TopicApi) AddTopic(c *gin.Context) { // @Tags 帖子话题 // @Summary 修改话题 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.UpdateTopic true "修改话题" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}" @@ -64,14 +64,15 @@ func (a *TopicApi) UpdateTopic(c *gin.Context) { // @Tags 帖子话题 // @Summary 话题分页 // @Security BearerAuth -// @accept json +// @accept application/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 { + err := c.ShouldBindJSON(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } diff --git a/api/v1/plant/user_profile.go b/api/v1/plant/user_profile.go index 4cf7090..aa4901d 100644 --- a/api/v1/plant/user_profile.go +++ b/api/v1/plant/user_profile.go @@ -14,7 +14,7 @@ type UserProfileApi struct{} // @Tags 个人中心 // @Summary 修改用户信息 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.UpdateProfile true "修改用户信息" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" diff --git a/api/v1/plant/wiki.go b/api/v1/plant/wiki.go index 370525b..f85ada2 100644 --- a/api/v1/plant/wiki.go +++ b/api/v1/plant/wiki.go @@ -22,11 +22,12 @@ type WikiApi struct{} // @Router /wiki/add [post] func (a *WikiApi) CreateWiki(c *gin.Context) { var req plantReq.CreateWiki - if err := c.ShouldBind(&req); err != nil { + err := c.ShouldBind(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } - err := wikiService.CreateWiki(req) + err = wikiService.CreateWiki(req) if err != nil { global.Logger.Error("添加百科失败", zap.Error(err)) response.FailWithMsg("添加百科失败", c) @@ -46,11 +47,12 @@ func (a *WikiApi) CreateWiki(c *gin.Context) { // @Router /wiki/update [post] func (a *WikiApi) UpdateWiki(c *gin.Context) { var req plantReq.UpdateWiki - if err := c.ShouldBind(&req); err != nil { + err := c.ShouldBind(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } - err := wikiService.UpdateWiki(req) + err = wikiService.UpdateWiki(req) if err != nil { global.Logger.Error("修改百科失败", zap.Error(err)) response.FailWithMsg("修改百科失败", c) @@ -71,7 +73,8 @@ func (a *WikiApi) UpdateWiki(c *gin.Context) { // @Router /wiki/page [post] func (a *WikiApi) WikiPage(c *gin.Context) { var req plantReq.WikiPage - if err := c.ShouldBind(&req); err != nil { + err := c.ShouldBind(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } diff --git a/api/v1/plant/wiki_class.go b/api/v1/plant/wiki_class.go index e7cfdaa..bce10e5 100644 --- a/api/v1/plant/wiki_class.go +++ b/api/v1/plant/wiki_class.go @@ -16,18 +16,19 @@ type WikiClassApi struct{} // @Tags 百科分类 // @Summary 添加分类 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.CreateWikiClass true "添加分类" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}" // @Router /wiki-class/add [post] func (a *WikiClassApi) AddClass(c *gin.Context) { var req plantReq.CreateWikiClass - if err := c.ShouldBindJSON(&req); err != nil { + err := c.ShouldBindJSON(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } - err := wikiClassService.AddClass(req) + err = wikiClassService.AddClass(req) if err != nil { global.Logger.Error("添加百科分类失败", zap.Error(err)) response.FailWithMsg("添加百科分类失败", c) @@ -40,18 +41,19 @@ func (a *WikiClassApi) AddClass(c *gin.Context) { // @Tags 百科分类 // @Summary 修改分类(可直接传入ossId修改图片) // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body plantReq.UpdateWikiClass true "修改分类" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}" // @Router /wiki-class/update [post] func (a *WikiClassApi) UpdateClass(c *gin.Context) { var req plantReq.UpdateWikiClass - if err := c.ShouldBindJSON(&req); err != nil { + err := c.ShouldBindJSON(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } - err := wikiClassService.UpdateClass(req) + err = wikiClassService.UpdateClass(req) if err != nil { global.Logger.Error("修改百科分类失败", zap.Error(err)) response.FailWithMsg("修改百科失败", c) @@ -64,14 +66,15 @@ func (a *WikiClassApi) UpdateClass(c *gin.Context) { // @Tags 百科分类 // @Summary 分类分页 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.PageInfo true "分页获取分类列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /wiki-class/page [post] func (a *WikiClassApi) ClassPage(c *gin.Context) { var req request.PageInfo - if err := c.ShouldBindQuery(&req); err != nil { + err := c.ShouldBindQuery(&req) + if err != nil { response.FailWithMsg("请求参数错误", c) return } @@ -93,7 +96,7 @@ func (a *WikiClassApi) ClassPage(c *gin.Context) { // @Tags 百科分类 // @Summary 删除分类 // @Security BearerAuth -// @accept json +// @accept application/json // @Produce application/json // @Param data body request.IdsReq true "删除分类" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" diff --git a/model/plant/community_post.go b/model/plant/community_post.go index 5fef4b6..226fcd8 100644 --- a/model/plant/community_post.go +++ b/model/plant/community_post.go @@ -15,7 +15,7 @@ type Post struct { CommentCount int `json:"commentCount" form:"commentCount" gorm:"default:0;column:comment_count;comment:评论次数"` LikeCount int `json:"likeCount" form:"likeCount" gorm:"default:0;column:like_count;comment:点赞次数"` Location string `json:"location" form:"location" gorm:"column:location;size:100;comment:位置"` - HasReviewed int `json:"hasReviewed" form:"hasReviewed" gorm:"column:has_reviewed;comment:是否审核通过"` + HasReviewed int `json:"hasReviewed" form:"hasReviewed" gorm:"column:has_reviewed;default:0;comment:是否审核通过"` HasLiked int `json:"hasLiked" form:"hasLiked" gorm:"-"` //图片 ImgList []*system.Oss `json:"imgList" form:"imgList" gorm:"many2many:post_oss;comment:图片列表"` diff --git a/model/plant/community_post_topic.go b/model/plant/community_post_topic.go index e9f0120..a41d41b 100644 --- a/model/plant/community_post_topic.go +++ b/model/plant/community_post_topic.go @@ -8,7 +8,7 @@ import ( type Topic struct { global.BaseModel Title string `json:"title"` - StartTime time.Time `json:"start_time" gorm:"column:start_time;"` - EndTime time.Time `json:"end_time" gorm:"column:end_time;"` + StartTime time.Time `json:"startTime" gorm:"type:date;column:start_time;"` + EndTime time.Time `json:"endTime" gorm:"type:date;column:end_time;"` Remark string `json:"remark"` } diff --git a/model/plant/request/post.go b/model/plant/request/post.go index aa23c63..c187979 100644 --- a/model/plant/request/post.go +++ b/model/plant/request/post.go @@ -22,7 +22,7 @@ type UpdatePost struct { type PostPage struct { common.PageInfo Title string `json:"title"` // 标题 - HasReviewed int `json:"hasReviewed"` //是否审核通过 + HasReviewed *int `json:"hasReviewed"` //是否审核通过 } // CreateComment 创建评论 diff --git a/model/plant/request/topic.go b/model/plant/request/topic.go index 0d601ef..38fab88 100644 --- a/model/plant/request/topic.go +++ b/model/plant/request/topic.go @@ -2,15 +2,15 @@ package request type CreateTopic struct { Title string `json:"title"` - StartTime string `json:"start_time"` - EndTime string `json:"end_time"` + StartTime string `json:"startTime"` + EndTime string `json:"endTime"` Remark string `json:"remark"` } type UpdateTopic struct { Id int `json:"id" binding:"required"` Title string `json:"title"` - StartTime string `json:"start_time"` - EndTime string `json:"end_time"` + StartTime string `json:"startTime"` + EndTime string `json:"endTime"` Remark string `json:"remark"` } diff --git a/service/plant/post.go b/service/plant/post.go index 73a653a..45669c9 100644 --- a/service/plant/post.go +++ b/service/plant/post.go @@ -76,6 +76,9 @@ func (s *PostService) PostPage(req plantReq.PostPage, userId string) (list inter if req.Title != "" { db = db.Where("title like ?", "%"+req.Title+"%") } + if req.HasReviewed != nil { + db = db.Where("has_reviewed = ?", *req.HasReviewed) + } //todo 审核帖子 err = db.Count(&total).Error if err != nil { diff --git a/service/plant/topic.go b/service/plant/topic.go index 2029e17..495dd6e 100644 --- a/service/plant/topic.go +++ b/service/plant/topic.go @@ -50,7 +50,7 @@ func (s *TopicService) TopicPage(req common.PageInfo) (list interface{}, total i limit := req.PageSize offset := req.PageSize * (req.Current - 1) db := global.DB.Model(&plant.Topic{}) - var topics []*plant.Topic + var topics []plant.Topic err = db.Count(&total).Error if err != nil { return