|
| 1 | +package com.dasom.MemoReal.domain.user.controller; |
| 2 | + |
| 3 | +import com.dasom.MemoReal.domain.user.dto.JoinDTO; |
| 4 | +import com.dasom.MemoReal.domain.user.dto.LoginDTO; |
| 5 | +import com.dasom.MemoReal.domain.user.dto.UserDTO; |
| 6 | +import com.dasom.MemoReal.domain.user.service.UserService; |
| 7 | +import com.dasom.MemoReal.global.jwt.dto.JwtTokenDTO; |
| 8 | +import com.dasom.MemoReal.global.security.util.SecurityUtil; |
| 9 | +import lombok.RequiredArgsConstructor; |
| 10 | +import org.springframework.http.ResponseEntity; |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; |
| 13 | +import org.springframework.web.bind.annotation.RestController; |
| 14 | + |
| 15 | +@RestController |
| 16 | +@RequiredArgsConstructor |
| 17 | +public class UserController { |
| 18 | + private final UserService userService; |
| 19 | + |
| 20 | + @PostMapping("/login") |
| 21 | + public JwtTokenDTO login(@RequestBody LoginDTO loginDto) { |
| 22 | + String email = loginDto.getEmail(); |
| 23 | + String password = loginDto.getPassword(); |
| 24 | + JwtTokenDTO jwtToken = userService.login(email, password); |
| 25 | + return jwtToken; |
| 26 | + } |
| 27 | + |
| 28 | + @PostMapping("/join") |
| 29 | + public ResponseEntity<UserDTO> join(@RequestBody JoinDTO joinDto) { |
| 30 | + UserDTO savedUserDto = userService.join(joinDto); |
| 31 | + return ResponseEntity.ok(savedUserDto); |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | + // 임시 테스트 토큰이 있는 사용자가 요청 시, 사용자의 닉네임 반환 |
| 36 | + @PostMapping("/test") |
| 37 | + public String test() { |
| 38 | + return SecurityUtil.getCurrentUsername(); |
| 39 | + } |
| 40 | +} |
0 commit comments