Skip to content

Commit

Permalink
Merge pull request #225 from hufscheer/refactor/#222-league
Browse files Browse the repository at this point in the history
[REFACTOR] 리그 생성 시 자동으로 Organization 등록되도록 수정
  • Loading branch information
Zena0128 authored Sep 20, 2024
2 parents e965f3c + c8d96d8 commit e7955af
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class LeagueService {
private final LeagueRepository leagueRepository;

public void register(final Member manager, final LeagueRequestDto.Register request) {
Organization organization = entityUtils.getEntity(request.organizationId(), Organization.class);
leagueRepository.save(request.toEntity(manager, organization));
leagueRepository.save(request.toEntity(manager));
}

public void update(final Member manager, final LeagueRequestDto.Update request, final Long leagueId) {
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/com/sports/server/command/league/domain/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
@Getter
@RequiredArgsConstructor
public enum Round {
FINAL("결승"),
SEMI_FINAL("4강"),
QUARTER_FINAL("8강"),
ROUND_16("16강"),
ROUND_32("32강");
FINAL("결승", 2),
SEMI_FINAL("4강", 4),
QUARTER_FINAL("8강", 8),
ROUND_16("16강", 16),
ROUND_32("32강", 32);

private final String description;
private final int number;

public static Round from(final String value) {
return Stream.of(Round.values())
Expand All @@ -27,6 +28,14 @@ public static Round from(final String value) {
});
}

public static Round fromNumber(int number) {
return Stream.of(Round.values())
.filter(round -> round.number == number)
.findAny()
.orElseThrow(() -> new CustomException(HttpStatus.BAD_REQUEST, LeagueErrorMessages.ROUND_NOT_FOUND_EXCEPTION));
}


public static boolean isValidDescription(final String value) {
return Stream.of(Round.values())
.anyMatch(round -> round.getDescription().equals(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

public class LeagueRequestDto {
public record Register(
Long organizationId,
String name,
String maxRound,
int maxRound,
LocalDateTime startAt,
LocalDateTime endAt
) {
public League toEntity(final Member manager, final Organization organization) {
return new League(manager, organization, name, startAt, endAt, Round.from(maxRound));
public League toEntity(final Member manager) {
return new League(manager, manager.getOrganization(), name, startAt, endAt, Round.fromNumber(maxRound));
}
}

Expand Down
34 changes: 14 additions & 20 deletions src/main/resources/static/docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ <h4 id="_게임_등록_http_request"><a class="link" href="#_게임_등록_http_
"round" : "16강",
"quarter" : "경기전",
"state" : "SCHEDULED",
"startTime" : "2024-09-18T18:41:01.634111",
"startTime" : "2024-09-19T19:34:01.751883",
"idOfTeam1" : 1,
"idOfTeam2" : 2,
"videoId" : "videoId"
Expand Down Expand Up @@ -1908,16 +1908,15 @@ <h4 id="_리그_생성_http_request"><a class="link" href="#_리그_생성_http_
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /leagues HTTP/1.1
Content-Type: application/json
Content-Length: 179
Content-Length: 150
Host: www.api.hufstreaming.site
Cookie: HCC_SES=temp-cookie

{
"organizationId" : 1,
"name" : "우물정 제기차기 대회",
"maxRound" : "4강",
"startAt" : "2024-09-18T18:41:01.840974",
"endAt" : "2024-09-18T18:41:01.840975"
"maxRound" : 4,
"startAt" : "2024-09-19T19:34:02.040614",
"endAt" : "2024-09-19T19:34:02.040618"
}</code></pre>
</div>
</div>
Expand All @@ -1939,19 +1938,14 @@ <h4 id="_리그_생성_request_fields"><a class="link" href="#_리그_생성_req
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>organizationId</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">조직 id</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">대회 이름</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>maxRound</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">대회 진행 라운드 수</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">대회 진행 라운드 수. 결승은 2</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>startAt</code></p></td>
Expand Down Expand Up @@ -1992,8 +1986,8 @@ <h4 id="_리그_수정_http_request"><a class="link" href="#_리그_수정_http_

{
"name" : "훕치치배 망고 빨리먹기 대회",
"startAt" : "2024-09-18T18:41:01.856257",
"endAt" : "2024-09-18T18:41:01.856261",
"startAt" : "2024-09-19T19:34:02.059989",
"endAt" : "2024-09-19T19:34:02.059994",
"maxRound" : "16강"
}</code></pre>
</div>
Expand Down Expand Up @@ -2873,12 +2867,12 @@ <h4 id="_매니저가_생성한_리그_전체_조회_http_response"><a class="li
"state" : "진행 중",
"sizeOfLeagueTeams" : 2,
"maxRound" : "16강",
"startAt" : "2024-09-18T18:41:05.056959",
"endAt" : "2024-09-18T18:41:05.056959",
"startAt" : "2024-09-19T19:34:05.926666",
"endAt" : "2024-09-19T19:34:05.926666",
"inProgressGames" : [ {
"id" : 1,
"state" : "PLAYING",
"startTime" : "2024-09-18T18:41:05.056951",
"startTime" : "2024-09-19T19:34:05.926657",
"gameTeams" : [ {
"gameTeamId" : 1,
"gameTeamName" : "경영 야생마",
Expand Down Expand Up @@ -4117,7 +4111,7 @@ <h4 id="_사용자_로그인_http_response"><a class="link" href="#_사용자_
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Set-Cookie: HCC_SES=testAccessToken; Path=/; Max-Age=604800; Expires=Wed, 25 Sep 2024 09:40:56 GMT; Secure; HttpOnly; SameSite=Strict</code></pre>
Set-Cookie: HCC_SES=testAccessToken; Path=/; Max-Age=604800; Expires=Thu, 26 Sep 2024 10:33:57 GMT; Secure; HttpOnly; SameSite=Strict</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -4191,7 +4185,7 @@ <h4 id="_사용자_정보_조회_response_fields"><a class="link" href="#_사용
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-09-18 18:40:18 +0900
Last updated 2024-09-19 18:35:26 +0900
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LeagueAcceptanceTest extends AcceptanceTest {
@Test
void 대회를_저장한다() {
// given
LeagueRequestDto.Register request = new LeagueRequestDto.Register(1L, "우물정 제기차기 대회", "4강", LocalDateTime.now(),
LeagueRequestDto.Register request = new LeagueRequestDto.Register("우물정 제기차기 대회", 4, LocalDateTime.now(),
LocalDateTime.now());

configureMockJwtForEmail("[email protected]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LeagueControllerTest extends DocumentationTest {
@Test
void 리그를_생성한다() throws Exception {
// given
LeagueRequestDto.Register request = new LeagueRequestDto.Register(1L, "우물정 제기차기 대회", "4강", LocalDateTime.now(), LocalDateTime.now());
LeagueRequestDto.Register request = new LeagueRequestDto.Register("우물정 제기차기 대회", 4, LocalDateTime.now(), LocalDateTime.now());

doNothing().when(leagueService).register(any(Member.class), any(LeagueRequestDto.Register.class));

Expand All @@ -44,9 +44,8 @@ class LeagueControllerTest extends DocumentationTest {
result.andExpect(status().isOk())
.andDo(restDocsHandler.document(
requestFields(
fieldWithPath("organizationId").type(JsonFieldType.NUMBER).description("조직 id"),
fieldWithPath("name").type(JsonFieldType.STRING).description("대회 이름"),
fieldWithPath("maxRound").type(JsonFieldType.STRING).description("대회 진행 라운드 수"),
fieldWithPath("maxRound").type(JsonFieldType.NUMBER).description("대회 진행 라운드 수. 결승은 2"),
fieldWithPath("startAt").type(JsonFieldType.STRING).description("대회 시작 시간"),
fieldWithPath("endAt").type(JsonFieldType.STRING).description("대회 종료 시간")
),
Expand Down

0 comments on commit e7955af

Please sign in to comment.