前端控制器 @author 虎哥 @since 2021-12-22
| 29 | * @since 2021-12-22 |
| 30 | */ |
| 31 | @Slf4j |
| 32 | @RestController |
| 33 | @RequestMapping("/user") |
| 34 | public class UserController { |
| 35 | |
| 36 | @Resource |
| 37 | private IUserService userService; |
| 38 | |
| 39 | @Resource |
| 40 | private IUserInfoService userInfoService; |
| 41 | |
| 42 | @Autowired |
| 43 | private StringRedisTemplate redisTemplate; |
| 44 | |
| 45 | /** |
| 46 | * 发送手机验证码 |
| 47 | */ |
| 48 | @PostMapping("code") |
| 49 | public Result sendCode(@RequestParam("phone") String phone, HttpSession session) { |
| 50 | return userService.sendCode(phone,session); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * 登录功能 |
| 55 | * @param loginForm 登录参数,包含手机号、验证码;或者手机号、密码 |
| 56 | */ |
| 57 | @PostMapping("/login") |
| 58 | public Result login(@RequestBody LoginFormDTO loginForm, HttpSession session){ |
| 59 | return userService.login(loginForm,session); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * 登出功能 |
| 64 | * @return 无 |
| 65 | */ |
| 66 | @PostMapping("/logout") |
| 67 | public Result logout(){ |
| 68 | UserHolder.removeUser(); |
| 69 | return Result.fail("功能未完成"); |
| 70 | } |
| 71 | |
| 72 | @GetMapping("/me") |
| 73 | public Result me(){ |
| 74 | UserDTO user = UserHolder.getUser(); |
| 75 | return Result.ok(user); |
| 76 | } |
| 77 | |
| 78 | @GetMapping("/info/{id}") |
| 79 | public Result info(@PathVariable("id") Long userId){ |
| 80 | // 查询详情 |
| 81 | UserInfo info = userInfoService.getById(userId); |
| 82 | if (info == null) { |
| 83 | // 没有详情,应该是第一次查看详情 |
| 84 | return Result.ok(); |
| 85 | } |
| 86 | info.setCreateTime(null); |
| 87 | info.setUpdateTime(null); |
| 88 | // 返回 |
nothing calls this directly
no outgoing calls
no test coverage detected