Skip to content

Commit

Permalink
[#119] refactor: 푸시 알림 관련 상수값 enum으로 선언
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Feb 6, 2024
1 parent 778af99 commit 0bc31eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +15,6 @@ public interface MeetingRepository extends JpaRepository<Meeting, Integer> {

default Meeting findByIdOrThrow(Integer meetingId) {
return findById(meetingId)
.orElseThrow(() -> new BadRequestException("모임이 없습니다."));
.orElseThrow(() -> new BadRequestException(NOT_FOUND_MEETING.getErrorCode()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,8 +13,6 @@
@RequiredArgsConstructor
public class PushNotificationService {

private static final String ACTION = "send";

@Value("${push-notification.x-api-key}")
private String pushNotificationApiKey;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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";

/**
* 모임 게시글 작성
*
Expand All @@ -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()
Expand All @@ -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);

Expand Down

0 comments on commit 0bc31eb

Please sign in to comment.