From 0bc31eb6155c978b609b1f627632a64eaee30149 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Mon, 5 Feb 2024 18:44:58 +0900 Subject: [PATCH] =?UTF-8?q?[#119]=20refactor:=20=ED=91=B8=EC=8B=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B4=80=EB=A0=A8=20=EC=83=81=EC=88=98?= =?UTF-8?q?=EA=B0=92=20enum=EC=9C=BC=EB=A1=9C=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crew/main/common/response/ErrorStatus.java | 7 ++++++- .../main/entity/meeting/MeetingRepository.java | 4 +++- .../notification/PushNotificationEnums.java | 17 +++++++++++++++++ .../notification/PushNotificationService.java | 8 +++----- .../main/post/v2/service/PostV2ServiceImpl.java | 12 ++++++------ 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationEnums.java diff --git a/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java b/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java index be76a915..72c32673 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java +++ b/main/src/main/java/org/sopt/makers/crew/main/common/response/ErrorStatus.java @@ -6,19 +6,24 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) - public enum ErrorStatus { /** * 400 BAD_REQUEST */ VALIDATION_EXCEPTION("CR-001"), // errorCode는 예시, 추후 변경 예정 -> 잘못된 요청입니다. VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."), + NOT_FOUND_MEETING("모임이 없습니다."), /** * 401 UNAUTHORIZED */ UNAUTHORIZED_TOKEN("유효하지 않은 토큰입니다."), + /** + * 403 FORBIDDEN + */ + FORBIDDEN_EXCEPTION("권한이 없습니다."), + /** * 500 SERVER_ERROR */ diff --git a/main/src/main/java/org/sopt/makers/crew/main/entity/meeting/MeetingRepository.java b/main/src/main/java/org/sopt/makers/crew/main/entity/meeting/MeetingRepository.java index 18e30aff..e7804a6a 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/entity/meeting/MeetingRepository.java +++ b/main/src/main/java/org/sopt/makers/crew/main/entity/meeting/MeetingRepository.java @@ -1,5 +1,7 @@ package org.sopt.makers.crew.main.entity.meeting; +import static org.sopt.makers.crew.main.common.response.ErrorStatus.NOT_FOUND_MEETING; + import java.util.List; import java.util.Optional; import org.sopt.makers.crew.main.common.exception.BadRequestException; @@ -13,6 +15,6 @@ public interface MeetingRepository extends JpaRepository { default Meeting findByIdOrThrow(Integer meetingId) { return findById(meetingId) - .orElseThrow(() -> new BadRequestException("모임이 없습니다.")); + .orElseThrow(() -> new BadRequestException(NOT_FOUND_MEETING.getErrorCode())); } } diff --git a/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationEnums.java b/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationEnums.java new file mode 100644 index 00000000..46c6d533 --- /dev/null +++ b/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationEnums.java @@ -0,0 +1,17 @@ +package org.sopt.makers.crew.main.internal.notification; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public enum PushNotificationEnums { + PUSH_NOTIFICATION_ACTION("send"), + + PUSH_NOTIFICATION_CATEGORY("NEWS"), + + NEW_POST_PUSH_NOTIFICATION_TITLE("✏️내 모임에 새로운 글이 업로드됐어요."); + + private final String value; +} diff --git a/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationService.java b/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationService.java index 74519e62..f34cd9cd 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationService.java +++ b/main/src/main/java/org/sopt/makers/crew/main/internal/notification/PushNotificationService.java @@ -1,5 +1,7 @@ package org.sopt.makers.crew.main.internal.notification; +import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.PUSH_NOTIFICATION_ACTION; + import java.util.UUID; import lombok.RequiredArgsConstructor; import org.sopt.makers.crew.main.internal.notification.dto.PushNotificationRequestDto; @@ -11,8 +13,6 @@ @RequiredArgsConstructor public class PushNotificationService { - private static final String ACTION = "send"; - @Value("${push-notification.x-api-key}") private String pushNotificationApiKey; @@ -24,12 +24,10 @@ public class PushNotificationService { public void sendPushNotification(PushNotificationRequestDto request) { PushNotificationResponseDto response = pushServerClient.sendPushNotification( pushNotificationApiKey, - ACTION, + PUSH_NOTIFICATION_ACTION.getValue(), UUID.randomUUID().toString(), service, request ); - - System.out.println(response.getMessage()); } } diff --git a/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java b/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java index 24f6ae14..a00ae877 100644 --- a/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java +++ b/main/src/main/java/org/sopt/makers/crew/main/post/v2/service/PostV2ServiceImpl.java @@ -1,6 +1,9 @@ package org.sopt.makers.crew.main.post.v2.service; import static java.util.stream.Collectors.toList; +import static org.sopt.makers.crew.main.common.response.ErrorStatus.FORBIDDEN_EXCEPTION; +import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.NEW_POST_PUSH_NOTIFICATION_TITLE; +import static org.sopt.makers.crew.main.internal.notification.PushNotificationEnums.PUSH_NOTIFICATION_CATEGORY; import java.util.List; import lombok.RequiredArgsConstructor; @@ -35,9 +38,6 @@ public class PostV2ServiceImpl implements PostV2Service { @Value("${push-notification.web-url}") private String pushWebUrl; - private static final String NEW_POST_PUSH_NOTIFICATION_TITLE = "✏️내 모임에 새로운 글이 업로드됐어요."; - private static final String PUSH_NOTIFICATION_CATEGORY = "NEWS"; - /** * 모임 게시글 작성 * @@ -58,7 +58,7 @@ public PostV2CreatePostResponseDto createPost(PostV2CreatePostBodyDto requestBod boolean isMeetingCreator = meeting.getUserId().equals(userId); if (isInMeeting == false && isMeetingCreator == false) { - throw new ForbiddenException("권한이 없습니다."); + throw new ForbiddenException(FORBIDDEN_EXCEPTION.getErrorCode()); } Post post = Post.builder() @@ -83,9 +83,9 @@ public PostV2CreatePostResponseDto createPost(PostV2CreatePostBodyDto requestBod String pushNotificationWeblink = pushWebUrl + "/detail?id=" + meeting.getId(); PushNotificationRequestDto pushRequestDto = PushNotificationRequestDto.of(userIds, - NEW_POST_PUSH_NOTIFICATION_TITLE, + NEW_POST_PUSH_NOTIFICATION_TITLE.getValue(), pushNotificationContent, - PUSH_NOTIFICATION_CATEGORY, pushNotificationWeblink); + PUSH_NOTIFICATION_CATEGORY.getValue(), pushNotificationWeblink); pushNotificationService.sendPushNotification(pushRequestDto);