| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package com.kym.miniapp.controller;
- import cn.dev33.satoken.stp.StpUtil;
- import com.alibaba.fastjson2.JSONObject;
- import com.kym.common.R;
- import com.kym.entity.common.PageBean;
- import com.kym.entity.miniapp.User;
- import com.kym.entity.miniapp.queryParams.WxLoginParams;
- import com.kym.entity.miniapp.vo.UserVo;
- import com.kym.service.miniapp.CollectService;
- import com.kym.service.miniapp.UserService;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- /**
- * <p>
- * 用户表 前端控制器
- * </p>
- *
- * @author skyline
- * @since 2023-06-27
- */
- @RestController
- @RequestMapping("/user")
- public class UserController {
- private final UserService userService;
- private final CollectService collectService;
- public UserController(UserService userService, CollectService collectService) {
- this.userService = userService;
- this.collectService = collectService;
- }
- /**
- * 微信登录/注册
- *
- * @param params
- * @return
- */
- @PostMapping("/wxLogin")
- public R<?> login(@RequestBody @Validated WxLoginParams params) {
- return userService.wxLogin(params);
- }
- /**
- * 登出
- *
- * @return
- */
- @GetMapping("/logout")
- public R<?> logout() {
- StpUtil.logout();
- return R.success();
- }
- /**
- * 当前用户信息
- *
- * @return
- */
- @GetMapping("/me")
- public R<?> me() {
- return R.success(userService.getMe());
- }
- /**
- * 用户列表
- *
- * @param pageNum
- * @param pageSize
- * @return
- */
- @GetMapping("listUser")
- PageBean<UserVo> listUser(@RequestParam int pageNum, @RequestParam int pageSize) {
- return userService.listUserVo(pageNum, pageSize);
- }
- /**
- * 更新用户信息
- *
- * @param userVo
- * @return
- */
- @PutMapping
- R<?> updateUser(@RequestBody UserVo userVo) {
- userService.updateUser(userVo);
- return R.success();
- }
- /**
- * 收藏列表
- *
- * @return
- */
- @GetMapping("/collectList")
- R<?> listCollect() {
- return R.success(collectService.listCollect());
- }
- /**
- * 添加/取消收藏
- *
- * @param json
- * @return
- */
- @PostMapping("/collect")
- R<?> saveCollect(@RequestBody JSONObject json) {
- collectService.updateCollect(json.getString("stationId"), json.getInteger("status"));
- return R.success();
- }
- }
|