Skip to content

Commit

Permalink
fix: 디바이스 토큰 업데이트 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyu0218 committed Dec 20, 2024
1 parent 0196c5e commit 35293f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface DeviceRepository extends JpaRepository<Device, Long> {
@Query("SELECT d FROM Device d JOIN FETCH d.member WHERE d.deviceIdentifier = :deviceIdentifier")
List<Device> 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)
Expand Down

0 comments on commit 35293f5

Please sign in to comment.