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-household-gateway/errors" param_v1 "property-household-gateway/param/v1" "property-household-gateway/pb" "property-household-gateway/pb/v1" "property-household-gateway/utils" ) // // @Summary 分类列表 // @Description 分类列表 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param garden_id query int true "小区id" // @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.GetJwtTokenInfo(ctx) if err != nil { return err }*/ // 响应数据 resp := param_v1.NeighborClassListResponse{} rpcReq := &v1.NeighborClassListRequest{ GardenId: req.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 body body v1.NeighborArticleAddBody true "信息" // @Success 200 {object} v1.NeighborArticleAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/article [post] func (c *Controller) NeighborArticleAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborArticleAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborArticleAddBody) 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleAddResponse{} rpcReq := &v1.NeighborArticleAddRequest{ GardenId: req.GardenId, Uid: tokenInfo.Uid, UserIcon: tokenInfo.UserIcon, Title: req.Title, Content: req.Content, Pics: req.Pics, ClassId: req.ClassId, NickName: tokenInfo.NickName, } _, err = pb.Garden.NeighborArticleAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborArticleAdd"), 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.NeighborArticleUpdateBody true "信息" // @Success 200 {object} v1.NeighborArticleUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/article [put] func (c *Controller) NeighborArticleUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborArticleUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborArticleUpdateBody) 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleUpdateResponse{} rpcReq := &v1.NeighborArticleUpdateRequest{ GardenId: req.GardenId, Title: req.Title, Content: req.Content, Pics: req.Pics, Id: req.Id, Uid: tokenInfo.Uid, } _, err = pb.Garden.NeighborArticleUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborArticleUpdate"), 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 garden_id query int true "小区id" // @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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleDelResponse{} rpcReq := &v1.NeighborArticleDelRequest{ GardenId: req.GardenId, Id: req.Id, Admin: false, Uid: tokenInfo.Uid, } _, 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 garden_id query int true "小区id" // @Param page query int false " " // @Param page_size query int false " " // @Param title query string false "文章标题 " // @Param is_me query bool false "true我发布的 false 不过滤 " // @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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborArticleListResponse{} rpcReq := &v1.NeighborArticleListRequest{ GardenId: req.GardenId, PageSize: req.PageSize, Page: req.Page, Title: req.Title, Uid: tokenInfo.Uid, IsMe: req.IsMe, } 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 body body v1.NeighborCommentAddBody true "信息" // @Success 200 {object} v1.NeighborCommentAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/comment [post] func (c *Controller) NeighborCommentAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborCommentAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborCommentAddBody) 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentAddResponse{} rpcReq := &v1.NeighborCommentAddRequest{ GardenId: req.GardenId, Uid: tokenInfo.Uid, UserIcon: tokenInfo.UserIcon, Content: req.Content, Pics: req.Pics, Pid: req.Pid, ArticleId: req.ArticleId, NickName: tokenInfo.NickName, } _, err = pb.Garden.NeighborCommentAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborCommentAdd"), 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.NeighborCommentUpdateBody true "信息" // @Success 200 {object} v1.NeighborCommentUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/comment [put] func (c *Controller) NeighborCommentUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborCommentUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborCommentUpdateBody) 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentUpdateResponse{} rpcReq := &v1.NeighborCommentUpdateRequest{ GardenId: req.GardenId, Content: req.Content, Pics: req.Pics, Id: req.Id, Uid: tokenInfo.Uid, } _, err = pb.Garden.NeighborCommentUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborCommentUpdate"), 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 garden_id query int true "小区id" // @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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentDelResponse{} rpcReq := &v1.NeighborCommentDelRequest{ GardenId: req.GardenId, Id: req.Id, Admin: false, Uid: tokenInfo.Uid, } _, 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 garden_id query int true "小区id" // @Param page query int false " " // @Param page_size query int false " " // @Param article_id query int true "文章id" // @Param pid 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborCommentListResponse{} rpcReq := &v1.NeighborCommentListRequest{ GardenId: req.GardenId, PageSize: req.PageSize, Page: req.Page, Uid: tokenInfo.Uid, ArticleId: req.ArticleId, CommentId: req.Pid, } 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) } // // @Summary 点赞或撤销点赞 // @Description 点赞或撤销点赞 // @Tags 社区邻里 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.NeighborLikeBody true "信息" // @Success 200 {object} v1.NeighborLikeResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/neighbor/like [put] func (c *Controller) NeighborLike(ctx *gin.Context) { // 解析参数 req := ¶m_v1.NeighborLikeRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborLikeBody) 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.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.NeighborLikeResponse{} rpcReq := &v1.NeighborLikeRequest{ GardenId: req.GardenId, LikeType: req.LikeType, LikeId: req.LikeId, Uid: tokenInfo.Uid, Like: req.Like, } _, err = pb.Garden.NeighborLike(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.NeighborLike"), 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) }