Skip to content

Commit

Permalink
refactor: 이전 버전 지원, 함수 중복 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyu0218 committed Dec 19, 2024
1 parent 44d1a00 commit 2c0eb79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public void sendIndividualNotification(String title, String body, String token)
.setToken(token)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE);
}

public void sendGroupNotification(String title, String body, String topic) {
Expand All @@ -35,11 +31,7 @@ public void sendGroupNotification(String title, String body, String topic) {
.setTopic(topic)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE);
}

public void sendIndividualData(Map<String, String> data, String token) {
Expand All @@ -48,11 +40,7 @@ public void sendIndividualData(Map<String, String> data, String token) {
.setToken(token)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE);
}

public void sendGroupData(Map<String, String> data, String topic) {
Expand All @@ -61,11 +49,7 @@ public void sendGroupData(Map<String, String> data, String topic) {
.setTopic(topic)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE);
}

public void sendIndividualNotificationWithData(String title, String body, Map<String, String> data, String token) {
Expand All @@ -76,11 +60,7 @@ public void sendIndividualNotificationWithData(String title, String body, Map<St
.setToken(token)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_INDIVIDUAL_MESSAGE);
}

public void sendGroupNotificationWithData(String title, String body, Map<String, String> data, String topic) {
Expand All @@ -91,11 +71,7 @@ public void sendGroupNotificationWithData(String title, String body, Map<String,
.setTopic(topic)
.build();

try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE, e);
}
sendMessage(message, ErrorCode.FAILED_TO_SEND_GROUP_MESSAGE);
}

private Notification makeNotification(final String title, final String body) {
Expand All @@ -104,4 +80,12 @@ private Notification makeNotification(final String title, final String body) {
.setBody(body)
.build();
}

private void sendMessage(final Message message, final ErrorCode errorCode) {
try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
throw new BaseException(errorCode, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
public record AppleLoginRequest(
@Schema(description = "애플 ID 토큰", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty String identityToken,
// TODO: 추후 NotEmpty 변경
// 이전 버전 지원을 위해 @NotEmpty 붙이지 않음
@Schema(description = "디바이스 식별자", requiredMode = Schema.RequiredMode.REQUIRED)
String deviceIdentifier
) {

public AppleLoginCommand toServiceDto() {
// TODO: 추후 삭제
if (deviceIdentifier == null) {
return new AppleLoginCommand(identityToken, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
public record GoogleLoginRequest(
@Schema(description = "구글 이메일", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty String email,
// 이전 버전 지원을 위해 @NotEmpty 붙이지 않음
@Schema(description = "디바이스 식별자", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty String deviceIdentifier
String deviceIdentifier
) {

public GoogleLoginCommand toServiceDto() {
if (deviceIdentifier == null) {
return new GoogleLoginCommand(email, "");
}
return new GoogleLoginCommand(email, deviceIdentifier);
}
}

0 comments on commit 2c0eb79

Please sign in to comment.