11package com .tave .PromptMate .auth .controller ;
22
3+ import com .tave .PromptMate .auth .dto .request .CustomUserDetails ;
34import com .tave .PromptMate .auth .dto .request .LoginRequest ;
45import com .tave .PromptMate .auth .dto .request .SignUpRequest ;
56import com .tave .PromptMate .auth .dto .response .JwtLoginResponse ;
67import com .tave .PromptMate .auth .dto .response .TokenResponse ;
78import com .tave .PromptMate .auth .dto .response .LoginResponse ;
89import com .tave .PromptMate .auth .service .AuthService ;
10+ import com .tave .PromptMate .service .UserService ;
911import io .swagger .v3 .oas .annotations .Operation ;
1012import io .swagger .v3 .oas .annotations .tags .Tag ;
1113import lombok .RequiredArgsConstructor ;
1214import org .springframework .http .HttpHeaders ;
1315import org .springframework .http .HttpStatus ;
1416import org .springframework .http .ResponseEntity ;
15- import org .springframework .web .bind .annotation .PostMapping ;
16- import org .springframework .web .bind .annotation .RequestBody ;
17- import org .springframework .web .bind .annotation .RequestParam ;
18- import org .springframework .web .bind .annotation .RestController ;
17+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
18+ import org .springframework .web .bind .annotation .*;
1919
2020@ RestController
2121@ RequiredArgsConstructor
22- @ Tag (name ="카카오로그인 API" )
22+ @ RequestMapping ("/api/auth" )
23+ @ Tag (name = "Auth API" , description = "로그인 및 인증 관련 API" )
2324public class AuthController {
2425 private final AuthService authService ;
26+ private final UserService userService ;
2527
26- @ PostMapping ("/api/auth/ login/kakao" )
27- @ Operation (summary = "카카오로그인" )
28+ @ PostMapping ("/login/kakao" )
29+ @ Operation (summary = "카카오로그인" , description = "카카오로그인을 합니다." )
2830 public ResponseEntity <JwtLoginResponse > kakaoLogin (@ RequestParam String code ){
2931 JwtLoginResponse jwtLoginResponse = authService .loginOrRegister (code );
3032
@@ -34,6 +36,31 @@ public ResponseEntity<JwtLoginResponse> kakaoLogin(@RequestParam String code){
3436 }
3537
3638
39+ @ PostMapping ("/signup" )
40+ @ Operation (summary = "회원가입" , description = "이메일을 통해 회원가입합니다." )
41+ public ResponseEntity <String > signUp (@ RequestBody SignUpRequest request ){
42+ authService .signUp (request );
43+
44+ return ResponseEntity .status (HttpStatus .OK ).body ("회원가입 완료" );
45+ }
46+
47+ @ PostMapping ("/login" )
48+ @ Operation (summary = "로그인" , description = "회원가입한 이메일을 통해 로그인합니다." )
49+ public ResponseEntity <LoginResponse > login (@ RequestBody LoginRequest request ){
50+ LoginResponse response =authService .login (request );
51+
52+ return ResponseEntity .status (HttpStatus .OK ).body (response );
53+ }
54+
55+ @ PostMapping ("/logout" )
56+ @ Operation (summary = "로그아웃" ,description = "사용자를 로그아웃합니다." )
57+ public ResponseEntity <String > logout (@ AuthenticationPrincipal CustomUserDetails principal ){
58+ Long userId =principal .getUserId ();
59+ String message =userService .logout (userId );
60+ return ResponseEntity .ok (message );
61+ }
62+
63+
3764 //백엔드 확인용
3865 @ PostMapping ("/api/auth/token/reissue" )
3966 @ Operation (summary = "백엔드 개발용 API" )
@@ -47,21 +74,4 @@ public ResponseEntity<TokenResponse> reissueAccessToken(@RequestParam String ref
4774 return ResponseEntity .ok (response );
4875 }
4976
50-
51- @ PostMapping ("/api/auth/signup" )
52- @ Operation (summary = "회원가입" )
53- public ResponseEntity <String > signUp (@ RequestBody SignUpRequest request ){
54- authService .signUp (request );
55-
56- return ResponseEntity .status (HttpStatus .OK ).body ("회원가입 완료" );
57- }
58-
59- @ PostMapping ("/api/auth/login" )
60- @ Operation (summary = "로그인" )
61- public ResponseEntity <LoginResponse > login (@ RequestBody LoginRequest request ){
62- LoginResponse response =authService .login (request );
63-
64- return ResponseEntity .status (HttpStatus .OK ).body (response );
65- }
66-
6777}
0 commit comments