1010import com .together .backend .global .security .oauth2 .dto .CustomOAuth2User ;
1111import com .together .backend .domain .user .model .entity .User ;
1212import com .together .backend .domain .user .repository .UserRepository ;
13+ import lombok .extern .slf4j .Slf4j ;
1314import org .springframework .http .HttpStatus ;
1415import org .springframework .http .ResponseEntity ;
1516import org .springframework .security .core .annotation .AuthenticationPrincipal ;
2021import java .util .List ;
2122import java .util .Optional ;
2223
24+ @ Slf4j
2325@ RestController
2426@ RequestMapping ("/api/calendar" )
2527public class CalendarController {
@@ -36,26 +38,31 @@ public ResponseEntity<BaseResponse<List<CalendarRecordResponse>>> saveRecord(
3638 @ RequestBody CalendarRecordRequest request ,
3739 @ AuthenticationPrincipal CustomOAuth2User customUser
3840 ) {
41+ log .info ("[API] /api/calendar POST 호출: customUser={}" , customUser != null ? customUser .getEmail () : "null" );
42+
3943 if (customUser == null ) {
44+ log .warn ("[API] 인증 실패 (customUser==null)" );
4045 return ResponseEntity
4146 .status (HttpStatus .UNAUTHORIZED )
4247 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
4348 }
44- // 실제 DB의 User 조회
4549 String email = customUser .getEmail ();
4650 Optional <User > userOpt = userRepository .findByEmail (email );
4751 if (userOpt .isEmpty ()) {
52+ log .warn ("[API] 인증 실패 (userOpt.isEmpty): email={}" , email );
4853 return ResponseEntity
4954 .status (HttpStatus .UNAUTHORIZED )
5055 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
5156 }
52- User user = userOpt .get (); // 또는 userOpt.orElseThrow(() -> ...);
57+ User user = userOpt .get ();
5358
5459 try {
5560 calendarService .saveCalendarRecord (user , request );
61+ log .info ("[API] /api/calendar POST 성공: userId={}" , user .getUserId ());
5662 return ResponseEntity .status (HttpStatus .OK )
5763 .body (new BaseResponse <>(BaseResponseStatus .OK ));
5864 } catch (Exception e ) {
65+ log .error ("[API] /api/calendar POST 실패: userId={}, message={}" , user .getUserId (), e .getMessage (), e );
5966 return ResponseEntity
6067 .status (HttpStatus .INTERNAL_SERVER_ERROR )
6168 .body (new BaseResponse <>(BaseResponseStatus .INTERNAL_SERVER_ERROR ));
@@ -67,15 +74,18 @@ public ResponseEntity<BaseResponse<List<CalendarSummaryResponse>>> getCalendarSu
6774 @ RequestParam ("month" ) String month ,
6875 @ AuthenticationPrincipal CustomOAuth2User customUser
6976 ) {
77+ log .info ("[API] /api/calendar/summary GET 호출: customUser={}, month={}" , customUser != null ? customUser .getEmail () : "null" , month );
78+
7079 if (customUser == null ) {
80+ log .warn ("[API] 인증 실패 (customUser==null)" );
7181 return ResponseEntity
7282 .status (HttpStatus .UNAUTHORIZED )
7383 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
7484 }
7585
76- // DB의 User 엔티티 조회
7786 Optional <User > userOpt = userRepository .findByEmail (customUser .getEmail ());
7887 if (userOpt .isEmpty ()) {
88+ log .warn ("[API] 인증 실패 (userOpt.isEmpty): email={}" , customUser .getEmail ());
7989 return ResponseEntity
8090 .status (HttpStatus .UNAUTHORIZED )
8191 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
@@ -84,11 +94,14 @@ public ResponseEntity<BaseResponse<List<CalendarSummaryResponse>>> getCalendarSu
8494
8595 try {
8696 List <CalendarSummaryResponse > result = calendarService .getCalendarSummary (user , month );
97+ log .info ("[API] /api/calendar/summary GET 성공: userId={}, count={}" , user .getUserId (), result .size ());
8798 return ResponseEntity .ok (new BaseResponse <>(result ));
8899 } catch (DateTimeException e ) {
100+ log .warn ("[API] 잘못된 날짜 포맷: month={}, message={}" , month , e .getMessage ());
89101 return ResponseEntity .badRequest ()
90102 .body (new BaseResponse <>(BaseResponseStatus .BAD_REQUEST , null ));
91103 } catch (Exception e ) {
104+ log .error ("[API] /api/calendar/summary GET 실패: userId={}, message={}" , user .getUserId (), e .getMessage (), e );
92105 return ResponseEntity
93106 .status (HttpStatus .INTERNAL_SERVER_ERROR )
94107 .body (new BaseResponse <>(BaseResponseStatus .INTERNAL_SERVER_ERROR ));
@@ -100,15 +113,17 @@ public ResponseEntity<BaseResponse<CalendarDetailResponse>> getCalendarDetail(
100113 @ RequestParam ("date" ) String dateStr ,
101114 @ AuthenticationPrincipal CustomOAuth2User customUser
102115 ) {
103- // 인증 확인
116+ log .info ("[API] /api/calendar/detail GET 호출: customUser={}, date={}" , customUser != null ? customUser .getEmail () : "null" , dateStr );
117+
104118 if (customUser == null ) {
119+ log .warn ("[API] 인증 실패 (customUser==null)" );
105120 return ResponseEntity .status (HttpStatus .UNAUTHORIZED )
106121 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
107122 }
108123
109- // 유저 엔티티 조회
110124 Optional <User > userOpt = userRepository .findByEmail (customUser .getEmail ());
111125 if (userOpt .isEmpty ()) {
126+ log .warn ("[API] 인증 실패 (userOpt.isEmpty): email={}" , customUser .getEmail ());
112127 return ResponseEntity .status (HttpStatus .UNAUTHORIZED )
113128 .body (new BaseResponse <>(BaseResponseStatus .UNAUTHORIZED ));
114129 }
@@ -119,14 +134,17 @@ public ResponseEntity<BaseResponse<CalendarDetailResponse>> getCalendarDetail(
119134 LocalDate date = LocalDate .parse (dateStr );
120135
121136 CalendarDetailResponse result = calendarService .getCalendarDetail (user , date );
137+ log .info ("[API] /api/calendar/detail GET 성공: userId={}, date={}" , user .getUserId (), dateStr );
122138 return ResponseEntity .ok (new BaseResponse <>(result ));
123139 } catch (DateTimeException e ) {
140+ log .warn ("[API] 잘못된 날짜 포맷: date={}, message={}" , dateStr , e .getMessage ());
124141 return ResponseEntity .badRequest ()
125142 .body (new BaseResponse <>(BaseResponseStatus .BAD_REQUEST , null ));
126143 } catch (Exception e ) {
144+ log .error ("[API] /api/calendar/detail GET 실패: userId={}, date={}, message={}" , user .getUserId (), dateStr , e .getMessage (), e );
127145 return ResponseEntity
128146 .status (HttpStatus .INTERNAL_SERVER_ERROR )
129147 .body (new BaseResponse <>(BaseResponseStatus .INTERNAL_SERVER_ERROR ));
130148 }
131149 }
132- }
150+ }
0 commit comments