Skip to content

Commit 790b732

Browse files
committed
fix: notification, 로그아웃 로그 추가
1 parent cb83428 commit 790b732

6 files changed

Lines changed: 32 additions & 27 deletions

File tree

src/main/java/com/example/ImFact/auth/controller/AuthController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public ResponseEntity<ApiResponseDto<ReissueResponseDto>> reissue(
3636
public ResponseEntity<ApiResponseDto<Void>> logout(
3737
@CookieValue("refresh_token") String refreshToken, HttpServletResponse response) {
3838

39+
log.info("로그아웃 API 호출");
3940
authService.logout(refreshToken);
4041

4142
Cookie cookie = new Cookie("refresh_token", null);

src/main/java/com/example/ImFact/auth/controller/OAuthSuccessController.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/com/example/ImFact/auth/service/AuthService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ public void logout(String refreshTokenValue) {
5353
.orElseThrow(() -> new BusinessException(ErrorCode.REFRESH_TOKEN_NOT_FOUND));
5454

5555
refreshTokenRepository.delete(target);
56+
log.info("로그아웃 완료");
5657
}
5758
}

src/main/java/com/example/ImFact/news/controller/NewsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class NewsController {
2626
@GetMapping("")
2727
public ResponseEntity<ApiResponseDto<NewsListDto>> searchNews(
2828
@AuthenticationPrincipal UserDetails userDetails,
29-
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size,
29+
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size,
3030
@RequestParam(required = false) String category, @RequestParam(required = false) Double reliabilityScore,
3131
@RequestParam(required = false) String query, @RequestParam(required = false) String press) {
3232

src/main/java/com/example/ImFact/notification/controller/NotificationController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public ResponseEntity<ApiResponseDto<Void>> registerFcmToken (
3030
String userIdString = userDetails.getUsername();
3131
Long userId = Long.parseLong(userIdString);
3232

33+
log.info("FCM 토큰 등록/갱신 요청 수신 - userId: {}", userId);
3334
notificationService.saveOrUpdateFcmToken(userId, fcmTokenRequestDto.getFcmToken());
3435

3536
ApiResponseDto<Void> apiResponse = ApiResponseDto.success(null);
@@ -54,9 +55,13 @@ public ResponseEntity<ApiResponseDto<List<NotificationResponseDto>>> getNotifica
5455
String userIdString = userDetails.getUsername();
5556
Long userId = Long.parseLong(userIdString);
5657

58+
log.info("알림 목록 조회 요청 수신 - userId: {}", userId);
59+
5760
List<NotificationResponseDto> notifications = notificationService.getNotifications(userId);
5861
ApiResponseDto<List<NotificationResponseDto>> apiResponse = ApiResponseDto.success(notifications);
5962

63+
log.info("알림 {}건 조회 완료 - userId: {}", notifications.size(), userId);
64+
6065
return ResponseEntity.ok(apiResponse);
6166
}
6267

@@ -67,20 +72,26 @@ public ResponseEntity<ApiResponseDto<UnreadCountResponseDto>> getUnreadCount(
6772
String userIdString = userDetails.getUsername();
6873
Long userId = Long.parseLong(userIdString);
6974

75+
log.info("안 읽은 알림 개수 조회 요청 수신 - userId: {}", userId);
76+
7077
UnreadCountResponseDto unreadCount = notificationService.getUnreadCount(userId);
7178
ApiResponseDto<UnreadCountResponseDto> apiResponse = ApiResponseDto.success(unreadCount);
7279

80+
log.info("안 읽은 알림 {}건 확인 - userId: {}", unreadCount.getCount(), userId);
81+
7382
return ResponseEntity.ok(apiResponse);
7483
}
7584

7685
@PostMapping("{notificationId}/read")
77-
public ResponseEntity<ApiResponseDto<Void>> ReadNotification(
86+
public ResponseEntity<ApiResponseDto<Void>> readNotification(
7887
@AuthenticationPrincipal UserDetails userDetails,
7988
@PathVariable Long notificationId) {
8089

8190
String userIdString = userDetails.getUsername();
8291
Long userId = Long.parseLong(userIdString);
8392

93+
log.info("알림 읽음 처리 요청 수신 - userId: {}, notificationId: {}", userId, notificationId);
94+
8495
notificationService.readNotification(userId, notificationId);
8596
ApiResponseDto<Void> apiResponse = ApiResponseDto.success(null);
8697

src/main/java/com/example/ImFact/notification/service/NotificationService.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public class NotificationService {
3636
@Transactional
3737
public void saveOrUpdateFcmToken(Long userId, String fcmToken) {
3838

39+
log.info("FCM 토큰 저장 시작 - userId: {}", userId);
40+
3941
// findById로 사용자를 찾음
4042
UserEntity user = userRepository.findById(userId)
4143
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
4244

4345
user.updateFcmToken(fcmToken);
46+
log.info("FCM 토큰 저장 완료 - userId: {}", userId);
4447
}
4548

4649
@Async
@@ -53,6 +56,7 @@ public void sendGlobalNotification(String type) {
5356

5457
int page = 0;
5558
Page<UserEntity> userPage;
59+
long totalSentCount = 0;
5660

5761
try {
5862
do {
@@ -72,17 +76,18 @@ public void sendGlobalNotification(String type) {
7276
}
7377

7478
List<UserEntity> users = userPage.getContent();
79+
int pageCount = users.size();
7580

7681
if (!users.isEmpty()) {
7782
log.info("[{} Notification] {}명에게 알림 발송 (Page {})", type, users.size(), page);
78-
7983
fcmService.sendPushNotificationToMultipleUsers(users, title, body);
84+
totalSentCount += pageCount;
8085
}
8186

8287
page++;
8388
} while (userPage.hasNext());
8489

85-
log.info("[Async Task END] {} 알림 발송이 완료되었습니다.", type);
90+
log.info("[Async Task END] {} 알림 발송이 완료되었습니다. (총 {}명 대상)", type, totalSentCount);
8691

8792
} catch (Exception e) {
8893
log.error("[Async Task ERROR] {} 알림 발송 중 오류 발생", type, e);
@@ -92,11 +97,15 @@ public void sendGlobalNotification(String type) {
9297
@Transactional
9398
public List<NotificationResponseDto> getNotifications(Long userId) {
9499

100+
log.info("알림 목록 조회 시작 - userId: {}", userId);
101+
95102
UserEntity user = userRepository.findById(userId)
96103
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
97104

98105
List<NotificationEntity> notifications = notificationRepository.findAllByUserOrderByCreatedAtDesc(user);
99106

107+
log.info("알림 {}건 조회 완료 - userId: {}", notifications.size(), userId);
108+
100109
return notifications.stream()
101110
.map(NotificationResponseDto::from)
102111
.collect(Collectors.toList());
@@ -105,17 +114,22 @@ public List<NotificationResponseDto> getNotifications(Long userId) {
105114
@Transactional
106115
public UnreadCountResponseDto getUnreadCount(Long userId) {
107116

117+
log.info("안 읽은 알림 개수 조회 시작 - userId: {}", userId);
118+
108119
UserEntity user = userRepository.findById(userId)
109120
.orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND));
110121

111122
Long count = notificationRepository.countByUserAndIsReadFalse(user);
123+
log.info("안 읽은 알림 {}건 확인 - userId: {}", count, userId);
112124

113125
return new UnreadCountResponseDto(count);
114126
}
115127

116128
@Transactional
117129
public void readNotification(Long userId, Long notificationId) {
118130

131+
log.info("알림 읽음 처리 시작 - userId: {}, notificationId: {}", userId, notificationId);
132+
119133
NotificationEntity notification = notificationRepository.findById(notificationId)
120134
.orElseThrow(() -> new BusinessException(ErrorCode.NOTIFICATION_NOT_FOUND));
121135

@@ -125,5 +139,6 @@ public void readNotification(Long userId, Long notificationId) {
125139
}
126140

127141
notification.markAsRead();
142+
log.info("알림 읽음 처리 완료 - notificationId: {}", notificationId);
128143
}
129144
}

0 commit comments

Comments
 (0)