UserController.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.kym.miniapp.controller;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.kym.common.R;
  5. import com.kym.entity.common.PageBean;
  6. import com.kym.entity.miniapp.User;
  7. import com.kym.entity.miniapp.queryParams.WxLoginParams;
  8. import com.kym.entity.miniapp.vo.UserVo;
  9. import com.kym.service.miniapp.CollectService;
  10. import com.kym.service.miniapp.UserService;
  11. import org.springframework.validation.annotation.Validated;
  12. import org.springframework.web.bind.annotation.*;
  13. /**
  14. * <p>
  15. * 用户表 前端控制器
  16. * </p>
  17. *
  18. * @author skyline
  19. * @since 2023-06-27
  20. */
  21. @RestController
  22. @RequestMapping("/user")
  23. public class UserController {
  24. private final UserService userService;
  25. private final CollectService collectService;
  26. public UserController(UserService userService, CollectService collectService) {
  27. this.userService = userService;
  28. this.collectService = collectService;
  29. }
  30. /**
  31. * 微信登录/注册
  32. *
  33. * @param params
  34. * @return
  35. */
  36. @PostMapping("/wxLogin")
  37. public R<?> login(@RequestBody @Validated WxLoginParams params) {
  38. return userService.wxLogin(params);
  39. }
  40. /**
  41. * 登出
  42. *
  43. * @return
  44. */
  45. @GetMapping("/logout")
  46. public R<?> logout() {
  47. StpUtil.logout();
  48. return R.success();
  49. }
  50. /**
  51. * 当前用户信息
  52. *
  53. * @return
  54. */
  55. @GetMapping("/me")
  56. public R<?> me() {
  57. return R.success(userService.getMe());
  58. }
  59. /**
  60. * 用户列表
  61. *
  62. * @param pageNum
  63. * @param pageSize
  64. * @return
  65. */
  66. @GetMapping("listUser")
  67. PageBean<UserVo> listUser(@RequestParam int pageNum, @RequestParam int pageSize) {
  68. return userService.listUserVo(pageNum, pageSize);
  69. }
  70. /**
  71. * 更新用户信息
  72. *
  73. * @param userVo
  74. * @return
  75. */
  76. @PutMapping
  77. R<?> updateUser(@RequestBody UserVo userVo) {
  78. userService.updateUser(userVo);
  79. return R.success();
  80. }
  81. /**
  82. * 收藏列表
  83. *
  84. * @return
  85. */
  86. @GetMapping("/collectList")
  87. R<?> listCollect() {
  88. return R.success(collectService.listCollect());
  89. }
  90. /**
  91. * 添加/取消收藏
  92. *
  93. * @param json
  94. * @return
  95. */
  96. @PostMapping("/collect")
  97. R<?> saveCollect(@RequestBody JSONObject json) {
  98. collectService.updateCollect(json.getString("stationId"), json.getInteger("status"));
  99. return R.success();
  100. }
  101. }