Skip to content

Commit

Permalink
[Refactor/#291] remove not necessary part
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Jeong committed Jun 10, 2024
1 parent 9783cd0 commit f8d6cce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public void deleteTeam(Long teamId, Member member) {
Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));
validateCallerIsLeader(team, member);
awsS3Service.deleteFile(team.getCoverImageUrl());
if (MediaUtil.validateRemoveImgInS3(team.getCoverImageUrl(), null)) {
awsS3Service.deleteFile(team.getCoverImageUrl());
}
teamRepository.deleteTeamWithRelations(teamId);
}

Expand Down Expand Up @@ -130,7 +132,7 @@ public void changeTeamLeader(Long teamId, Long memberId, Member leader) {

validateCallerIsLeader(team, leader);
validateTargetIsNotLeader(memberId, team);
validateMemberBelongsToTeam(team, member);
validateMemberIsInTeam(team, member);
team.updateLeader(member);
}

Expand All @@ -140,6 +142,7 @@ public Long requestParticipation(Long teamId, Member member) {
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));

validateNonExistenceOfParticipationRequest(team, member);
validateMemberIsNotInTeam(team, member);

Participation participation = buildParticipation(member, team);
participationRepository.save(participation);
Expand Down Expand Up @@ -181,7 +184,7 @@ public void respondToParticipation(Long teamId, Long memberId, Member leader,
content)
);
}
participationRepository.deleteByMemberAndTeam(member, team);
participationRepository.delete(participation);
}

private static ParticipationDto buildParticipationDto(Team team) {
Expand All @@ -197,14 +200,18 @@ private void validateCallerIsLeader(Team team, Member member) {
}
}

private void validateMemberBelongsToTeam(Team team, Member member) {
boolean isMember = team.getTeamMembers().stream()
.anyMatch(tm -> tm.getMember().equals(member));
if (!isMember) {
private void validateMemberIsInTeam(Team team, Member member) {
if (!teamMemberRepository.existsByMemberAndTeam(member, team)) {
throw new TeamHandler(ErrorStatus.TEAM_MEMBER_NOT_IN_TEAM);
}
}

private void validateMemberIsNotInTeam(Team team, Member member) {
if (teamMemberRepository.existsByMemberAndTeam(member, team)) {
throw new TeamHandler(ErrorStatus.TEAM_MEMBER_ALREADY_EXISTS);
}
}

private void validateNonExistenceOfParticipationRequest(Team team, Member member) {
if (participationRepository.existsByTeamAndMember(team, member)) {
throw new TeamHandler(ErrorStatus.TEAM_PARTICIPATION_REQUEST_ALREADY_EXISTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;

public interface TeamQueryService {

Expand All @@ -22,9 +21,5 @@ public interface TeamQueryService {

List<Participation> getParticipationList(Member leader, Long teamId);

Optional<Participation> getParticipation(Member member, Long teamId);

boolean isMemberOfTeam(Member member, Long teamId);

Status getParticipationStatus(Member member, Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -63,19 +62,6 @@ private static void validateIsLeader(Member leader, Team team) {
}
}

@Override
public Optional<Participation> getParticipation(Member member, Long teamId) {
return participationRepository.findByTeamIdAndMemberId(teamId, member.getId());
}

@Override
public boolean isMemberOfTeam(Member member, Long teamId) {
Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));
return team.getTeamMembers().stream()
.anyMatch(teamMember -> teamMember.getMember().equals(member));
}

@Override
public Status getParticipationStatus(Member member, Long teamId) {
if (teamMemberRepository.existsByMemberIdAndTeamId(member.getId(), teamId)) {
Expand Down

0 comments on commit f8d6cce

Please sign in to comment.