UserInterestApiController.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.goafanti.user.controller;
  2. import javax.annotation.Resource;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.RestController;
  7. import com.goafanti.common.bo.Result;
  8. import com.goafanti.common.constant.ErrorConstants;
  9. import com.goafanti.common.controller.CertifyApiController;
  10. import com.goafanti.common.enums.UserType;
  11. import com.goafanti.common.model.UserInterest;
  12. import com.goafanti.core.shiro.token.TokenManager;
  13. import com.goafanti.user.service.UserInterestService;
  14. @RestController
  15. @RequestMapping(value = "/api/user/interest")
  16. public class UserInterestApiController extends CertifyApiController {
  17. @Resource
  18. private UserInterestService userInterestService;
  19. /**
  20. * 关注用户列表
  21. */
  22. @RequestMapping(value = "/interestUserList", method = RequestMethod.GET)
  23. public Result interestUserList(String pageNo, String pageSize, String type) {
  24. Result res = new Result();
  25. Integer pNo = 1;
  26. Integer pSize = 10;
  27. if (StringUtils.isNumeric(pageSize)) {
  28. pSize = Integer.parseInt(pageSize);
  29. }
  30. if (StringUtils.isNumeric(pageNo)) {
  31. pNo = Integer.parseInt(pageNo);
  32. }
  33. Integer userType = StringUtils.isBlank(type) ? null : UserType.getStatus(type).getCode();
  34. res.setData(userInterestService.listInterestUser(pNo, pSize, userType));
  35. return res;
  36. }
  37. /**
  38. * 关注用户
  39. */
  40. @RequestMapping(value = "/interestUser", method = RequestMethod.POST)
  41. public Result interestUser(String toUid) {
  42. Result res = new Result();
  43. if (StringUtils.isBlank(toUid)) {
  44. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "被关注用户ID"));
  45. return res;
  46. }
  47. UserInterest ui = userInterestService.findByFromUidAndToUid(TokenManager.getUserId(), toUid);
  48. if (null != ui) {
  49. res.getError().add(buildError("", "当前用户已关注!"));
  50. return res;
  51. }
  52. res.setData(userInterestService.insert(toUid));
  53. return res;
  54. }
  55. /**
  56. * 取消关注
  57. */
  58. @RequestMapping(value = "/cancelInterest", method = RequestMethod.POST)
  59. public Result cancelInterest(String interestId) {
  60. Result res = new Result();
  61. if (StringUtils.isBlank(interestId)) {
  62. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "关注ID"));
  63. return res;
  64. }
  65. UserInterest ui = userInterestService.findByPrimaryKey(interestId);
  66. if (null == ui || !TokenManager.getUserId().equals(ui.getFromUid())) {
  67. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关注ID"));
  68. return res;
  69. }
  70. res.setData(userInterestService.deleteByPrimaryKey(interestId));
  71. return res;
  72. }
  73. }