Skip to content

Commit 97dbdd3

Browse files
committed
CLAP-162 Feat: 미확인 알림개수 조회 기능 구현
1 parent 2326a5c commit 97dbdd3

File tree

8 files changed

+68
-0
lines changed

8 files changed

+68
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package clap.server.adapter.inbound.web.dto.notification;
2+
3+
public record CountNotificationResponse(
4+
Long memberId,
5+
Integer count
6+
) {
7+
}

src/main/java/clap/server/adapter/inbound/web/notification/FindNotificationController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import clap.server.adapter.inbound.security.SecurityUserDetails;
44
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
5+
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
56
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
7+
import clap.server.application.port.inbound.notification.CountNotificationUseCase;
68
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
79
import clap.server.common.annotation.architecture.WebAdapter;
810
import io.swagger.v3.oas.annotations.Operation;
@@ -27,6 +29,7 @@
2729
public class FindNotificationController {
2830

2931
private final FindNotificationListUsecase findNotificationListUsecase;
32+
private final CountNotificationUseCase countNotificationUseCase;
3033

3134
@Operation(summary = "알림 목록 조회 API")
3235
@Parameters({
@@ -41,4 +44,11 @@ public ResponseEntity<SliceResponse<FindNotificationListResponse>> findNotificat
4144
Pageable pageable = PageRequest.of(page, size);
4245
return ResponseEntity.ok(findNotificationListUsecase.findNotificationList(securityUserDetails.getUserId(), pageable));
4346
}
47+
48+
@Operation(summary = "미확인 알림 개수 조회 API")
49+
@GetMapping("/count")
50+
public ResponseEntity<CountNotificationResponse> countNotification(
51+
@AuthenticationPrincipal SecurityUserDetails userInfo) {
52+
return ResponseEntity.ok(countNotificationUseCase.countNotification(userInfo.getUserId()));
53+
}
4454
}

src/main/java/clap/server/adapter/outbound/persistense/NotificationPersistenceAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public List<Notification> findNotificationsByMemberId(Long memberId) {
4949
.collect(Collectors.toList());
5050
}
5151

52+
@Override
53+
public Integer countNotification(Long memberId) {
54+
return notificationRepository.countByIsReadFalseAndReceiver_MemberId(memberId);
55+
}
56+
5257
@Override
5358
public void save(Notification notification) {
5459
notificationRepository.save(notificationPersistenceMapper.toEntity(notification));

src/main/java/clap/server/adapter/outbound/persistense/repository/notification/NotificationRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package clap.server.adapter.outbound.persistense.repository.notification;
22

3+
import clap.server.adapter.outbound.persistense.entity.member.MemberEntity;
34
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
45
import org.springframework.data.domain.Pageable;
56
import org.springframework.data.domain.Slice;
@@ -15,4 +16,6 @@ public interface NotificationRepository extends JpaRepository<NotificationEntity
1516
Slice<NotificationEntity> findAllByReceiver_MemberIdOrderByCreatedAtDesc(Long receiverId, Pageable pageable);
1617

1718
List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);
19+
20+
Integer countByIsReadFalseAndReceiver_MemberId(Long memberId);
1821
}

src/main/java/clap/server/application/mapper/NotificationMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package clap.server.application.mapper;
22

33
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
4+
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
45
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
56
import clap.server.domain.model.notification.Notification;
67
import org.springframework.data.domain.Slice;
@@ -28,4 +29,11 @@ public static SliceResponse<FindNotificationListResponse> toSliceOfFindNoticeLis
2829
slice.isLast()
2930
);
3031
}
32+
33+
public static CountNotificationResponse toCountNotificationResponse(Long userId, Integer count) {
34+
return new CountNotificationResponse(
35+
userId,
36+
count
37+
);
38+
}
3139
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package clap.server.application.port.inbound.notification;
2+
3+
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
4+
5+
public interface CountNotificationUseCase {
6+
7+
CountNotificationResponse countNotification(Long userId);
8+
}

src/main/java/clap/server/application/port/outbound/notification/LoadNotificationPort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public interface LoadNotificationPort {
1515
SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
1616

1717
List<Notification> findNotificationsByMemberId(Long memberId);
18+
19+
Integer countNotification(Long memberId);
1820
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package clap.server.application.service.notification;
2+
3+
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
4+
import clap.server.application.mapper.NotificationMapper;
5+
import clap.server.application.port.inbound.notification.CountNotificationUseCase;
6+
import clap.server.application.port.outbound.notification.LoadNotificationPort;
7+
import clap.server.common.annotation.architecture.ApplicationService;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.transaction.annotation.Transactional;
10+
11+
@ApplicationService
12+
@Transactional(readOnly = true)
13+
@RequiredArgsConstructor
14+
public class CountNotificationService implements CountNotificationUseCase {
15+
16+
private final LoadNotificationPort loadNotificationPort;
17+
18+
@Transactional
19+
@Override
20+
public CountNotificationResponse countNotification(Long userId) {
21+
Integer count = loadNotificationPort.countNotification(userId);
22+
23+
return NotificationMapper.toCountNotificationResponse(userId, count);
24+
}
25+
}

0 commit comments

Comments
 (0)