Skip to content

Commit

Permalink
CHECKPASS-382 Feat : [ Server ] 비콘 조회 시 강의관 이름 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung committed Apr 19, 2024
1 parent 2df9caf commit e82ff9e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -74,7 +75,7 @@ public ResultForm getBeaconList(@LoginUser Users loggedInUser) {
throw new NoPermission();
}

List<Beacon> beaconList = beaconService.getBeaconList();
List<BeaconInformation> beaconList = beaconService.getBeaconList();

return ResultFormUtils.getSuccessResultForm(beaconList);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);

Expand All @@ -71,9 +90,24 @@ public Beacon getBeacon(int major, int minor){
* 비콘 목록 조회
* @return DB에 저장되어 있는 비콘 List
*/
public List<Beacon> getBeaconList(){
public List<BeaconInformation> getBeaconList(){
List<Beacon> beaconList = queryRepository.getBeaconList();
return beaconList;
List<BeaconInformation> 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;
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e82ff9e

Please sign in to comment.