From e82ff9ef9342581e11c05a6c8ea33db90594bf71 Mon Sep 17 00:00:00 2001 From: JIUNG YANG Date: Fri, 19 Apr 2024 23:27:00 +0900 Subject: [PATCH] =?UTF-8?q?CHECKPASS-382=20Feat=20:=20[=20Server=20]=20?= =?UTF-8?q?=EB=B9=84=EC=BD=98=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EA=B0=95?= =?UTF-8?q?=EC=9D=98=EA=B4=80=20=EC=9D=B4=EB=A6=84=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/BeaconController.java | 5 ++- .../resultForm/BeaconInformation.java | 18 ++++++++ .../web/service/beacon/BeaconService.java | 44 +++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/FXPROJECT/CHECKPASS/web/form/responseForm/resultForm/BeaconInformation.java diff --git a/backend/src/main/java/FXPROJECT/CHECKPASS/web/controller/BeaconController.java b/backend/src/main/java/FXPROJECT/CHECKPASS/web/controller/BeaconController.java index d33299d4..f3683c3e 100644 --- a/backend/src/main/java/FXPROJECT/CHECKPASS/web/controller/BeaconController.java +++ b/backend/src/main/java/FXPROJECT/CHECKPASS/web/controller/BeaconController.java @@ -8,6 +8,7 @@ import FXPROJECT.CHECKPASS.web.common.annotation.LoginUser; import FXPROJECT.CHECKPASS.web.common.utils.ResultFormUtils; import FXPROJECT.CHECKPASS.web.form.requestForm.beacon.register.BeaconRegisterForm; +import FXPROJECT.CHECKPASS.web.form.responseForm.resultForm.BeaconInformation; import FXPROJECT.CHECKPASS.web.form.responseForm.resultForm.ResultForm; import FXPROJECT.CHECKPASS.web.service.beacon.BeaconService; import lombok.RequiredArgsConstructor; @@ -60,7 +61,7 @@ public ResultForm getBeacon(@PathVariable("major") int major, @PathVariable("min throw new NoPermission(); } - return ResultFormUtils.getSuccessResultForm(beaconService.getBeacon(major, minor)); + return ResultFormUtils.getSuccessResultForm(beaconService.getBeaconInformation(major, minor)); } /** @@ -74,7 +75,7 @@ public ResultForm getBeaconList(@LoginUser Users loggedInUser) { throw new NoPermission(); } - List beaconList = beaconService.getBeaconList(); + List beaconList = beaconService.getBeaconList(); return ResultFormUtils.getSuccessResultForm(beaconList); } diff --git a/backend/src/main/java/FXPROJECT/CHECKPASS/web/form/responseForm/resultForm/BeaconInformation.java b/backend/src/main/java/FXPROJECT/CHECKPASS/web/form/responseForm/resultForm/BeaconInformation.java new file mode 100644 index 00000000..3e0c0d7c --- /dev/null +++ b/backend/src/main/java/FXPROJECT/CHECKPASS/web/form/responseForm/resultForm/BeaconInformation.java @@ -0,0 +1,18 @@ +package FXPROJECT.CHECKPASS.web.form.responseForm.resultForm; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class BeaconInformation { + + private int major; + private int minor; + private String buildingName; + +} diff --git a/backend/src/main/java/FXPROJECT/CHECKPASS/web/service/beacon/BeaconService.java b/backend/src/main/java/FXPROJECT/CHECKPASS/web/service/beacon/BeaconService.java index a0dd8041..c2fea6d9 100644 --- a/backend/src/main/java/FXPROJECT/CHECKPASS/web/service/beacon/BeaconService.java +++ b/backend/src/main/java/FXPROJECT/CHECKPASS/web/service/beacon/BeaconService.java @@ -5,18 +5,21 @@ import FXPROJECT.CHECKPASS.domain.entity.beacon.Beacon; import FXPROJECT.CHECKPASS.domain.entity.beacon.BeaconPK; import FXPROJECT.CHECKPASS.domain.entity.lectures.Lecture; +import FXPROJECT.CHECKPASS.domain.enums.BuildingsEnum; import FXPROJECT.CHECKPASS.domain.repository.beacon.JpaBeaconRepository; import FXPROJECT.CHECKPASS.domain.repository.QueryRepository; import FXPROJECT.CHECKPASS.domain.repository.building.JpaBuildingRepository; import FXPROJECT.CHECKPASS.domain.repository.lectures.JpaLectureRepository; import FXPROJECT.CHECKPASS.web.common.utils.ResultFormUtils; import FXPROJECT.CHECKPASS.web.form.requestForm.beacon.register.BeaconRegisterForm; +import FXPROJECT.CHECKPASS.web.form.responseForm.resultForm.BeaconInformation; import FXPROJECT.CHECKPASS.web.form.responseForm.resultForm.ResultForm; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import static FXPROJECT.CHECKPASS.domain.common.constant.CommonMessage.*; @@ -57,6 +60,22 @@ public Beacon registerBeacon(BeaconRegisterForm form){ * @param minor 비콘 minor * @return 조회된 비콘 */ + public BeaconInformation getBeaconInformation(int major, int minor){ + BeaconPK beaconPK = new BeaconPK(major, minor); + + if (!existsBeacon(beaconPK)) { + throw new NonExistentBeacon(); + } + + BeaconInformation beaconInformation = new BeaconInformation().builder() + .major(major) + .minor(minor) + .buildingName(getBuilding(major)) + .build(); + + return beaconInformation; + } + public Beacon getBeacon(int major, int minor){ BeaconPK beaconPK = new BeaconPK(major, minor); @@ -71,9 +90,24 @@ public Beacon getBeacon(int major, int minor){ * 비콘 목록 조회 * @return DB에 저장되어 있는 비콘 List */ - public List getBeaconList(){ + public List getBeaconList(){ List beaconList = queryRepository.getBeaconList(); - return beaconList; + List beaconInformationList = new ArrayList<>(); + for (Beacon beacon : beaconList) { + BeaconPK beaconPK = beacon.getBeaconPK(); + int major = beaconPK.getMajor(); + int minor = beaconPK.getMinor(); + String buildingName = getBuilding(major); + + BeaconInformation beaconInformation = new BeaconInformation().builder() + .major(major) + .minor(minor) + .buildingName(buildingName) + .build(); + + beaconInformationList.add(beaconInformation); + } + return beaconInformationList; } /** @@ -116,9 +150,13 @@ public boolean existsBeacon(BeaconPK beaconPK) { public String getLectureRoom(BeaconPK beaconPK) { int major = beaconPK.getMajor(); int minor = beaconPK.getMinor(); - String buildingName = jpaBuildingRepository.findBuildingNameByBuildingCode(major); + String buildingName = getBuilding(major); String lectureRoom = buildingName + " (" + minor + ")"; return lectureRoom; } + + public String getBuilding(int major) { + return jpaBuildingRepository.findBuildingNameByBuildingCode(major); + } } \ No newline at end of file