neighbor.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. "property-household-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 garden_id query int true "小区id"
  23. // @Param page query int false " "
  24. // @Param page_size query int false " "
  25. // @Param class_name query string false "分类名称"
  26. // @Success 200 {object} v1.NeighborClassListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/service/neighbor/class [get]
  29. func (c *Controller) NeighborClassList(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.NeighborClassListRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborClassListQuery, nil)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. return nil
  41. }
  42. // 业务处理
  43. handleServiceTask := func() error {
  44. /*
  45. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  46. if err != nil {
  47. return err
  48. }*/
  49. // 响应数据
  50. resp := param_v1.NeighborClassListResponse{}
  51. rpcReq := &v1.NeighborClassListRequest{
  52. GardenId: req.GardenId,
  53. PageSize: req.PageSize,
  54. Page: req.Page,
  55. ClassName: req.ClassName,
  56. }
  57. rpcRsp, err := pb.Garden.NeighborClassList(ctx, rpcReq)
  58. if err != nil {
  59. s, _ := json.MarshalToString(req)
  60. logger.Error("func",
  61. zap.String("call", "pb.Garden.NeighborClassList"),
  62. zap.String("params", s),
  63. zap.String("error", err.Error()))
  64. return errors.ErrorTransForm(err)
  65. }
  66. if rpcRsp.List == nil {
  67. rpcRsp.List = make([]*v1.NeighborClassItem, 0)
  68. }
  69. resp.Data = *rpcRsp
  70. ctx.JSON(http.StatusOK, resp)
  71. return nil
  72. }
  73. // 执行任务
  74. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  75. }
  76. //
  77. // @Summary 添加文章
  78. // @Description 添加文章
  79. // @Tags 社区邻里
  80. // @Accept json
  81. // @Produce json
  82. // @Param token header string true "token"
  83. // @Param body body v1.NeighborArticleAddBody true "信息"
  84. // @Success 200 {object} v1.NeighborArticleAddResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/service/neighbor/article [post]
  87. func (c *Controller) NeighborArticleAdd(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.NeighborArticleAddRequest{}
  90. parseParamTask := func() error {
  91. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborArticleAddBody)
  92. if err != nil {
  93. logger.Error("func",
  94. zap.String("call", "util.ShouldBind"),
  95. zap.String("error", err.Error()))
  96. return errors.ParamsError
  97. }
  98. return nil
  99. }
  100. // 业务处理
  101. handleServiceTask := func() error {
  102. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  103. if err != nil {
  104. return err
  105. }
  106. // 响应数据
  107. resp := param_v1.NeighborArticleAddResponse{}
  108. rpcReq := &v1.NeighborArticleAddRequest{
  109. GardenId: req.GardenId,
  110. Uid: tokenInfo.Uid,
  111. UserIcon: tokenInfo.UserIcon,
  112. Title: req.Title,
  113. Content: req.Content,
  114. Pics: req.Pics,
  115. ClassId: req.ClassId,
  116. NickName: tokenInfo.NickName,
  117. }
  118. _, err = pb.Garden.NeighborArticleAdd(ctx, rpcReq)
  119. if err != nil {
  120. s, _ := json.MarshalToString(req)
  121. logger.Error("func",
  122. zap.String("call", "pb.Garden.NeighborArticleAdd"),
  123. zap.String("params", s),
  124. zap.String("error", err.Error()))
  125. return errors.ErrorTransForm(err)
  126. }
  127. ctx.JSON(http.StatusOK, resp)
  128. return nil
  129. }
  130. // 执行任务
  131. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  132. }
  133. //
  134. // @Summary 修改文章
  135. // @Description 修改文章
  136. // @Tags 社区邻里
  137. // @Accept json
  138. // @Produce json
  139. // @Param token header string true "token"
  140. // @Param body body v1.NeighborArticleUpdateBody true "信息"
  141. // @Success 200 {object} v1.NeighborArticleUpdateResponse
  142. // @Failure 500 {object} base.HTTPError
  143. // @Router /api/v1/service/neighbor/article [put]
  144. func (c *Controller) NeighborArticleUpdate(ctx *gin.Context) {
  145. // 解析参数
  146. req := &param_v1.NeighborArticleUpdateRequest{}
  147. parseParamTask := func() error {
  148. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborArticleUpdateBody)
  149. if err != nil {
  150. logger.Error("func",
  151. zap.String("call", "util.ShouldBind"),
  152. zap.String("error", err.Error()))
  153. return errors.ParamsError
  154. }
  155. return nil
  156. }
  157. // 业务处理
  158. handleServiceTask := func() error {
  159. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  160. if err != nil {
  161. return err
  162. }
  163. // 响应数据
  164. resp := param_v1.NeighborArticleUpdateResponse{}
  165. rpcReq := &v1.NeighborArticleUpdateRequest{
  166. GardenId: req.GardenId,
  167. Title: req.Title,
  168. Content: req.Content,
  169. Pics: req.Pics,
  170. Id: req.Id,
  171. Uid: tokenInfo.Uid,
  172. }
  173. _, err = pb.Garden.NeighborArticleUpdate(ctx, rpcReq)
  174. if err != nil {
  175. s, _ := json.MarshalToString(req)
  176. logger.Error("func",
  177. zap.String("call", "pb.Garden.NeighborArticleUpdate"),
  178. zap.String("params", s),
  179. zap.String("error", err.Error()))
  180. return errors.ErrorTransForm(err)
  181. }
  182. ctx.JSON(http.StatusOK, resp)
  183. return nil
  184. }
  185. // 执行任务
  186. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  187. }
  188. //
  189. // @Summary 删除文章
  190. // @Description 删除文章
  191. // @Tags 社区邻里
  192. // @Accept json
  193. // @Produce json
  194. // @Param token header string true "token"
  195. // @Param garden_id query int true "小区id"
  196. // @Param id query int true " "
  197. // @Success 200 {object} v1.NeighborArticleDelResponse
  198. // @Failure 500 {object} base.HTTPError
  199. // @Router /api/v1/service/neighbor/article [delete]
  200. func (c *Controller) NeighborArticleDel(ctx *gin.Context) {
  201. // 解析参数
  202. req := &param_v1.NeighborArticleDelRequest{}
  203. parseParamTask := func() error {
  204. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleDelQuery, nil)
  205. if err != nil {
  206. logger.Error("func",
  207. zap.String("call", "util.ShouldBind"),
  208. zap.String("error", err.Error()))
  209. return errors.ParamsError
  210. }
  211. return nil
  212. }
  213. // 业务处理
  214. handleServiceTask := func() error {
  215. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  216. if err != nil {
  217. return err
  218. }
  219. // 响应数据
  220. resp := param_v1.NeighborArticleDelResponse{}
  221. rpcReq := &v1.NeighborArticleDelRequest{
  222. GardenId: req.GardenId,
  223. Id: req.Id,
  224. Admin: false,
  225. Uid: tokenInfo.Uid,
  226. }
  227. _, err = pb.Garden.NeighborArticleDel(ctx, rpcReq)
  228. if err != nil {
  229. s, _ := json.MarshalToString(req)
  230. logger.Error("func",
  231. zap.String("call", "pb.Garden.NeighborArticleDel"),
  232. zap.String("params", s),
  233. zap.String("error", err.Error()))
  234. return errors.ErrorTransForm(err)
  235. }
  236. ctx.JSON(http.StatusOK, resp)
  237. return nil
  238. }
  239. // 执行任务
  240. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  241. }
  242. //
  243. // @Summary 文章列表
  244. // @Description 文章列表
  245. // @Tags 社区邻里
  246. // @Accept json
  247. // @Produce json
  248. // @Param token header string true "token"
  249. // @Param garden_id query int true "小区id"
  250. // @Param page query int false " "
  251. // @Param page_size query int false " "
  252. // @Param title query string false "文章标题 "
  253. // @Param is_me query bool false "true我发布的 false 不过滤 "
  254. // @Success 200 {object} v1.NeighborArticleListResponse
  255. // @Failure 500 {object} base.HTTPError
  256. // @Router /api/v1/service/neighbor/article [get]
  257. func (c *Controller) NeighborArticleList(ctx *gin.Context) {
  258. // 解析参数
  259. req := &param_v1.NeighborArticleListRequest{}
  260. parseParamTask := func() error {
  261. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborArticleListQuery, nil)
  262. if err != nil {
  263. logger.Error("func",
  264. zap.String("call", "util.ShouldBind"),
  265. zap.String("error", err.Error()))
  266. return errors.ParamsError
  267. }
  268. return nil
  269. }
  270. // 业务处理
  271. handleServiceTask := func() error {
  272. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  273. if err != nil {
  274. return err
  275. }
  276. // 响应数据
  277. resp := param_v1.NeighborArticleListResponse{}
  278. rpcReq := &v1.NeighborArticleListRequest{
  279. GardenId: req.GardenId,
  280. PageSize: req.PageSize,
  281. Page: req.Page,
  282. Title: req.Title,
  283. Uid: tokenInfo.Uid,
  284. IsMe: req.IsMe,
  285. }
  286. rpcRsp, err := pb.Garden.NeighborArticleList(ctx, rpcReq)
  287. if err != nil {
  288. s, _ := json.MarshalToString(req)
  289. logger.Error("func",
  290. zap.String("call", "pb.Garden.NeighborArticleList"),
  291. zap.String("params", s),
  292. zap.String("error", err.Error()))
  293. return errors.ErrorTransForm(err)
  294. }
  295. if rpcRsp.List == nil {
  296. rpcRsp.List = make([]*v1.NeighborArticleItem, 0)
  297. }
  298. resp.Data = *rpcRsp
  299. ctx.JSON(http.StatusOK, resp)
  300. return nil
  301. }
  302. // 执行任务
  303. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  304. }
  305. //
  306. // @Summary 添加评论
  307. // @Description 添加评论
  308. // @Tags 社区邻里
  309. // @Accept json
  310. // @Produce json
  311. // @Param token header string true "token"
  312. // @Param body body v1.NeighborCommentAddBody true "信息"
  313. // @Success 200 {object} v1.NeighborCommentAddResponse
  314. // @Failure 500 {object} base.HTTPError
  315. // @Router /api/v1/service/neighbor/comment [post]
  316. func (c *Controller) NeighborCommentAdd(ctx *gin.Context) {
  317. // 解析参数
  318. req := &param_v1.NeighborCommentAddRequest{}
  319. parseParamTask := func() error {
  320. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborCommentAddBody)
  321. if err != nil {
  322. logger.Error("func",
  323. zap.String("call", "util.ShouldBind"),
  324. zap.String("error", err.Error()))
  325. return errors.ParamsError
  326. }
  327. return nil
  328. }
  329. // 业务处理
  330. handleServiceTask := func() error {
  331. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  332. if err != nil {
  333. return err
  334. }
  335. // 响应数据
  336. resp := param_v1.NeighborCommentAddResponse{}
  337. rpcReq := &v1.NeighborCommentAddRequest{
  338. GardenId: req.GardenId,
  339. Uid: tokenInfo.Uid,
  340. UserIcon: tokenInfo.UserIcon,
  341. Content: req.Content,
  342. Pics: req.Pics,
  343. Pid: req.Pid,
  344. ArticleId: req.ArticleId,
  345. NickName: tokenInfo.NickName,
  346. }
  347. _, err = pb.Garden.NeighborCommentAdd(ctx, rpcReq)
  348. if err != nil {
  349. s, _ := json.MarshalToString(req)
  350. logger.Error("func",
  351. zap.String("call", "pb.Garden.NeighborCommentAdd"),
  352. zap.String("params", s),
  353. zap.String("error", err.Error()))
  354. return errors.ErrorTransForm(err)
  355. }
  356. ctx.JSON(http.StatusOK, resp)
  357. return nil
  358. }
  359. // 执行任务
  360. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  361. }
  362. //
  363. // @Summary 修改评论
  364. // @Description 修改评论
  365. // @Tags 社区邻里
  366. // @Accept json
  367. // @Produce json
  368. // @Param token header string true "token"
  369. // @Param body body v1.NeighborCommentUpdateBody true "信息"
  370. // @Success 200 {object} v1.NeighborCommentUpdateResponse
  371. // @Failure 500 {object} base.HTTPError
  372. // @Router /api/v1/service/neighbor/comment [put]
  373. func (c *Controller) NeighborCommentUpdate(ctx *gin.Context) {
  374. // 解析参数
  375. req := &param_v1.NeighborCommentUpdateRequest{}
  376. parseParamTask := func() error {
  377. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborCommentUpdateBody)
  378. if err != nil {
  379. logger.Error("func",
  380. zap.String("call", "util.ShouldBind"),
  381. zap.String("error", err.Error()))
  382. return errors.ParamsError
  383. }
  384. return nil
  385. }
  386. // 业务处理
  387. handleServiceTask := func() error {
  388. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  389. if err != nil {
  390. return err
  391. }
  392. // 响应数据
  393. resp := param_v1.NeighborCommentUpdateResponse{}
  394. rpcReq := &v1.NeighborCommentUpdateRequest{
  395. GardenId: req.GardenId,
  396. Content: req.Content,
  397. Pics: req.Pics,
  398. Id: req.Id,
  399. Uid: tokenInfo.Uid,
  400. }
  401. _, err = pb.Garden.NeighborCommentUpdate(ctx, rpcReq)
  402. if err != nil {
  403. s, _ := json.MarshalToString(req)
  404. logger.Error("func",
  405. zap.String("call", "pb.Garden.NeighborCommentUpdate"),
  406. zap.String("params", s),
  407. zap.String("error", err.Error()))
  408. return errors.ErrorTransForm(err)
  409. }
  410. ctx.JSON(http.StatusOK, resp)
  411. return nil
  412. }
  413. // 执行任务
  414. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  415. }
  416. //
  417. // @Summary 删除评论
  418. // @Description 删除评论
  419. // @Tags 社区邻里
  420. // @Accept json
  421. // @Produce json
  422. // @Param token header string true "token"
  423. // @Param garden_id query int true "小区id"
  424. // @Param id query int true " "
  425. // @Success 200 {object} v1.NeighborCommentDelResponse
  426. // @Failure 500 {object} base.HTTPError
  427. // @Router /api/v1/service/neighbor/comment [delete]
  428. func (c *Controller) NeighborCommentDel(ctx *gin.Context) {
  429. // 解析参数
  430. req := &param_v1.NeighborCommentDelRequest{}
  431. parseParamTask := func() error {
  432. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentDelQuery, nil)
  433. if err != nil {
  434. logger.Error("func",
  435. zap.String("call", "util.ShouldBind"),
  436. zap.String("error", err.Error()))
  437. return errors.ParamsError
  438. }
  439. return nil
  440. }
  441. // 业务处理
  442. handleServiceTask := func() error {
  443. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  444. if err != nil {
  445. return err
  446. }
  447. // 响应数据
  448. resp := param_v1.NeighborCommentDelResponse{}
  449. rpcReq := &v1.NeighborCommentDelRequest{
  450. GardenId: req.GardenId,
  451. Id: req.Id,
  452. Admin: false,
  453. Uid: tokenInfo.Uid,
  454. }
  455. _, err = pb.Garden.NeighborCommentDel(ctx, rpcReq)
  456. if err != nil {
  457. s, _ := json.MarshalToString(req)
  458. logger.Error("func",
  459. zap.String("call", "pb.Garden.NeighborCommentDel"),
  460. zap.String("params", s),
  461. zap.String("error", err.Error()))
  462. return errors.ErrorTransForm(err)
  463. }
  464. ctx.JSON(http.StatusOK, resp)
  465. return nil
  466. }
  467. // 执行任务
  468. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  469. }
  470. //
  471. // @Summary 评论列表
  472. // @Description 评论列表
  473. // @Tags 社区邻里
  474. // @Accept json
  475. // @Produce json
  476. // @Param token header string true "token"
  477. // @Param garden_id query int true "小区id"
  478. // @Param page query int false " "
  479. // @Param page_size query int false " "
  480. // @Param article_id query int true "文章id"
  481. // @Param pid query int false "父评论id"
  482. // @Success 200 {object} v1.NeighborCommentListResponse
  483. // @Failure 500 {object} base.HTTPError
  484. // @Router /api/v1/service/neighbor/comment [get]
  485. func (c *Controller) NeighborCommentList(ctx *gin.Context) {
  486. // 解析参数
  487. req := &param_v1.NeighborCommentListRequest{}
  488. parseParamTask := func() error {
  489. err := util.ShouldBind(ctx, &req.Header, nil, &req.NeighborCommentListQuery, nil)
  490. if err != nil {
  491. logger.Error("func",
  492. zap.String("call", "util.ShouldBind"),
  493. zap.String("error", err.Error()))
  494. return errors.ParamsError
  495. }
  496. return nil
  497. }
  498. // 业务处理
  499. handleServiceTask := func() error {
  500. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  501. if err != nil {
  502. return err
  503. }
  504. // 响应数据
  505. resp := param_v1.NeighborCommentListResponse{}
  506. rpcReq := &v1.NeighborCommentListRequest{
  507. GardenId: req.GardenId,
  508. PageSize: req.PageSize,
  509. Page: req.Page,
  510. Uid: tokenInfo.Uid,
  511. ArticleId: req.ArticleId,
  512. CommentId: req.Pid,
  513. }
  514. rpcRsp, err := pb.Garden.NeighborCommentList(ctx, rpcReq)
  515. if err != nil {
  516. s, _ := json.MarshalToString(req)
  517. logger.Error("func",
  518. zap.String("call", "pb.Garden.NeighborCommentList"),
  519. zap.String("params", s),
  520. zap.String("error", err.Error()))
  521. return errors.ErrorTransForm(err)
  522. }
  523. if rpcRsp.List == nil {
  524. rpcRsp.List = make([]*v1.NeighborCommentItem, 0)
  525. }
  526. resp.Data = *rpcRsp
  527. ctx.JSON(http.StatusOK, resp)
  528. return nil
  529. }
  530. // 执行任务
  531. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  532. }
  533. //
  534. // @Summary 点赞或撤销点赞
  535. // @Description 点赞或撤销点赞
  536. // @Tags 社区邻里
  537. // @Accept json
  538. // @Produce json
  539. // @Param token header string true "token"
  540. // @Param body body v1.NeighborLikeBody true "信息"
  541. // @Success 200 {object} v1.NeighborLikeResponse
  542. // @Failure 500 {object} base.HTTPError
  543. // @Router /api/v1/service/neighbor/like [put]
  544. func (c *Controller) NeighborLike(ctx *gin.Context) {
  545. // 解析参数
  546. req := &param_v1.NeighborLikeRequest{}
  547. parseParamTask := func() error {
  548. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.NeighborLikeBody)
  549. if err != nil {
  550. logger.Error("func",
  551. zap.String("call", "util.ShouldBind"),
  552. zap.String("error", err.Error()))
  553. return errors.ParamsError
  554. }
  555. return nil
  556. }
  557. // 业务处理
  558. handleServiceTask := func() error {
  559. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  560. if err != nil {
  561. return err
  562. }
  563. // 响应数据
  564. resp := param_v1.NeighborLikeResponse{}
  565. rpcReq := &v1.NeighborLikeRequest{
  566. GardenId: req.GardenId,
  567. LikeType: req.LikeType,
  568. LikeId: req.LikeId,
  569. Uid: tokenInfo.Uid,
  570. Like: req.Like,
  571. }
  572. _, err = pb.Garden.NeighborLike(ctx, rpcReq)
  573. if err != nil {
  574. s, _ := json.MarshalToString(req)
  575. logger.Error("func",
  576. zap.String("call", "pb.Garden.NeighborLike"),
  577. zap.String("params", s),
  578. zap.String("error", err.Error()))
  579. return errors.ErrorTransForm(err)
  580. }
  581. ctx.JSON(http.StatusOK, resp)
  582. return nil
  583. }
  584. // 执行任务
  585. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  586. }