15
15
import java .util .Arrays ;
16
16
import java .util .List ;
17
17
18
+ import static kusitms .backend .result .domain .enums .KtWizStadiumStatusType .CHEERING_DUMMY ;
19
+
18
20
@ Service
19
21
@ RequiredArgsConstructor
20
22
public class StadiumService {
21
23
24
+ /**
25
+ * 주어진 경기장 이름에 대한 정보를 조회.
26
+ *
27
+ * @param stadiumName 경기장 이름
28
+ * @return 경기장 정보와 구역 정보 리스트를 포함하는 DTO
29
+ * @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
30
+ */
22
31
@ Transactional (readOnly = true )
23
32
public GetStadiumInfosResponseDto getStadiumInfos (String stadiumName ) {
24
33
StadiumInfo stadiumInfo = getStadiumInfoByName (stadiumName );
@@ -27,22 +36,14 @@ public GetStadiumInfosResponseDto getStadiumInfos(String stadiumName) {
27
36
return GetStadiumInfosResponseDto .of (stadiumInfo .getImgUrl (), stadiumInfo .getFirstBaseSide (), stadiumInfo .getThirdBaseSide (), zoneInfos );
28
37
}
29
38
30
- private StadiumInfo getStadiumInfoByName (String stadiumName ) {
31
- return switch (stadiumName ) {
32
- case "잠실종합운동장 (잠실)" -> StadiumInfo .LG_HOME ;
33
- case "수원KT위즈파크" -> StadiumInfo .KT_HOME ;
34
- default -> throw new CustomException (StadiumErrorStatus ._NOT_FOUND_STADIUM );
35
- };
36
- }
37
-
38
- private StadiumStatusType [] getStatusTypesByName (String stadiumName ) {
39
- return switch (stadiumName ) {
40
- case "잠실종합운동장 (잠실)" -> JamsilStadiumStatusType .values ();
41
- case "수원KT위즈파크" -> KtWizStadiumStatusType .values ();
42
- default -> throw new CustomException (StadiumErrorStatus ._NOT_FOUND_STADIUM );
43
- };
44
- }
45
-
39
+ /**
40
+ * 주어진 경기장 이름에 해당하는 구역 정보를 조회.
41
+ *
42
+ * @param stadiumName 경기장 이름
43
+ * @param zoneName 구역 이름
44
+ * @return 구역 정보 DTO
45
+ * @throws CustomException 유효하지 않은 경기장 이름이나 구역 이름이 주어진 경우
46
+ */
46
47
@ Transactional (readOnly = true )
47
48
public GetZoneGuideResponseDto getZoneGuide (String stadiumName , String zoneName ) {
48
49
StadiumStatusType zoneType = switch (stadiumName ) {
@@ -53,16 +54,62 @@ public GetZoneGuideResponseDto getZoneGuide(String stadiumName, String zoneName)
53
54
return GetZoneGuideResponseDto .from (zoneType );
54
55
}
55
56
57
+ /**
58
+ * 주어진 상태 타입 배열에서 특정 구역의 이름과 색상을 조회.
59
+ * CHEERING_DUMMY 구역은 제외됩니다.
60
+ *
61
+ * @param statusTypes 상태 타입 배열
62
+ * @return 구역 이름과 색상 정보를 담은 리스트
63
+ */
56
64
private List <GetStadiumInfosResponseDto .ZoneInfo > getZonesNameAndColorFromStadium (StadiumStatusType [] statusTypes ) {
57
65
return Arrays .stream (statusTypes )
66
+ .filter (status -> status != CHEERING_DUMMY )
58
67
.map (status -> GetStadiumInfosResponseDto .ZoneInfo .of (status .getZoneName (), status .getZoneColor ()))
59
68
.toList ();
60
69
}
61
70
71
+ /**
72
+ * 주어진 상태 타입 배열에서 특정 구역 이름과 일치하는 구역 정보를 조회.
73
+ *
74
+ * @param statusTypes 상태 타입 배열
75
+ * @param zoneName 구역 이름
76
+ * @return 일치하는 구역 정보
77
+ * @throws CustomException 일치하는 구역을 찾을 수 없는 경우
78
+ */
62
79
private StadiumStatusType findZoneInStadium (StadiumStatusType [] statusTypes , String zoneName ) {
63
80
return Arrays .stream (statusTypes )
64
81
.filter (status -> status .getZoneName ().equals (zoneName ))
65
82
.findFirst ()
66
83
.orElseThrow (() -> new CustomException (StadiumErrorStatus ._NOT_FOUND_ZONE ));
67
84
}
68
- }
85
+
86
+ /**
87
+ * 주어진 경기장 이름에 대한 기본 정보를 조회.
88
+ *
89
+ * @param stadiumName 경기장 이름
90
+ * @return 경기장 기본 정보
91
+ * @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
92
+ */
93
+ private StadiumInfo getStadiumInfoByName (String stadiumName ) {
94
+ return switch (stadiumName ) {
95
+ case "잠실종합운동장 (잠실)" -> StadiumInfo .LG_HOME ;
96
+ case "수원KT위즈파크" -> StadiumInfo .KT_HOME ;
97
+ default -> throw new CustomException (StadiumErrorStatus ._NOT_FOUND_STADIUM );
98
+ };
99
+ }
100
+
101
+ /**
102
+ * 주어진 경기장 이름에 대한 상태 타입 배열을 조회.
103
+ *
104
+ * @param stadiumName 경기장 이름
105
+ * @return 경기장 상태 타입 배열
106
+ * @throws CustomException 유효하지 않은 경기장 이름이 주어진 경우
107
+ */
108
+ private StadiumStatusType [] getStatusTypesByName (String stadiumName ) {
109
+ return switch (stadiumName ) {
110
+ case "잠실종합운동장 (잠실)" -> JamsilStadiumStatusType .values ();
111
+ case "수원KT위즈파크" -> KtWizStadiumStatusType .values ();
112
+ default -> throw new CustomException (StadiumErrorStatus ._NOT_FOUND_STADIUM );
113
+ };
114
+ }
115
+ }
0 commit comments