diff --git a/.github/workflows/main-api-deploy.yml b/.github/workflows/main-api-deploy.yml index 60246c1fe..af74cd970 100644 --- a/.github/workflows/main-api-deploy.yml +++ b/.github/workflows/main-api-deploy.yml @@ -21,6 +21,6 @@ jobs: port: ${{ secrets.MAIN_API_SSH_PORT }} script: | cd /home/whozin/Whoz-in-BE/modules/main-api/docker # 프로젝트 폴더로 이동 - git switch develop # develop 브랜치로 이동 - git pull origin develop # 최신 코드 가져오기 + git fetch origin # branch 이력 가져오기 + git reset --hard origin/develop # develop branch로 이동 ./build-and-deploy.sh # 배포 스크립트 실행 \ No newline at end of file diff --git a/.github/workflows/network-api-deploy.yml b/.github/workflows/network-api-deploy.yml index 5da07b1fd..09c289f42 100644 --- a/.github/workflows/network-api-deploy.yml +++ b/.github/workflows/network-api-deploy.yml @@ -20,7 +20,7 @@ jobs: password: ${{ secrets.NETWORK_API_PASSWORD }} port: ${{ secrets.NETWORK_API_SSH_PORT }} script: | - cd /home/whozin/Whoz-in-BE/modules/network-api/docker # ???? ??? ?? - git switch develop # develop ???? ?? - git pull origin develop # ?? ?? ???? - ./build-and-deploy.sh # ?? ???? ?? \ No newline at end of file + cd /home/whozin/Whoz-in-BE/modules/main-api/docker # 프로젝트 폴더로 이동 + git fetch origin # branch 이력 가져오기 + git reset --hard origin/develop # develop branch로 이동 + ./build-and-deploy.sh # 배포 스크립트 실행 \ No newline at end of file diff --git a/modules/domain/src/main/java/com/whoz_in/domain/device/event/DeviceDeleted.java b/modules/domain/src/main/java/com/whoz_in/domain/device/event/DeviceDeleted.java new file mode 100644 index 000000000..cb35af4f7 --- /dev/null +++ b/modules/domain/src/main/java/com/whoz_in/domain/device/event/DeviceDeleted.java @@ -0,0 +1,14 @@ +package com.whoz_in.domain.device.event; + +import com.whoz_in.domain.shared.event.DomainEvent; +import java.util.UUID; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public final class DeviceDeleted extends DomainEvent { + + private final UUID deviceId; + +} diff --git a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/ActiveDeviceRepository.java b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/ActiveDeviceRepository.java index fa525144a..d558992e5 100644 --- a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/ActiveDeviceRepository.java +++ b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/ActiveDeviceRepository.java @@ -17,8 +17,6 @@ public interface ActiveDeviceRepository extends JpaRepository findByDeviceId(UUID deviceId); - void deleteByDeviceId(UUID deviceId); - boolean existsByDeviceId(UUID deviceId); } diff --git a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/event/ActiveDeviceDeletedEventHandler.java b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/event/ActiveDeviceDeletedEventHandler.java new file mode 100644 index 000000000..6a9b3a383 --- /dev/null +++ b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/device/active/event/ActiveDeviceDeletedEventHandler.java @@ -0,0 +1,22 @@ +package com.whoz_in.api_query_jpa.device.active.event; + +import com.whoz_in.api_query_jpa.device.active.ActiveDeviceRepository; +import com.whoz_in.main_api.shared.domain.device.active.event.DeviceDeletedEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component("ActiveDeviceDeletedEventHandler") +@RequiredArgsConstructor +public class ActiveDeviceDeletedEventHandler { + + private final ActiveDeviceRepository activeDeviceRepository; + + @Transactional + @EventListener(DeviceDeletedEvent.class) + public void handle(DeviceDeletedEvent event) { + activeDeviceRepository.deleteById(event.deviceId()); + } + +} diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceRemoveHandler.java b/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceRemoveHandler.java index 583a3c8b7..b2e80e945 100644 --- a/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceRemoveHandler.java +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/command/device/application/DeviceRemoveHandler.java @@ -1,10 +1,14 @@ package com.whoz_in.main_api.command.device.application; import com.whoz_in.domain.device.DeviceRepository; +import com.whoz_in.domain.device.event.DeviceDeleted; +import com.whoz_in.domain.device.model.Device; import com.whoz_in.domain.member.service.MemberFinderService; +import com.whoz_in.domain.shared.event.EventBus; import com.whoz_in.main_api.command.shared.application.CommandHandler; import com.whoz_in.main_api.shared.application.Handler; import com.whoz_in.main_api.shared.utils.RequesterInfo; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -14,12 +18,14 @@ public class DeviceRemoveHandler implements CommandHandler { private final RequesterInfo requesterInfo; private final MemberFinderService memberFinderService; private final DeviceRepository deviceRepository; + private final EventBus eventBus; @Transactional @Override public Void handle(DeviceRemove command) { memberFinderService.mustExist(requesterInfo.getMemberId()); deviceRepository.delete(command.getDeviceId()); + eventBus.publish(List.of(new DeviceDeleted(command.getDeviceId().id()))); return null; } } diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEvent.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEvent.java new file mode 100644 index 000000000..42292849e --- /dev/null +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEvent.java @@ -0,0 +1,10 @@ +package com.whoz_in.main_api.shared.domain.device.active.event; + +import com.whoz_in.main_api.shared.event.ApplicationEvent; +import java.util.UUID; + +public record DeviceDeletedEvent( + UUID deviceId +) + implements ApplicationEvent { +} diff --git a/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEventHandler.java b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEventHandler.java new file mode 100644 index 000000000..347576bf7 --- /dev/null +++ b/modules/main-api/src/main/java/com/whoz_in/main_api/shared/domain/device/active/event/DeviceDeletedEventHandler.java @@ -0,0 +1,20 @@ +package com.whoz_in.main_api.shared.domain.device.active.event; + +import com.whoz_in.domain.device.event.DeviceDeleted; +import com.whoz_in.main_api.shared.event.Events; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionalEventListener; + +@Component +@RequiredArgsConstructor +public class DeviceDeletedEventHandler { + + @TransactionalEventListener(DeviceDeleted.class) + public void processDeviceDeletedEvent(DeviceDeleted event) { + UUID deviceId = event.getDeviceId(); + + Events.raise(new DeviceDeletedEvent(deviceId)); + } +}