Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] : 스타디움 구역 정보 중복 & 구역 추천(KT) 문제를 해결한다 #89

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@RequiredArgsConstructor
public enum KtWizStadiumStatusType implements StadiumStatusType{

//특징 확인 필요
CENTER("https://kr.object.ncloudstorage.com/hitzone-bucket/hitzone/guide/kt/center.svg",
"중앙지정석",
"#5E346E",
Expand Down Expand Up @@ -126,10 +125,10 @@ public enum KtWizStadiumStatusType implements StadiumStatusType{
)
)
),
List.of("나 혼자", "같은 팀 팬과"),
List.of("열정적인 응원"),
List.of(),
List.of("다른 팀 팬과", "큰 소리 싫어요", "음식 먹기 편한", "삼겹살 구워먹기 가능"),
List.of(),
List.of(),
List.of(),
new String[]{"데이터 추가 입력 예정"},
new String[]{"[1루] 약 27~32cm [3루] 약 27~32cm"},
new String[]{"[1루] 약 28cm [3루] 약 26~33cm"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
import java.util.Arrays;
import java.util.List;

import static kusitms.backend.result.domain.enums.KtWizStadiumStatusType.CHEERING_DUMMY;

@Service
@RequiredArgsConstructor
public class StadiumService {

/**
* 주어진 경기장 이름에 대한 정보를 조회.
*
* @param stadiumName 경기장 이름
* @return 경기장 정보와 구역 정보 리스트를 포함하는 DTO
* @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
*/
@Transactional(readOnly = true)
public GetStadiumInfosResponseDto getStadiumInfos(String stadiumName) {
StadiumInfo stadiumInfo = getStadiumInfoByName(stadiumName);
Expand All @@ -27,22 +36,14 @@ public GetStadiumInfosResponseDto getStadiumInfos(String stadiumName) {
return GetStadiumInfosResponseDto.of(stadiumInfo.getImgUrl(), stadiumInfo.getFirstBaseSide(), stadiumInfo.getThirdBaseSide(), zoneInfos);
}

private StadiumInfo getStadiumInfoByName(String stadiumName) {
return switch (stadiumName) {
case "잠실종합운동장 (잠실)" -> StadiumInfo.LG_HOME;
case "수원KT위즈파크" -> StadiumInfo.KT_HOME;
default -> throw new CustomException(StadiumErrorStatus._NOT_FOUND_STADIUM);
};
}

private StadiumStatusType[] getStatusTypesByName(String stadiumName) {
return switch (stadiumName) {
case "잠실종합운동장 (잠실)" -> JamsilStadiumStatusType.values();
case "수원KT위즈파크" -> KtWizStadiumStatusType.values();
default -> throw new CustomException(StadiumErrorStatus._NOT_FOUND_STADIUM);
};
}

/**
* 주어진 경기장 이름에 해당하는 구역 정보를 조회.
*
* @param stadiumName 경기장 이름
* @param zoneName 구역 이름
* @return 구역 정보 DTO
* @throws CustomException 유효하지 않은 경기장 이름이나 구역 이름이 주어진 경우
*/
@Transactional(readOnly = true)
public GetZoneGuideResponseDto getZoneGuide(String stadiumName, String zoneName) {
StadiumStatusType zoneType = switch (stadiumName) {
Expand All @@ -53,16 +54,62 @@ public GetZoneGuideResponseDto getZoneGuide(String stadiumName, String zoneName)
return GetZoneGuideResponseDto.from(zoneType);
}

/**
* 주어진 상태 타입 배열에서 특정 구역의 이름과 색상을 조회.
* CHEERING_DUMMY 구역은 제외됩니다.
*
* @param statusTypes 상태 타입 배열
* @return 구역 이름과 색상 정보를 담은 리스트
*/
private List<GetStadiumInfosResponseDto.ZoneInfo> getZonesNameAndColorFromStadium(StadiumStatusType[] statusTypes) {
return Arrays.stream(statusTypes)
.filter(status -> status != CHEERING_DUMMY)
.map(status -> GetStadiumInfosResponseDto.ZoneInfo.of(status.getZoneName(), status.getZoneColor()))
.toList();
}

/**
* 주어진 상태 타입 배열에서 특정 구역 이름과 일치하는 구역 정보를 조회.
*
* @param statusTypes 상태 타입 배열
* @param zoneName 구역 이름
* @return 일치하는 구역 정보
* @throws CustomException 일치하는 구역을 찾을 수 없는 경우
*/
private StadiumStatusType findZoneInStadium(StadiumStatusType[] statusTypes, String zoneName) {
return Arrays.stream(statusTypes)
.filter(status -> status.getZoneName().equals(zoneName))
.findFirst()
.orElseThrow(() -> new CustomException(StadiumErrorStatus._NOT_FOUND_ZONE));
}
}

/**
* 주어진 경기장 이름에 대한 기본 정보를 조회.
*
* @param stadiumName 경기장 이름
* @return 경기장 기본 정보
* @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
*/
private StadiumInfo getStadiumInfoByName(String stadiumName) {
return switch (stadiumName) {
case "잠실종합운동장 (잠실)" -> StadiumInfo.LG_HOME;
case "수원KT위즈파크" -> StadiumInfo.KT_HOME;
default -> throw new CustomException(StadiumErrorStatus._NOT_FOUND_STADIUM);
};
}

/**
* 주어진 경기장 이름에 대한 상태 타입 배열을 조회.
*
* @param stadiumName 경기장 이름
* @return 경기장 상태 타입 배열
* @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
*/
private StadiumStatusType[] getStatusTypesByName(String stadiumName) {
return switch (stadiumName) {
case "잠실종합운동장 (잠실)" -> JamsilStadiumStatusType.values();
case "수원KT위즈파크" -> KtWizStadiumStatusType.values();
default -> throw new CustomException(StadiumErrorStatus._NOT_FOUND_STADIUM);
};
}
}
Loading