From 6e47e564bb317d9cbdbf270050ccd789c5fd7726 Mon Sep 17 00:00:00 2001 From: jcw1031 Date: Wed, 21 Feb 2024 12:49:40 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20=EC=BA=A0=ED=8D=BC=EC=8A=A4=EB=AA=85?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/device/request/DeviceRegistrationRequest.java | 4 +--- src/main/java/ac/knu/likeknu/domain/value/Campus.java | 9 +++++++++ src/main/java/ac/knu/likeknu/service/DeviceService.java | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/ac/knu/likeknu/controller/dto/device/request/DeviceRegistrationRequest.java b/src/main/java/ac/knu/likeknu/controller/dto/device/request/DeviceRegistrationRequest.java index 37d81a30..1eb42956 100644 --- a/src/main/java/ac/knu/likeknu/controller/dto/device/request/DeviceRegistrationRequest.java +++ b/src/main/java/ac/knu/likeknu/controller/dto/device/request/DeviceRegistrationRequest.java @@ -1,6 +1,4 @@ package ac.knu.likeknu.controller.dto.device.request; -import ac.knu.likeknu.domain.value.Campus; - -public record DeviceRegistrationRequest(String deviceId, String userAgent, Campus campus) { +public record DeviceRegistrationRequest(String deviceId, String userAgent, String campus) { } diff --git a/src/main/java/ac/knu/likeknu/domain/value/Campus.java b/src/main/java/ac/knu/likeknu/domain/value/Campus.java index 5fc5e76f..3bfc9247 100644 --- a/src/main/java/ac/knu/likeknu/domain/value/Campus.java +++ b/src/main/java/ac/knu/likeknu/domain/value/Campus.java @@ -2,6 +2,8 @@ import lombok.Getter; +import java.util.Arrays; + @Getter public enum Campus { @@ -17,4 +19,11 @@ public enum Campus { this.campus = campus; this.dormitoryAnnouncementId = dormitoryAnnouncementId; } + + public static Campus of(String campusName) { + return Arrays.stream(values()) + .filter(campus -> campus.getCampus().equals(campusName)) + .findAny() + .orElseThrow(); + } } diff --git a/src/main/java/ac/knu/likeknu/service/DeviceService.java b/src/main/java/ac/knu/likeknu/service/DeviceService.java index 004fbc80..e4cea2dd 100644 --- a/src/main/java/ac/knu/likeknu/service/DeviceService.java +++ b/src/main/java/ac/knu/likeknu/service/DeviceService.java @@ -38,7 +38,8 @@ public void registerDeviceId(DeviceRegistrationRequest deviceRequest) { .orElseGet(() -> Device.of(deviceRequest)); device.updatePlatform(deviceRequest.userAgent()); - device.updateCampus(deviceRequest.campus()); + String campus = deviceRequest.campus(); + device.updateCampus(Campus.of(campus)); device.visitNow(); if (registeredDevices.add(deviceId)) { deviceRepository.save(device);