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,13 @@
package clap.server.adapter.inbound.web.dto.common;


import java.util.List;

public record SliceResponse<T> (
List<T> content,
int currentPage,
int size,
boolean isFirst,
boolean isLast
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clap.server.adapter.inbound.web.notification;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
Expand All @@ -9,7 +10,6 @@
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
Expand All @@ -34,7 +34,7 @@ public class FindNotificationController {
@Parameter(name = "size", description = "조회할 목록 페이지 당 개수", example = "5", required = false)
})
@GetMapping
public ResponseEntity<Page<FindNotificationListResponse>> findNotificationList(
public ResponseEntity<SliceResponse<FindNotificationListResponse>> findNotificationList(
@AuthenticationPrincipal SecurityUserDetails securityUserDetails,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package clap.server.adapter.inbound.web.notification;

import clap.server.adapter.inbound.security.SecurityUserDetails;
import clap.server.application.port.inbound.notification.UpdateNotificationUsecase;
import clap.server.common.annotation.architecture.WebAdapter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -27,4 +29,10 @@ public class ManagementNotificationController {
public void updateNotificationIsRead(@PathVariable Long notificationId) {
updateNotificationUsecase.updateNotification(notificationId);
}

@Operation(summary = "알림 목록에서 전체 읽음 버튼을 눌렀을 때 전체 읽음 처리")
@PatchMapping
public void updateAllNotificationIsRead(@AuthenticationPrincipal SecurityUserDetails userInfo) {
updateNotificationUsecase.updateAllNotification(userInfo.getUserId());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package clap.server.adapter.outbound.persistense;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.adapter.outbound.persistense.mapper.NotificationPersistenceMapper;
import clap.server.adapter.outbound.persistense.repository.notification.NotificationRepository;
Expand All @@ -9,11 +10,12 @@
import clap.server.common.annotation.architecture.PersistenceAdapter;
import clap.server.domain.model.notification.Notification;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@PersistenceAdapter
@RequiredArgsConstructor
Expand All @@ -30,10 +32,21 @@ public Optional<Notification> findById(Long notificationId) {
}

@Override
public Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
Page<Notification> notificationList = notificationRepository.findAllByReceiver_MemberId(receiverId, pageable)
public SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable) {
Slice<Notification> notificationList = notificationRepository
.findAllByReceiver_MemberIdOrderByCreatedAtDesc(receiverId, pageable)
.map(notificationPersistenceMapper::toDomain);
return notificationList.map(NotificationMapper::toFindNoticeListResponse);

return NotificationMapper.toSliceOfFindNoticeListResponse(
notificationList.map(NotificationMapper::toFindNoticeListResponse)
);
}

@Override
public List<Notification> findNotificationsByMemberId(Long memberId) {
return notificationRepository.findAllByReceiver_MemberId(memberId)
.stream().map(notificationPersistenceMapper::toDomain)
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package clap.server.adapter.outbound.persistense.repository.notification;

import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface NotificationRepository extends JpaRepository<NotificationEntity, Long> {

Page<NotificationEntity> findAllByReceiver_MemberId(Long receiverId, Pageable pageable);
Slice<NotificationEntity> findAllByReceiver_MemberIdOrderByCreatedAtDesc(Long receiverId, Pageable pageable);

List<NotificationEntity> findAllByReceiver_MemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package clap.server.application.mapper;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.domain.model.notification.Notification;
import org.springframework.data.domain.Slice;

public class NotificationMapper {
private NotificationMapper() {throw new IllegalArgumentException();}
Expand All @@ -17,4 +19,14 @@ public static FindNotificationListResponse toFindNoticeListResponse(Notification
notification.getCreatedAt()
);
}

public static SliceResponse<FindNotificationListResponse> toSliceOfFindNoticeListResponse(Slice<FindNotificationListResponse> slice) {
return new SliceResponse<>(
slice.getContent(),
slice.getNumber(),
slice.getSize(),
slice.isFirst(),
slice.isLast()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package clap.server.application.port.inbound.notification;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface FindNotificationListUsecase {
Page<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable);
SliceResponse<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface UpdateNotificationUsecase {
void updateNotification(Long notificationId);

void updateAllNotification(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package clap.server.application.port.outbound.notification;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.adapter.outbound.persistense.entity.notification.NotificationEntity;
import clap.server.domain.model.notification.Notification;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;

Expand All @@ -14,5 +12,7 @@ public interface LoadNotificationPort {

Optional<Notification> findById(Long notificationId);

Page<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);
SliceResponse<FindNotificationListResponse> findAllByReceiverId(Long receiverId, Pageable pageable);

List<Notification> findNotificationsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package clap.server.application.service.notification;

import clap.server.adapter.inbound.web.dto.common.SliceResponse;
import clap.server.adapter.inbound.web.dto.notification.FindNotificationListResponse;
import clap.server.application.port.inbound.notification.FindNotificationListUsecase;
import clap.server.application.port.outbound.notification.LoadNotificationPort;
import clap.server.common.annotation.architecture.ApplicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -18,7 +18,7 @@ public class FindNotificationListService implements FindNotificationListUsecase


@Override
public Page<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable) {
public SliceResponse<FindNotificationListResponse> findNotificationList(Long receiverId, Pageable pageable) {
return loadNotificationPort.findAllByReceiverId(receiverId, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@ApplicationService
@RequiredArgsConstructor
public class ReadNotificationService implements UpdateNotificationUsecase {
Expand All @@ -26,4 +28,14 @@ public void updateNotification(Long notificationId) {
notification.updateNotificationIsRead();
commandNotificationPort.save(notification);
}

@Transactional
@Override
public void updateAllNotification(Long memberId) {
List<Notification> notificationList = loadNotificationPort.findNotificationsByMemberId(memberId);
for (Notification notification : notificationList) {
notification.updateNotificationIsRead();
commandNotificationPort.save(notification);
}
}
}

This file was deleted.

Loading