package v1 import ( "git.getensh.com/common/gopkgs/logger" "git.getensh.com/common/gopkgs/tasker/httptasker" "git.getensh.com/common/gopkgs/util" "github.com/gin-gonic/gin" "go.uber.org/zap" "net/http" "property-system-gateway/errors" param_v1 "property-system-gateway/param/v1" "property-system-gateway/pb" "property-system-gateway/pb/v1" "property-system-gateway/utils" ) // // @Summary 添加分类 // @Description 添加分类 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.NeighborClassAddBody true "信息" // @Success 200 {object} v1.NeighborClassAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/class [post] func (c *Controller) NeighborClassAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborClassAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborClassAddBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborClassAddResponse{} rpcReq := &v1.NeighborClassAddRequest{ GardenId:tokenInfo.GardenId, ClassName:req.ClassName, Enable:req.Enable, ClassPic:req.ClassPic, } _, err = pb.Garden.NeighborClassAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborClassAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 修改分类 // @Description 修改分类 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.NeighborClassUpdateBody true "信息" // @Success 200 {object} v1.NeighborClassUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/class [put] func (c *Controller) NeighborClassUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborClassUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborClassUpdateBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborClassUpdateResponse{} rpcReq := &v1.NeighborClassUpdateRequest{ GardenId:tokenInfo.GardenId, ClassName:req.ClassName, Enable:req.Enable, Id:req.Id, ClassPic:req.ClassPic, } _, err = pb.Garden.NeighborClassUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborClassUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 删除分类 // @Description 删除分类 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param id query int true " " // @Success 200 {object} v1.NeighborClassDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/class [delete] func (c *Controller) NeighborClassDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborClassDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborClassDelQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborClassDelResponse{} rpcReq := &v1.NeighborClassDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } _, err = pb.Garden.NeighborClassDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborClassDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 分类列表 // @Description 分类列表 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param class_name query string false "分类名称 " // @Success 200 {object} v1.NeighborClassListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/class [get] func (c *Controller) NeighborClassList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborClassListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborClassListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborClassListResponse{} rpcReq := &v1.NeighborClassListRequest{ GardenId:tokenInfo.GardenId, PageSize:req.PageSize, Page:req.Page, ClassName:req.ClassName, } rpcRsp, err := pb.Garden.NeighborClassList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborClassList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.NeighborClassItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 删除文章 // @Description 删除文章 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param id query int true " " // @Success 200 {object} v1.NeighborArticleDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/article [delete] func (c *Controller) NeighborArticleDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborArticleDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleDelQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleDelResponse{} rpcReq := &v1.NeighborArticleDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, Admin:true, } _, err = pb.Garden.NeighborArticleDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborArticleDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 文章列表 // @Description 文章列表 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param title query string false "文章标题 " // @Param class_id query int false "分类id" // @Success 200 {object} v1.NeighborArticleListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/article [get] func (c *Controller) NeighborArticleList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborArticleListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleListResponse{} rpcReq := &v1.NeighborArticleListRequest{ GardenId:tokenInfo.GardenId, PageSize:req.PageSize, Page:req.Page, Title:req.Title, ClassId:req.ClassId, } rpcRsp, err := pb.Garden.NeighborArticleList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborArticleList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.NeighborArticleItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 删除评论 // @Description 删除评论 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param id query int true " " // @Success 200 {object} v1.NeighborCommentDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/comment [delete] func (c *Controller) NeighborCommentDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborCommentDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentDelQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentDelResponse{} rpcReq := &v1.NeighborCommentDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, Admin:true, } _, err = pb.Garden.NeighborCommentDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborCommentDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 评论列表 // @Description 评论列表 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param article_id query int false "文章id" // @Param comment_id query int false "父评论id" // @Success 200 {object} v1.NeighborCommentListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/comment [get] func (c *Controller) NeighborCommentList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborCommentListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentListResponse{} rpcReq := &v1.NeighborCommentListRequest{ GardenId:tokenInfo.GardenId, PageSize:req.PageSize, Page:req.Page, ArticleId:req.ArticleId, CommentId:req.CommentId, } rpcRsp, err := pb.Garden.NeighborCommentList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborCommentList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.NeighborCommentItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }