Skip to content

Commit

Permalink
Merge pull request #525 from Kernel360/522-refactor-add-a-member-poli…
Browse files Browse the repository at this point in the history
…cy-when-start-match

refactor: add a member policy when start match
  • Loading branch information
soeunnPark authored Dec 5, 2024
2 parents 07b5a0b + 732051d commit 4baf4f7
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public SecurityFilterChain clubFilterChain(HttpSecurity http) throws Exception {
.requestMatchers(HttpMethod.DELETE, "/v1/clubs/{clubToken}/leagues/{leagueId}/participation")
.permitAll()
.requestMatchers(HttpMethod.PATCH,
"/v1/clubs/{clubToken}/clubMembers/role",
"v1/clubs/{clubToken}/clubMembers/ban", "v1/clubs/{clubToken}/clubMembers/expel")
"/v1/clubs/{clubToken}/clubMembers/role", "v1/clubs/{clubToken}/clubMembers/ban",
"v1/clubs/{clubToken}/clubMembers/expel")
.permitAll()
.anyRequest()
.authenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.badminton.api.interfaces.match.dto.SetScoreResponse;
import org.badminton.api.interfaces.match.dto.SetScoreUpdateRequest;
import org.badminton.api.interfaces.match.dto.StartMatchCommand;
import org.badminton.domain.common.policy.ClubMemberPolicy;
import org.badminton.domain.domain.match.command.MatchCommand.UpdateSetScore;
import org.badminton.domain.domain.match.info.BracketInfo;
import org.badminton.domain.domain.match.info.MatchInfo;
Expand All @@ -39,6 +40,7 @@
public class MatchController {

private final MatchFacade matchFacade;
private final ClubMemberPolicy clubMemberPolicy;

@GetMapping
@Operation(summary = "대진표 조회",
Expand Down Expand Up @@ -164,10 +166,11 @@ public CommonResponse<SetScoreFinishResponse> finishSetsScore(
public CommonResponse<String> startMatch(
@PathVariable String clubToken,
@PathVariable Long leagueId,
@PathVariable Long matchId
@PathVariable Long matchId,
@AuthenticationPrincipal CustomOAuth2Member member
) {
StartMatchCommand startMatchCommand =
new StartMatchCommand(clubToken, leagueId, matchId);
clubMemberPolicy.validateLeagueParticipant(leagueId, member.getMemberToken());
StartMatchCommand startMatchCommand = new StartMatchCommand(clubToken, leagueId, matchId);
MatchOperationHandler matchOperationFacade = matchFacade.getMatchOperationHandler(leagueId);
matchOperationFacade.startMatch(startMatchCommand);
return CommonResponse.success("OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public enum ErrorCode {
MATCH_ALREADY_STARTED_WHEN_BRACKET_GENERATION(412, "경기가 이미 시작되었습니다. 대진표를 확인해주세요."),
LEAGUE_NOT_RECRUITING(412, "모집 중이 아닙니다."),
LEAGUE_PARTICIPANT_POWER_OF_TWO(412, "토너먼트 경기에서는 경기 참여 인원이 2의 제곱이어야 합니다"),
LEAGUE_PARTICIPANTS_NOT_EXISTS(412, "해당 매치의 참여자가 아직 정해지지 않았습니다"),
LEAGUE_PARTICIPANTS_NOT_DETERMINED(412, "해당 매치의 참여자가 아직 정해지지 않았습니다"),
SET_FINISHED(412, "Set 의 상태가 FINISHED 입니다"),
ALREADY_WINNER_DETERMINED(412, "매치의 승리자가 정해졌습니다"),
CLUB_OWNER_CANT_WITHDRAW(412, "동호회원이 2명 이상인 동호회 회장은 동호회를 탈퇴할 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.badminton.domain.common.exception.match;

import org.badminton.domain.common.error.ErrorCode;
import org.badminton.domain.common.exception.BadmintonException;

public class LeagueParticipantNotDeterminedException extends BadmintonException {

public LeagueParticipantNotDeterminedException(Long matchId) {
super(ErrorCode.LEAGUE_PARTICIPANTS_NOT_DETERMINED, "[매치 번호 : " + matchId + "]");
}

public LeagueParticipantNotDeterminedException(Long matchId, Exception e) {
super(ErrorCode.LEAGUE_PARTICIPANTS_NOT_DETERMINED, "[매치 번호 : " + matchId + "]", e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class LeagueParticipantsNotExistsException extends BadmintonException {

public LeagueParticipantsNotExistsException(Long matchId) {
super(ErrorCode.LEAGUE_PARTICIPANTS_NOT_EXISTS, "[매치 ID : " + matchId + "]");
super(ErrorCode.LEAGUE_NOT_PARTICIPATED, "[매치 ID : " + matchId + "]");
}

public LeagueParticipantsNotExistsException(Long matchId, Exception e) {
super(ErrorCode.LEAGUE_PARTICIPANTS_NOT_EXISTS, "[매치 ID : " + matchId + "]", e);
super(ErrorCode.LEAGUE_NOT_PARTICIPATED, "[매치 ID : " + matchId + "]", e);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.badminton.domain.common.exception.clubmember.ClubMemberIsNotAboveManagerException;
import org.badminton.domain.common.exception.clubmember.ClubMemberIsNotOwnerException;
import org.badminton.domain.common.exception.league.LeagueParticipationNotExistException;
import org.badminton.domain.common.exception.member.MemberNotJoinedClubException;
import org.badminton.domain.domain.clubmember.ClubMemberReader;
import org.badminton.domain.domain.clubmember.entity.ClubMember;
import org.badminton.domain.domain.league.LeagueParticipantReader;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +16,7 @@
public class ClubMemberPolicy {

private final ClubMemberReader clubMemberReader;
private final LeagueParticipantReader leagueParticipantReader;

public void validateClubMember(String memberToken, String clubToken) {
if (!clubMemberReader.checkIsClubMember(memberToken, clubToken)) {
Expand All @@ -36,4 +39,10 @@ public void validateAboveClubManager(String memberToken, String clubToken) {
throw new ClubMemberIsNotAboveManagerException(memberToken, clubToken, clubMember.getRole());
}
}

public void validateLeagueParticipant(Long leagueId, String memberToken) {
if (!leagueParticipantReader.isParticipant(memberToken, leagueId)) {
throw new LeagueParticipationNotExistException(leagueId, memberToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.badminton.domain.common.enums.MatchType;
import org.badminton.domain.common.enums.SetStatus;
import org.badminton.domain.common.exception.league.LeagueParticipationNotExistException;
import org.badminton.domain.common.exception.match.LeagueParticipationNotExistInMatchException;
import org.badminton.domain.common.exception.match.LeagueParticipantNotDeterminedException;
import org.badminton.domain.common.exception.match.PreviousDetNotFinishedException;
import org.badminton.domain.common.exception.match.RoundNotFinishedException;
import org.badminton.domain.domain.league.LeagueParticipantReader;
Expand Down Expand Up @@ -86,7 +86,7 @@ private void validateSinglesMatch(Long matchId, int setNumber) {
SinglesMatch match = singlesMatchReader.getSinglesMatch(matchId);

if (match.getLeagueParticipant1() == null || match.getLeagueParticipant2() == null) {
throw new LeagueParticipationNotExistInMatchException(matchId);
throw new LeagueParticipantNotDeterminedException(matchId);
}

if (setNumber == 1) {
Expand All @@ -102,7 +102,7 @@ private void validateDoublesMatch(Long matchId, int setNumber) {
DoublesMatch match = doublesMatchReader.getDoublesMatch(matchId);

if (match.getTeam1() == null || match.getTeam2() == null) {
throw new LeagueParticipationNotExistInMatchException(matchId);
throw new LeagueParticipantNotDeterminedException(matchId);
}

if (setNumber == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.badminton.domain.common.enums.MatchResult;
import org.badminton.domain.common.enums.SetStatus;
import org.badminton.domain.common.exception.match.AlreadyWinnerDeterminedException;
import org.badminton.domain.common.exception.match.LeagueParticipantsNotExistsException;
import org.badminton.domain.common.exception.match.LeagueParticipantNotDeterminedException;
import org.badminton.domain.common.exception.match.PreviousDetNotFinishedException;
import org.badminton.domain.common.exception.match.RoundNotFinishedException;
import org.badminton.domain.common.exception.match.SetFinishedException;
Expand Down Expand Up @@ -91,7 +91,7 @@ public SetInfo.Main registerSetScoreInMatch(Long matchId, Integer setNumber,
}

if (doublesMatch.getTeam1() == null || doublesMatch.getTeam2() == null) {
throw new LeagueParticipantsNotExistsException(matchId);
throw new LeagueParticipantNotDeterminedException(matchId);
}

updateSetScore(doublesMatch, setNumber, updateSetScoreCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.badminton.domain.common.enums.SetStatus;
import org.badminton.domain.common.exception.match.AlreadyWinnerDeterminedException;
import org.badminton.domain.common.exception.match.ByeMatchException;
import org.badminton.domain.common.exception.match.LeagueParticipantsNotExistsException;
import org.badminton.domain.common.exception.match.LeagueParticipantNotDeterminedException;
import org.badminton.domain.common.exception.match.PreviousDetNotFinishedException;
import org.badminton.domain.common.exception.match.RoundNotFinishedException;
import org.badminton.domain.common.exception.match.SetFinishedException;
Expand Down Expand Up @@ -107,7 +107,7 @@ public SetInfo.Main registerSetScoreInMatch(Long matchId, Integer setNumber,
}

if (singlesMatch.getLeagueParticipant1() == null || singlesMatch.getLeagueParticipant2() == null) {
throw new LeagueParticipantsNotExistsException(matchId);
throw new LeagueParticipantNotDeterminedException(matchId);
}

updateSetScore(singlesMatch, setNumber, updateSetScoreCommand);
Expand Down

0 comments on commit 4baf4f7

Please sign in to comment.