Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clap.server.adapter.inbound.web.dto.notification;

public record CountNotificationResponse(
Long memberId,
Integer count
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.application.port.inbound.notification.CountNotificationUseCase;
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -27,6 +29,7 @@
public class FindNotificationController {

private final FindNotificationListUsecase findNotificationListUsecase;
private final CountNotificationUseCase countNotificationUseCase;

@Operation(summary = "알림 목록 조회 API")
@Parameters({
Expand All @@ -41,4 +44,11 @@ public ResponseEntity<SliceResponse<FindNotificationListResponse>> findNotificat
Pageable pageable = PageRequest.of(page, size);
return ResponseEntity.ok(findNotificationListUsecase.findNotificationList(securityUserDetails.getUserId(), pageable));
}

@Operation(summary = "미확인 알림 개수 조회 API")
@GetMapping("/count")
public ResponseEntity<CountNotificationResponse> countNotification(
@AuthenticationPrincipal SecurityUserDetails userInfo) {
return ResponseEntity.ok(countNotificationUseCase.countNotification(userInfo.getUserId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public List<Notification> findNotificationsByMemberId(Long memberId) {
.collect(Collectors.toList());
}

@Override
public Integer countNotification(Long memberId) {
return notificationRepository.countByIsReadFalseAndReceiver_MemberId(memberId);
}

@Override
public void save(Notification notification) {
notificationRepository.save(notificationPersistenceMapper.toEntity(notification));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package clap.server.adapter.outbound.persistense.repository.notification;

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

List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);

Integer countByIsReadFalseAndReceiver_MemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clap.server.application.mapper;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.domain.model.notification.Notification;
import org.springframework.data.domain.Slice;
Expand Down Expand Up @@ -28,4 +29,11 @@ public static SliceResponse<FindNotificationListResponse> toSliceOfFindNoticeLis
slice.isLast()
);
}

public static CountNotificationResponse toCountNotificationResponse(Long userId, Integer count) {
return new CountNotificationResponse(
userId,
count
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package clap.server.application.port.inbound.notification;

import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;

public interface CountNotificationUseCase {

CountNotificationResponse countNotification(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface LoadNotificationPort {
SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);

List<Notification> findNotificationsByMemberId(Long memberId);

Integer countNotification(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package clap.server.application.service.notification;

import clap.server.adapter.inbound.web.dto.notification.CountNotificationResponse;
import clap.server.application.mapper.NotificationMapper;
import clap.server.application.port.inbound.notification.CountNotificationUseCase;
import clap.server.application.port.outbound.notification.LoadNotificationPort;
import clap.server.common.annotation.architecture.ApplicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@ApplicationService
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class CountNotificationService implements CountNotificationUseCase {

private final LoadNotificationPort loadNotificationPort;

@Transactional
@Override
public CountNotificationResponse countNotification(Long userId) {
Integer count = loadNotificationPort.countNotification(userId);

return NotificationMapper.toCountNotificationResponse(userId, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.notification.Notification;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@ApplicationService
@RequiredArgsConstructor
public class CreateNotificationService{

private final CommandNotificationPort commandNotificationPort;

@Transactional
public void createNotification(Notification request) {

commandNotificationPort.save(request);
Expand Down
Loading