Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Hexagonal architecture #129 #131

Merged
merged 26 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
512be8f
setting(archUnit): 아키텍처 테스팅 의존성 추가
zbqmgldjfh Jan 25, 2024
f7e9215
test(HexagonalArchitecture): User의 HexagonalArchitecture 검증
zbqmgldjfh Jan 25, 2024
8a3ccf0
refactor: User 도메인 헥사고날 아키텍처로 전환
zbqmgldjfh Jan 25, 2024
adf64bd
feat: 헥사고날 애너테이션 적용
zbqmgldjfh Jan 25, 2024
9e07ad5
refactor: API가 포트에 의존하도록 변경
zbqmgldjfh Jan 25, 2024
620f216
refactor: UseCase의 구현체들이 Port에 의존하도록 리팩토링
zbqmgldjfh Jan 26, 2024
1d2f265
test: Notice의 HexagonalArchitecture 검증
zbqmgldjfh Jan 27, 2024
3526121
refactor: Notice 도메인 헥사고날 아키텍처로 전환
zbqmgldjfh Jan 27, 2024
ad66633
test: Admin의 HexagonalArchitecture 검증
zbqmgldjfh Jan 27, 2024
81acd1d
refactor(NoticeUpdateSupport): NoticeUpdateSupport 일부 로직 수정
zbqmgldjfh Jan 27, 2024
f044a36
refactor: Admin 도메인 헥사고날 아키텍처로 전환
zbqmgldjfh Jan 27, 2024
9d5562f
refactor: 필요없는 설정파일 삭제
zbqmgldjfh Jan 27, 2024
b0c018d
test: Staff의 HexagonalArchitecture 검증
zbqmgldjfh Jan 27, 2024
21be0e4
refactor: Staff 도메인 헥사고날 아키텍처로 전환
zbqmgldjfh Jan 27, 2024
bd81c16
feat: User 도메인의 Firebase 로직을 Event로 처리하도록 구현
zbqmgldjfh Feb 2, 2024
63046d3
feat: User-Token을 preHandler로 검증하도록 변경
zbqmgldjfh Feb 2, 2024
01e6cc5
feat(MessageUserEventListener): Token Validation 리스너 제거
zbqmgldjfh Feb 2, 2024
5f7c57c
feat(FirebaseService): 비즈니스 로직이 port에 의존하도록 리팩토링
zbqmgldjfh Feb 2, 2024
a29edc2
feat(FirebaseWithAdminUseCase): 어드민의 공지 전송 작업을 이벤트로 구현
zbqmgldjfh Feb 2, 2024
c363ac8
refactor: 기존의 단일 FirebaseService 를 구독과 공지 전송 2개의 서비스로 분리한다
zbqmgldjfh Feb 2, 2024
b74fcb0
refactor(DependencyRuleTests): 기존 아키텍처 검증에서 event 페키지 추가 검증하도록 구현
zbqmgldjfh Feb 2, 2024
0731935
fix: QueryDsl이 사용하는 dto의 경로 재설정
zbqmgldjfh Feb 2, 2024
a7711f6
chore: 테스트 서식 지정자 제거와 주석 제거
zbqmgldjfh Feb 2, 2024
bef0d70
docs(README): 문서 업데이트
zbqmgldjfh Feb 2, 2024
184e0b6
refactor(ServerProperties): 공통으로 사용중인 서버의 환경변수를 Common 패키지 하부로 이동
zbqmgldjfh Feb 4, 2024
b03e8d2
refactor(FirebaseExceptionHandler): exception handler의 페키지를 adapter.o…
zbqmgldjfh Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(FirebaseService): 비즈니스 로직이 port에 의존하도록 리팩토링
zbqmgldjfh committed Feb 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 5f7c57c5e37c39903d6dffe83f054a639b894ab2
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.kustacks.kuring.message.adapter.out.firebase;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseToken;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.TopicManagementResponse;
import com.kustacks.kuring.message.application.port.out.FirebaseAuthPort;
import com.kustacks.kuring.message.application.port.out.FirebaseMessagingPort;
import com.kustacks.kuring.message.application.port.out.FirebaseSubscribePort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class FirebaseAdapter implements FirebaseSubscribePort, FirebaseAuthPort, FirebaseMessagingPort {

private final FirebaseMessaging firebaseMessaging;
private final FirebaseAuth firebaseAuth;

@Override
public FirebaseToken verifyIdToken(String idToken) throws FirebaseAuthException {
return firebaseAuth.verifyIdToken(idToken);
}

@Override
public TopicManagementResponse subscribeToTopic(
List<String> tokens,
String topic
) throws FirebaseMessagingException {
return firebaseMessaging.subscribeToTopic(tokens, topic);
}

@Override
public TopicManagementResponse unsubscribeFromTopic(
List<String> tokens,
String topic
) throws FirebaseMessagingException {
return firebaseMessaging.unsubscribeFromTopic(tokens, topic);
}

@Override
public String send(Message message) throws FirebaseMessagingException {
return firebaseMessaging.send(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kustacks.kuring.message.application.port.out;

import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseToken;

public interface FirebaseAuthPort {
FirebaseToken verifyIdToken(String idToken) throws FirebaseAuthException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kustacks.kuring.message.application.port.out;

import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;

public interface FirebaseMessagingPort {
String send(Message message) throws FirebaseMessagingException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kustacks.kuring.message.application.port.out;

import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.TopicManagementResponse;

import java.util.List;

public interface FirebaseSubscribePort {
TopicManagementResponse subscribeToTopic(List<String> tokens, String topic) throws FirebaseMessagingException;
TopicManagementResponse unsubscribeFromTopic(List<String> tokens, String topic) throws FirebaseMessagingException;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.kustacks.kuring.message.application.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.messaging.*;
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.google.firebase.messaging.TopicManagementResponse;
import com.kustacks.kuring.admin.application.port.out.dto.AdminNotificationDto;
import com.kustacks.kuring.common.annotation.UseCase;
import com.kustacks.kuring.common.exception.InternalLogicException;
import com.kustacks.kuring.common.exception.code.ErrorCode;
import com.kustacks.kuring.message.application.port.in.FirebaseWithUserUseCase;
import com.kustacks.kuring.message.application.port.in.dto.UserSubscribeCommand;
import com.kustacks.kuring.message.application.port.in.dto.UserUnsubscribeCommand;
import com.kustacks.kuring.message.application.port.out.FirebaseAuthPort;
import com.kustacks.kuring.message.application.port.out.FirebaseMessagingPort;
import com.kustacks.kuring.message.application.port.out.FirebaseSubscribePort;
import com.kustacks.kuring.message.application.port.out.dto.NoticeMessageDto;
import com.kustacks.kuring.message.application.service.exception.FirebaseInvalidTokenException;
import com.kustacks.kuring.message.application.service.exception.FirebaseMessageSendException;
@@ -18,29 +24,29 @@
import com.kustacks.kuring.notice.domain.Notice;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Slf4j
@Service
@UseCase
@RequiredArgsConstructor
public class FirebaseService implements FirebaseWithUserUseCase {

private static final String NOTIFICATION_TITLE = "새로운 공지가 왔어요!";
public static final String ALL_DEVICE_SUBSCRIBED_TOPIC = "allDevice";

private final FirebaseMessaging firebaseMessaging;
private final ObjectMapper objectMapper;
private final FirebaseSubscribePort firebaseSubscribePort;
private final FirebaseMessagingPort firebaseMessagingPort;
private final FirebaseAuthPort firebaseAuthPort;
private final ServerProperties serverProperties;
private final FirebaseAuth firebaseAuth;
private final ObjectMapper objectMapper;

@Override
public void validationToken(String token) throws FirebaseInvalidTokenException {
try {
firebaseAuth.verifyIdToken(token);
firebaseAuthPort.verifyIdToken(token);
} catch (FirebaseAuthException e) {
throw new FirebaseInvalidTokenException();
}
@@ -49,8 +55,11 @@ public void validationToken(String token) throws FirebaseInvalidTokenException {
@Override
public void subscribe(UserSubscribeCommand command) throws FirebaseSubscribeException {
try {
TopicManagementResponse response = firebaseMessaging
.subscribeToTopic(List.of(command.token()), serverProperties.ifDevThenAddSuffix(command.topic()));
TopicManagementResponse response = firebaseSubscribePort
.subscribeToTopic(
List.of(command.token()),
serverProperties.ifDevThenAddSuffix(command.topic())
);

if (response.getFailureCount() > 0) {
throw new FirebaseSubscribeException();
@@ -63,7 +72,7 @@ public void subscribe(UserSubscribeCommand command) throws FirebaseSubscribeExce
@Override
public void unsubscribe(UserUnsubscribeCommand command) throws FirebaseUnSubscribeException {
try {
TopicManagementResponse response = firebaseMessaging
TopicManagementResponse response = firebaseSubscribePort
.unsubscribeFromTopic(List.of(command.token()), serverProperties.ifDevThenAddSuffix(command.topic()));

if (response.getFailureCount() > 0) {
@@ -107,7 +116,7 @@ public void sendNotificationByAdmin(AdminNotificationDto messageDto) {
.setTopic(serverProperties.ifDevThenAddSuffix(ALL_DEVICE_SUBSCRIBED_TOPIC))
.build();

firebaseMessaging.send(newMessage);
firebaseMessagingPort.send(newMessage);
} catch (FirebaseMessagingException exception) {
throw new FirebaseMessageSendException();
}
@@ -144,7 +153,7 @@ private void sendBaseNotification(NoticeMessageDto messageDto, Function<String,
.setTopic(suffixUtil.apply(messageDto.getCategory()))
.build();

firebaseMessaging.send(newMessage);
firebaseMessagingPort.send(newMessage);
} catch (FirebaseMessagingException exception) {
throw new FirebaseMessageSendException();
}