From 35293f5844de0f98a67dc64da727de5fb1341e7e Mon Sep 17 00:00:00 2001 From: kimyu0218 Date: Fri, 20 Dec 2024 21:53:50 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=94=94=EB=B0=94=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goalpanzi/application/device/DeviceService.java | 11 +++++++---- .../domain/device/repository/DeviceRepository.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/nexters/goalpanzi/application/device/DeviceService.java b/src/main/java/com/nexters/goalpanzi/application/device/DeviceService.java index 3d56142..4c00a5f 100644 --- a/src/main/java/com/nexters/goalpanzi/application/device/DeviceService.java +++ b/src/main/java/com/nexters/goalpanzi/application/device/DeviceService.java @@ -26,14 +26,17 @@ public class DeviceService { @Transactional public void updateDeviceToken(final UpdateDeviceTokenCommand command) { - if (command.deviceIdentifier().isBlank() // TODO: 추후 앞의 조건 삭제 - || !deviceRepository.existsByDeviceIdentifier(command.deviceIdentifier())) { - createDevice(command.memberId(), command.deviceIdentifier(), command.deviceToken(), command.osType()); - } else { + if (existsMemberDevice(command.memberId(), command.deviceIdentifier())) { updateDevice(command.memberId(), command.deviceIdentifier(), command.deviceToken()); + } else { + createDevice(command.memberId(), command.deviceIdentifier(), command.deviceToken(), command.osType()); } } + private boolean existsMemberDevice(final Long memberId, final String deviceIdentifier) { + return !deviceIdentifier.isBlank() && deviceRepository.existsByMemberIdAndDeviceIdentifier(memberId, deviceIdentifier); + } + private void createDevice(final Long memberId, final String deviceIdentifier, final String deviceToken, final OsType osType) { Member member = memberRepository.getMember(memberId); Device device = deviceRepository.save(new Device(member, deviceIdentifier, deviceToken, osType)); diff --git a/src/main/java/com/nexters/goalpanzi/domain/device/repository/DeviceRepository.java b/src/main/java/com/nexters/goalpanzi/domain/device/repository/DeviceRepository.java index 5e2c037..7ea0204 100644 --- a/src/main/java/com/nexters/goalpanzi/domain/device/repository/DeviceRepository.java +++ b/src/main/java/com/nexters/goalpanzi/domain/device/repository/DeviceRepository.java @@ -18,7 +18,7 @@ public interface DeviceRepository extends JpaRepository { @Query("SELECT d FROM Device d JOIN FETCH d.member WHERE d.deviceIdentifier = :deviceIdentifier") List findAllWithMemberByDeviceIdentifier(final String deviceIdentifier); - boolean existsByDeviceIdentifier(final String deviceIdentifier); + boolean existsByMemberIdAndDeviceIdentifier(final Long memberId, final String deviceIdentifier); default Device getDevice(final Long deviceId) { return findById(deviceId)