package plant import ( "github.com/gin-gonic/gin" "go.uber.org/zap" "sundynix-go/global" "sundynix-go/model/commom/request" "sundynix-go/model/commom/response" plantReq "sundynix-go/model/plant/request" "sundynix-go/utils/auth" ) type MyPlantApi struct{} // AddPlant 添加植物 // @Tags 我的植物 // @Summary 添加植物 // @Security ApiKeyAuth // @accept json // @Produce application/json // @Param data body plantReq.CreateMyPlant true "创建植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" // @Router /plant/add [post] func (a *MyPlantApi) AddPlant(c *gin.Context) { var req plantReq.CreateMyPlant err := c.ShouldBindJSON(&req) if err != nil { response.FailWithMsg("请求参数错误", c) return } userId := auth.GetUserId(c) err = plantService.AddPlant(req, userId) if err != nil { global.Logger.Error("添加植物失败", zap.Error(err)) response.FailWithMsg("添加失败", c) return } response.OkWithMsg("添加成功", c) } // PlantPage 植物列表 // @Tags 我的植物 // @Summary 植物列表 // @Security ApiKeyAuth // @accept json // @Produce application/json // @Param data body request.PageInfo true "分页获取植物列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /plant/page [post] func (a *MyPlantApi) PlantPage(c *gin.Context) { var req request.PageInfo err := c.ShouldBindJSON(&req) if err != nil { response.FailWithMsg("请求参数错误", c) } userId := auth.GetUserId(c) list, total, err := plantService.PlantPage(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) } // PlantDetail 植物详情 // @Tags 我的植物 // @Summary ById植物详情 // @Security ApiKeyAuth // @Produce application/json // @Param id query string true "id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取ById成功"}" // @Router /plant/detail [get] func (a *MyPlantApi) PlantDetail(c *gin.Context) { id := c.Query("id") plant, err := plantService.PlantDetail(id) if err != nil { response.FailWithMsg("获取失败", c) return } response.OkWithData(plant, c) } // UpdatePlant 修改植物 // @Tags 我的植物 // @Summary 修改ById植物 // @Security ApiKeyAuth // @accept json // @Produce application/json // @Param data body plantReq.UpdateMyPlant true "修改ById植物" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改ById成功"}" // @Router /plant/update [post] func (a *MyPlantApi) UpdatePlant(c *gin.Context) { var req plantReq.UpdateMyPlant err := c.ShouldBindJSON(&req) if err != nil { response.FailWithMsg("请求参数错误", c) return } err = plantService.UpdatePlant(req) if err != nil { global.Logger.Error("更新植物失败", zap.Error(err)) response.FailWithMsg("更新植物失败", c) return } response.OkWithMsg("更新植物成功", c) } // TodayTask 今日任务 // @Tags 我的植物 // @Summary 今日任务 // @Security ApiKeyAuth // @accept json // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /plant/todayTask [get] func (a *MyPlantApi) TodayTask(c *gin.Context) { userId := auth.GetUserId(c) list, err := plantService.TodayTask(userId) if err != nil { global.Logger.Error("获取今日任务失败", zap.Error(err)) response.FailWithMsg("获取今日任务失败", c) return } response.OkWithData(response.ListResult{ List: list, }, c) } // CompleteTask plantReq.CompleteMyPlant // @Tags 我的植物 // @Summary 完成任务 // @Security ApiKeyAuth // @accept json // @Produce application/json // @Param data body plantReq.CompleteTask true "完成任务" // @Success 200 {string} string "{"success":true,"data":{},"msg":"完成任务"}" // @Router /plant/completeTask [post] func (a *MyPlantApi) CompleteTask(c *gin.Context) { var req plantReq.CompleteTask err := c.ShouldBindJSON(&req) if err != nil { response.FailWithMsg("请求参数错误", c) return } err = plantService.CompleteTask(req) if err != nil { global.Logger.Error("完成任务失败", zap.Error(err)) response.FailWithMsg("完成任务失败", c) return } response.OkWithMsg("完成任务成功", c) }