11package com .umc .goodgame .domain .admin .controller ;
22
3- import com .umc .goodgame .domain .auth .dto .AuthResponseDto ;
43import com .umc .goodgame .domain .recommendation .service .DefaultRecommendationService ;
5- import com .umc .goodgame .domain .user .entity .Role ;
6- import com .umc .goodgame .domain .user .entity .User ;
7- import com .umc .goodgame .domain .user .repository .UserRepository ;
8- import com .umc .goodgame .global .exception .CustomException ;
94import com .umc .goodgame .global .response .ApiResponse ;
10- import com .umc .goodgame .global .response .ErrorCode ;
115import com .umc .goodgame .global .response .SuccessCode ;
12- import com .umc .goodgame .global .security .jwt .JwtTokenProvider ;
136import io .swagger .v3 .oas .annotations .Operation ;
147import io .swagger .v3 .oas .annotations .tags .Tag ;
158import lombok .RequiredArgsConstructor ;
2821@ Tag (name = "Admin Test" , description = "관리자 테스트용 API" )
2922public class AdminTestController {
3023
31- private final UserRepository userRepository ;
32- private final JwtTokenProvider jwtTokenProvider ;
3324 private final DefaultRecommendationService defaultRecommendationService ;
3425
3526 @ GetMapping ("/verify" )
@@ -39,89 +30,6 @@ public ApiResponse<String> adminTest() {
3930 return ApiResponse .success (SuccessCode .OK , "admin access verified" );
4031 }
4132
42- @ PostMapping ("/create" )
43- @ Operation (
44- summary = "관리자 계정 생성 (테스트용)" ,
45- description = "테스트용 관리자 계정을 생성합니다. 이미 관리자 계정이 존재하면 오류를 반환합니다."
46- )
47- @ Transactional
48- public ApiResponse <AuthResponseDto .UserInfo > createAdminAccount () {
49- log .info ("[AdminTestController.createAdminAccount] Creating admin account" );
50-
51- // 이미 ADMIN 역할을 가진 사용자가 있는지 확인
52- boolean adminExists = userRepository .findAll ().stream ()
53- .anyMatch (user -> user .getRole () == Role .ADMIN );
54-
55- if (adminExists ) {
56- log .warn ("[AdminTestController.createAdminAccount] Admin account already exists" );
57- throw new CustomException (ErrorCode .ADMIN_ALREADY_EXISTS );
58- }
59-
60- // 관리자 계정 생성
61- User admin = User .builder ()
62- .googleId ("admin-test-user" )
63- .email ("admin@test.local" )
64- .name ("관리자" )
65- .profileImage (null )
66- .role (Role .ADMIN )
67- .build ();
68-
69- User savedAdmin = userRepository .save (admin );
70- log .info ("[AdminTestController.createAdminAccount] Admin account created with id: {}" , savedAdmin .getId ());
71-
72- return ApiResponse .success (
73- SuccessCode .CREATED ,
74- AuthResponseDto .UserInfo .builder ()
75- .id (savedAdmin .getId ())
76- .email (savedAdmin .getEmail ())
77- .name (savedAdmin .getName ())
78- .profileImage (savedAdmin .getProfileImage ())
79- .role (savedAdmin .getRole ())
80- .build ()
81- );
82- }
83-
84- @ PostMapping ("/token" )
85- @ Operation (
86- summary = "관리자 JWT 토큰 발급 (테스트용)" ,
87- description = "관리자 계정의 JWT 토큰을 발급합니다. 관리자 계정이 없으면 오류를 반환합니다."
88- )
89- @ Transactional (readOnly = true )
90- public ApiResponse <AuthResponseDto .LoginResponse > issueAdminToken () {
91- log .info ("[AdminTestController.issueAdminToken] Issuing admin token" );
92-
93- // ADMIN 역할을 가진 사용자 찾기
94- User admin = userRepository .findAll ().stream ()
95- .filter (user -> user .getRole () == Role .ADMIN )
96- .findFirst ()
97- .orElseThrow (() -> {
98- log .warn ("[AdminTestController.issueAdminToken] Admin account not found" );
99- return new CustomException (ErrorCode .MEMBER_NOT_FOUND );
100- });
101-
102- String accessToken = jwtTokenProvider .createAccessToken (admin .getId (), admin .getRole ());
103- String refreshToken = jwtTokenProvider .createRefreshToken (admin .getId (), admin .getRole ());
104-
105- log .info ("[AdminTestController.issueAdminToken] Admin token issued for userId: {}" , admin .getId ());
106-
107- return ApiResponse .success (
108- SuccessCode .OK ,
109- AuthResponseDto .LoginResponse .builder ()
110- .accessToken (accessToken )
111- .refreshToken (refreshToken )
112- .accessTokenExpiresIn (jwtTokenProvider .getAccessTokenExpiry ())
113- .isNewUser (false )
114- .user (AuthResponseDto .UserInfo .builder ()
115- .id (admin .getId ())
116- .email (admin .getEmail ())
117- .name (admin .getName ())
118- .profileImage (admin .getProfileImage ())
119- .role (admin .getRole ())
120- .build ())
121- .build ()
122- );
123- }
124-
12533 @ Operation (summary = "기본 추천 전체 삭제" , description = "DefaultRecommendation 테이블을 비웁니다." )
12634 @ DeleteMapping ("/default-recommendations" )
12735 @ Transactional
0 commit comments