Skip to content

Commit

Permalink
[MERGE] 메인 브랜치와 반영 및 문서화 수정 #219
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin409 committed Sep 21, 2024
2 parents 18aa6d0 + e7955af commit 9dfdef4
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 190 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
Loading

0 comments on commit 9dfdef4

Please sign in to comment.