Skip to content

Commit

Permalink
Merge pull request #237 from JNU-econovation/feat/remove-active-device
Browse files Browse the repository at this point in the history
[FEAT] Active Device 삭제 기능
  • Loading branch information
rlajm1203 authored Mar 1, 2025
2 parents 226fec0 + c063f75 commit 46fec8d
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main-api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 배포 스크립트 실행
8 changes: 4 additions & 4 deletions .github/workflows/network-api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 # ?? ???? ??
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 # 배포 스크립트 실행
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public interface ActiveDeviceRepository extends JpaRepository<ActiveDeviceEntity

Optional<ActiveDeviceEntity> findByDeviceId(UUID deviceId);

void deleteByDeviceId(UUID deviceId);

boolean existsByDeviceId(UUID deviceId);

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,12 +18,14 @@ public class DeviceRemoveHandler implements CommandHandler<DeviceRemove, Void> {
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;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 46fec8d

Please sign in to comment.