Skip to content

Commit

Permalink
feat: 메인 페이지에서 모든 알림 읽었는지 확인하는 API 추가 #207
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbonai06 committed Sep 8, 2022
1 parent 8ecdb78 commit 683eeb8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.AllSendNotificationDTO;
import com.ceos.bankids.dto.NotificationDTO;
import com.ceos.bankids.dto.NotificationIsReadDTO;
import com.ceos.bankids.dto.NotificationListDTO;
import com.ceos.bankids.exception.ForbiddenException;
import com.ceos.bankids.repository.NotificationRepository;
Expand Down Expand Up @@ -85,6 +86,18 @@ public CommonResponse<NotificationListDTO> getNotificationList(
return CommonResponse.onSuccess(notificationListDTOS);
}

@ApiOperation(value = "유저 안읽은 알림 있는지 확인")
@GetMapping(value = "/isRead", produces = "application/json; charset=utf-8")
public CommonResponse<NotificationIsReadDTO> getNotificationIsAllRead(
@AuthenticationPrincipal User authUser) {

log.info("api = 안읽은 알림 있는지 확인 user = {}", authUser.getId());
NotificationIsReadDTO notificationIsReadDTO = expoNotificationService.readNotificationIsAllRead(
authUser);
return CommonResponse.onSuccess(notificationIsReadDTO);
}


@ApiOperation(value = "유저 알림 읽음 확인")
@PatchMapping(value = "/{notificationId}", produces = "application/json; charset=utf-8")
public CommonResponse<NotificationDTO> patchNotification(@AuthenticationPrincipal User authUser,
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/ceos/bankids/dto/NotificationIsReadDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ceos.bankids.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@ApiModel(value = "읽지 않은 알림 확인 DTO")
@Getter
@ToString
@EqualsAndHashCode
public class NotificationIsReadDTO {

@ApiModelProperty(example = "true")
private Boolean isAllRead;

public NotificationIsReadDTO(Boolean isAllRead) {
this.isAllRead = isAllRead;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.NotificationDTO;
import com.ceos.bankids.dto.NotificationIsReadDTO;
import com.ceos.bankids.dto.NotificationListDTO;
import org.springframework.stereotype.Service;

Expand All @@ -11,4 +12,6 @@ public interface ExpoNotificationService {
public NotificationListDTO readNotificationList(User user, Long lastId);

public NotificationDTO updateNotification(User user, Long notificationId);

public NotificationIsReadDTO readNotificationIsAllRead(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ceos.bankids.domain.Notification;
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.NotificationDTO;
import com.ceos.bankids.dto.NotificationIsReadDTO;
import com.ceos.bankids.dto.NotificationListDTO;
import com.ceos.bankids.exception.BadRequestException;
import com.ceos.bankids.exception.ForbiddenException;
Expand Down Expand Up @@ -87,6 +88,21 @@ public NotificationDTO updateNotification(User user, Long notificationId) {
return new NotificationDTO(notification);
}

@Transactional(readOnly = true)
@Override
public NotificationIsReadDTO readNotificationIsAllRead(User user) {

List<Notification> notificationList = notificationRepository.findAllByUserId(user.getId())
.stream()
.filter(notification -> !notification.getIsRead()).collect(
Collectors.toList());
if (notificationList.size() == 0) {
return new NotificationIsReadDTO(true);
} else {
return new NotificationIsReadDTO(false);
}
}

@Transactional
public void deleteAllNotification(User user) {
notificationRepository.deleteAllByUserId(user.getId());
Expand Down

0 comments on commit 683eeb8

Please sign in to comment.