From be9953a95915debab4f22244b16c0deb410e216b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A4=80?= Date: Sun, 11 Sep 2022 20:38:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20notice=20/=20notification=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=80=EC=9E=A5=EB=90=A0=20=EB=95=8C=20url=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bankids/controller/NoticeController.java | 8 +++++--- .../controller/NotificationController.java | 18 +++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ceos/bankids/controller/NoticeController.java b/src/main/java/com/ceos/bankids/controller/NoticeController.java index 719a1091..08de0d9d 100644 --- a/src/main/java/com/ceos/bankids/controller/NoticeController.java +++ b/src/main/java/com/ceos/bankids/controller/NoticeController.java @@ -1,11 +1,13 @@ package com.ceos.bankids.controller; import com.ceos.bankids.config.CommonResponse; +import com.ceos.bankids.constant.ErrorCode; import com.ceos.bankids.controller.request.NoticeRequest; import com.ceos.bankids.domain.User; import com.ceos.bankids.dto.AllSendNotificationDTO; import com.ceos.bankids.dto.NoticeDTO; import com.ceos.bankids.dto.NoticeListDTO; +import com.ceos.bankids.exception.ForbiddenException; import com.ceos.bankids.service.NoticeServiceImpl; import io.swagger.annotations.ApiOperation; import java.util.HashMap; @@ -35,9 +37,9 @@ public CommonResponse postNotice(@AuthenticationPrincipal User authUs @RequestBody NoticeRequest noticeRequest) { log.info("api = 공지사항 작성"); -// if (authUser.getId() != 1L) { -// throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode()); -// } + if (authUser.getId() != 1L) { + throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode()); + } String title = noticeRequest.getTitle(); String body = noticeRequest.getBody(); String message = noticeRequest.getMessage(); diff --git a/src/main/java/com/ceos/bankids/controller/NotificationController.java b/src/main/java/com/ceos/bankids/controller/NotificationController.java index acb7b2c1..46258a9a 100644 --- a/src/main/java/com/ceos/bankids/controller/NotificationController.java +++ b/src/main/java/com/ceos/bankids/controller/NotificationController.java @@ -2,6 +2,7 @@ import com.ceos.bankids.config.CommonResponse; import com.ceos.bankids.constant.ChallengeStatus; +import com.ceos.bankids.constant.ErrorCode; import com.ceos.bankids.constant.NotificationCategory; import com.ceos.bankids.domain.Challenge; import com.ceos.bankids.domain.ChallengeUser; @@ -12,10 +13,10 @@ 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; import com.ceos.bankids.repository.UserRepository; import com.ceos.bankids.service.ExpoNotificationServiceImpl; -import com.ceos.bankids.service.NoticeServiceImpl; import io.swagger.annotations.ApiOperation; import java.util.HashMap; import java.util.List; @@ -39,7 +40,6 @@ public class NotificationController { private final ExpoNotificationServiceImpl expoNotificationService; - private final NoticeServiceImpl noticeService; private final UserRepository userRepository; private final NotificationRepository notificationRepository; @@ -49,9 +49,9 @@ public CommonResponse allSendNotification( @RequestBody AllSendNotificationDTO allSendNotificationRequest, @AuthenticationPrincipal User authUser) { -// if (authUser.getId() != 1L) { -// throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode()); -// } + if (authUser.getId() != 1L) { + throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode()); + } String title = allSendNotificationRequest.getTitle(); String message = allSendNotificationRequest.getMessage(); @@ -62,10 +62,14 @@ public CommonResponse allSendNotification( if (user.getNoticeOptIn() && user.getExpoToken() .startsWith("ExponentPushToken")) { expoNotificationService.sendMessage(user, title, message, - allSendNotificationRequest.getNewMap(), notificationCategory, "/"); + allSendNotificationRequest.getNewMap(), notificationCategory, + "/manage/notices/" + allSendNotificationRequest.getNewMap() + .get("noticeId")); } else { Notification notification = Notification.builder().user(user).title(title) - .message(message).notificationCategory(notificationCategory).linkUrl("/") + .message(message).notificationCategory(notificationCategory) + .linkUrl("/manage/notices/" + allSendNotificationRequest.getNewMap() + .get("noticeId")) .build(); notificationRepository.save(notification); }