neighbor.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-applete-gateway/errors"
  10. param_v1 "property-applete-gateway/param/v1"
  11. "property-applete-gateway/pb"
  12. "property-applete-gateway/pb/v1"
  13. "property-applete-gateway/utils"
  14. )
  15. //
  16. // @Summary 添加分类
  17. // @Description 添加分类
  18. // @Tags 社区邻里
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.NeighborClassAddBody true "信息"
  23. // @Success 200 {object} v1.NeighborClassAddResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/service/neighbor/class [post]
  26. func (c *Controller) NeighborClassAdd(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.NeighborClassAddRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborClassAddBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetSubjectValue(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.NeighborClassAddResponse{}
  47. rpcReq := &v1.NeighborClassAddRequest{
  48. GardenId:tokenInfo.GardenId,
  49. ClassName:req.ClassName,
  50. Enable:req.Enable,
  51. ClassPic:req.ClassPic,
  52. }
  53. _, err = pb.Garden.NeighborClassAdd(ctx, rpcReq)
  54. if err != nil {
  55. s, _ := json.MarshalToString(req)
  56. logger.Error("func",
  57. zap.String("call", "pb.Garden.NeighborClassAdd"),
  58. zap.String("params", s),
  59. zap.String("error", err.Error()))
  60. return errors.ErrorTransForm(err)
  61. }
  62. ctx.JSON(http.StatusOK, resp)
  63. return nil
  64. }
  65. // 执行任务
  66. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  67. }
  68. //
  69. // @Summary 修改分类
  70. // @Description 修改分类
  71. // @Tags 社区邻里
  72. // @Accept json
  73. // @Produce json
  74. // @Param token header string true "token"
  75. // @Param body body v1.NeighborClassUpdateBody true "信息"
  76. // @Success 200 {object} v1.NeighborClassUpdateResponse
  77. // @Failure 500 {object} base.HTTPError
  78. // @Router /api/v1/service/neighbor/class [put]
  79. func (c *Controller) NeighborClassUpdate(ctx *gin.Context) {
  80. // 解析参数
  81. req := &param_v1.NeighborClassUpdateRequest{}
  82. parseParamTask := func() error {
  83. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborClassUpdateBody)
  84. if err != nil {
  85. logger.Error("func",
  86. zap.String("call", "util.ShouldBind"),
  87. zap.String("error", err.Error()))
  88. return errors.ParamsError
  89. }
  90. return nil
  91. }
  92. // 业务处理
  93. handleServiceTask := func() error {
  94. tokenInfo, err := utils.GetSubjectValue(ctx)
  95. if err != nil {
  96. return err
  97. }
  98. // 响应数据
  99. resp := param_v1.NeighborClassUpdateResponse{}
  100. rpcReq := &v1.NeighborClassUpdateRequest{
  101. GardenId:tokenInfo.GardenId,
  102. ClassName:req.ClassName,
  103. Enable:req.Enable,
  104. Id:req.Id,
  105. ClassPic:req.ClassPic,
  106. }
  107. _, err = pb.Garden.NeighborClassUpdate(ctx, rpcReq)
  108. if err != nil {
  109. s, _ := json.MarshalToString(req)
  110. logger.Error("func",
  111. zap.String("call", "pb.Garden.NeighborClassUpdate"),
  112. zap.String("params", s),
  113. zap.String("error", err.Error()))
  114. return errors.ErrorTransForm(err)
  115. }
  116. ctx.JSON(http.StatusOK, resp)
  117. return nil
  118. }
  119. // 执行任务
  120. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  121. }
  122. //
  123. // @Summary 删除分类
  124. // @Description 删除分类
  125. // @Tags 社区邻里
  126. // @Accept json
  127. // @Produce json
  128. // @Param token header string true "token"
  129. // @Param id query int true " "
  130. // @Success 200 {object} v1.NeighborClassDelResponse
  131. // @Failure 500 {object} base.HTTPError
  132. // @Router /api/v1/service/neighbor/class [delete]
  133. func (c *Controller) NeighborClassDel(ctx *gin.Context) {
  134. // 解析参数
  135. req := &param_v1.NeighborClassDelRequest{}
  136. parseParamTask := func() error {
  137. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborClassDelQuery, nil)
  138. if err != nil {
  139. logger.Error("func",
  140. zap.String("call", "util.ShouldBind"),
  141. zap.String("error", err.Error()))
  142. return errors.ParamsError
  143. }
  144. return nil
  145. }
  146. // 业务处理
  147. handleServiceTask := func() error {
  148. tokenInfo, err := utils.GetSubjectValue(ctx)
  149. if err != nil {
  150. return err
  151. }
  152. // 响应数据
  153. resp := param_v1.NeighborClassDelResponse{}
  154. rpcReq := &v1.NeighborClassDelRequest{
  155. GardenId:tokenInfo.GardenId,
  156. Id:req.Id,
  157. }
  158. _, err = pb.Garden.NeighborClassDel(ctx, rpcReq)
  159. if err != nil {
  160. s, _ := json.MarshalToString(req)
  161. logger.Error("func",
  162. zap.String("call", "pb.Garden.NeighborClassDel"),
  163. zap.String("params", s),
  164. zap.String("error", err.Error()))
  165. return errors.ErrorTransForm(err)
  166. }
  167. ctx.JSON(http.StatusOK, resp)
  168. return nil
  169. }
  170. // 执行任务
  171. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  172. }
  173. //
  174. // @Summary 分类列表
  175. // @Description 分类列表
  176. // @Tags 社区邻里
  177. // @Accept json
  178. // @Produce json
  179. // @Param token header string true "token"
  180. // @Param page query int false " "
  181. // @Param page_size query int false " "
  182. // @Param class_name query string false "分类名称 "
  183. // @Success 200 {object} v1.NeighborClassListResponse
  184. // @Failure 500 {object} base.HTTPError
  185. // @Router /api/v1/service/neighbor/class [get]
  186. func (c *Controller) NeighborClassList(ctx *gin.Context) {
  187. // 解析参数
  188. req := &param_v1.NeighborClassListRequest{}
  189. parseParamTask := func() error {
  190. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborClassListQuery, nil)
  191. if err != nil {
  192. logger.Error("func",
  193. zap.String("call", "util.ShouldBind"),
  194. zap.String("error", err.Error()))
  195. return errors.ParamsError
  196. }
  197. return nil
  198. }
  199. // 业务处理
  200. handleServiceTask := func() error {
  201. tokenInfo, err := utils.GetSubjectValue(ctx)
  202. if err != nil {
  203. return err
  204. }
  205. // 响应数据
  206. resp := param_v1.NeighborClassListResponse{}
  207. rpcReq := &v1.NeighborClassListRequest{
  208. GardenId:tokenInfo.GardenId,
  209. PageSize:req.PageSize,
  210. Page:req.Page,
  211. ClassName:req.ClassName,
  212. }
  213. rpcRsp, err := pb.Garden.NeighborClassList(ctx, rpcReq)
  214. if err != nil {
  215. s, _ := json.MarshalToString(req)
  216. logger.Error("func",
  217. zap.String("call", "pb.Garden.NeighborClassList"),
  218. zap.String("params", s),
  219. zap.String("error", err.Error()))
  220. return errors.ErrorTransForm(err)
  221. }
  222. if rpcRsp.List == nil {
  223. rpcRsp.List = make([]*v1.NeighborClassItem, 0)
  224. }
  225. resp.Data = *rpcRsp
  226. ctx.JSON(http.StatusOK, resp)
  227. return nil
  228. }
  229. // 执行任务
  230. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  231. }
  232. //
  233. // @Summary 删除文章
  234. // @Description 删除文章
  235. // @Tags 社区邻里
  236. // @Accept json
  237. // @Produce json
  238. // @Param token header string true "token"
  239. // @Param id query int true " "
  240. // @Success 200 {object} v1.NeighborArticleDelResponse
  241. // @Failure 500 {object} base.HTTPError
  242. // @Router /api/v1/service/neighbor/article [delete]
  243. func (c *Controller) NeighborArticleDel(ctx *gin.Context) {
  244. // 解析参数
  245. req := &param_v1.NeighborArticleDelRequest{}
  246. parseParamTask := func() error {
  247. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleDelQuery, nil)
  248. if err != nil {
  249. logger.Error("func",
  250. zap.String("call", "util.ShouldBind"),
  251. zap.String("error", err.Error()))
  252. return errors.ParamsError
  253. }
  254. return nil
  255. }
  256. // 业务处理
  257. handleServiceTask := func() error {
  258. tokenInfo, err := utils.GetSubjectValue(ctx)
  259. if err != nil {
  260. return err
  261. }
  262. // 响应数据
  263. resp := param_v1.NeighborArticleDelResponse{}
  264. rpcReq := &v1.NeighborArticleDelRequest{
  265. GardenId:tokenInfo.GardenId,
  266. Id:req.Id,
  267. Admin:true,
  268. }
  269. _, err = pb.Garden.NeighborArticleDel(ctx, rpcReq)
  270. if err != nil {
  271. s, _ := json.MarshalToString(req)
  272. logger.Error("func",
  273. zap.String("call", "pb.Garden.NeighborArticleDel"),
  274. zap.String("params", s),
  275. zap.String("error", err.Error()))
  276. return errors.ErrorTransForm(err)
  277. }
  278. ctx.JSON(http.StatusOK, resp)
  279. return nil
  280. }
  281. // 执行任务
  282. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  283. }
  284. //
  285. // @Summary 文章列表
  286. // @Description 文章列表
  287. // @Tags 社区邻里
  288. // @Accept json
  289. // @Produce json
  290. // @Param token header string true "token"
  291. // @Param page query int false " "
  292. // @Param page_size query int false " "
  293. // @Param title query string false "文章标题 "
  294. // @Param class_id query int false "分类id"
  295. // @Success 200 {object} v1.NeighborArticleListResponse
  296. // @Failure 500 {object} base.HTTPError
  297. // @Router /api/v1/service/neighbor/article [get]
  298. func (c *Controller) NeighborArticleList(ctx *gin.Context) {
  299. // 解析参数
  300. req := &param_v1.NeighborArticleListRequest{}
  301. parseParamTask := func() error {
  302. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleListQuery, nil)
  303. if err != nil {
  304. logger.Error("func",
  305. zap.String("call", "util.ShouldBind"),
  306. zap.String("error", err.Error()))
  307. return errors.ParamsError
  308. }
  309. return nil
  310. }
  311. // 业务处理
  312. handleServiceTask := func() error {
  313. tokenInfo, err := utils.GetSubjectValue(ctx)
  314. if err != nil {
  315. return err
  316. }
  317. // 响应数据
  318. resp := param_v1.NeighborArticleListResponse{}
  319. rpcReq := &v1.NeighborArticleListRequest{
  320. GardenId:tokenInfo.GardenId,
  321. PageSize:req.PageSize,
  322. Page:req.Page,
  323. Title:req.Title,
  324. ClassId:req.ClassId,
  325. }
  326. rpcRsp, err := pb.Garden.NeighborArticleList(ctx, rpcReq)
  327. if err != nil {
  328. s, _ := json.MarshalToString(req)
  329. logger.Error("func",
  330. zap.String("call", "pb.Garden.NeighborArticleList"),
  331. zap.String("params", s),
  332. zap.String("error", err.Error()))
  333. return errors.ErrorTransForm(err)
  334. }
  335. if rpcRsp.List == nil {
  336. rpcRsp.List = make([]*v1.NeighborArticleItem, 0)
  337. }
  338. resp.Data = *rpcRsp
  339. ctx.JSON(http.StatusOK, resp)
  340. return nil
  341. }
  342. // 执行任务
  343. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  344. }
  345. //
  346. // @Summary 删除评论
  347. // @Description 删除评论
  348. // @Tags 社区邻里
  349. // @Accept json
  350. // @Produce json
  351. // @Param token header string true "token"
  352. // @Param id query int true " "
  353. // @Success 200 {object} v1.NeighborCommentDelResponse
  354. // @Failure 500 {object} base.HTTPError
  355. // @Router /api/v1/service/neighbor/comment [delete]
  356. func (c *Controller) NeighborCommentDel(ctx *gin.Context) {
  357. // 解析参数
  358. req := &param_v1.NeighborCommentDelRequest{}
  359. parseParamTask := func() error {
  360. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentDelQuery, nil)
  361. if err != nil {
  362. logger.Error("func",
  363. zap.String("call", "util.ShouldBind"),
  364. zap.String("error", err.Error()))
  365. return errors.ParamsError
  366. }
  367. return nil
  368. }
  369. // 业务处理
  370. handleServiceTask := func() error {
  371. tokenInfo, err := utils.GetSubjectValue(ctx)
  372. if err != nil {
  373. return err
  374. }
  375. // 响应数据
  376. resp := param_v1.NeighborCommentDelResponse{}
  377. rpcReq := &v1.NeighborCommentDelRequest{
  378. GardenId:tokenInfo.GardenId,
  379. Id:req.Id,
  380. Admin:true,
  381. }
  382. _, err = pb.Garden.NeighborCommentDel(ctx, rpcReq)
  383. if err != nil {
  384. s, _ := json.MarshalToString(req)
  385. logger.Error("func",
  386. zap.String("call", "pb.Garden.NeighborCommentDel"),
  387. zap.String("params", s),
  388. zap.String("error", err.Error()))
  389. return errors.ErrorTransForm(err)
  390. }
  391. ctx.JSON(http.StatusOK, resp)
  392. return nil
  393. }
  394. // 执行任务
  395. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  396. }
  397. //
  398. // @Summary 评论列表
  399. // @Description 评论列表
  400. // @Tags 社区邻里
  401. // @Accept json
  402. // @Produce json
  403. // @Param token header string true "token"
  404. // @Param page query int false " "
  405. // @Param page_size query int false " "
  406. // @Success 200 {object} v1.NeighborCommentListResponse
  407. // @Failure 500 {object} base.HTTPError
  408. // @Router /api/v1/service/neighbor/comment [get]
  409. func (c *Controller) NeighborCommentList(ctx *gin.Context) {
  410. // 解析参数
  411. req := &param_v1.NeighborCommentListRequest{}
  412. parseParamTask := func() error {
  413. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentListQuery, nil)
  414. if err != nil {
  415. logger.Error("func",
  416. zap.String("call", "util.ShouldBind"),
  417. zap.String("error", err.Error()))
  418. return errors.ParamsError
  419. }
  420. return nil
  421. }
  422. // 业务处理
  423. handleServiceTask := func() error {
  424. tokenInfo, err := utils.GetSubjectValue(ctx)
  425. if err != nil {
  426. return err
  427. }
  428. // 响应数据
  429. resp := param_v1.NeighborCommentListResponse{}
  430. rpcReq := &v1.NeighborCommentListRequest{
  431. GardenId:tokenInfo.GardenId,
  432. PageSize:req.PageSize,
  433. Page:req.Page,
  434. ArticleId:req.ArticleId,
  435. CommentId:req.CommentId,
  436. }
  437. rpcRsp, err := pb.Garden.NeighborCommentList(ctx, rpcReq)
  438. if err != nil {
  439. s, _ := json.MarshalToString(req)
  440. logger.Error("func",
  441. zap.String("call", "pb.Garden.NeighborCommentList"),
  442. zap.String("params", s),
  443. zap.String("error", err.Error()))
  444. return errors.ErrorTransForm(err)
  445. }
  446. if rpcRsp.List == nil {
  447. rpcRsp.List = make([]*v1.NeighborCommentItem, 0)
  448. }
  449. resp.Data = *rpcRsp
  450. ctx.JSON(http.StatusOK, resp)
  451. return nil
  452. }
  453. // 执行任务
  454. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  455. }