Skip to content

Commit

Permalink
[Refactor/#185] remove team Max size
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Jeong committed Apr 7, 2024
1 parent cca889c commit 68a41ff
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 50 deletions.
25 changes: 4 additions & 21 deletions src/main/java/com/example/waggle/domain/schedule/entity/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@

import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.global.component.auditing.BaseEntity;
import com.example.waggle.web.dto.oauth.OAuthToken.request;
import com.example.waggle.web.dto.schedule.TeamRequest;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Getter
Expand All @@ -43,7 +28,6 @@ public class Team extends BaseEntity {
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private TeamColor teamColor;
private Integer maxTeamSize;


@Builder.Default
Expand Down Expand Up @@ -73,7 +57,6 @@ public void update(TeamRequest updateTeamRequest) {
this.description = updateTeamRequest.getDescription();
this.coverImageUrl = updateTeamRequest.getCoverImageUrl();
this.teamColor = TeamColor.valueOf(updateTeamRequest.getTeamColor());
this.maxTeamSize = updateTeamRequest.getMaxTeamSize();
}

public void updateLeader(Member teamLeader) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.waggle.domain.schedule.service.team;

import com.example.waggle.web.dto.schedule.TeamRequest;
import com.example.waggle.domain.member.entity.Member;
import com.example.waggle.web.dto.schedule.TeamRequest;

public interface TeamCommandService {

Expand All @@ -11,7 +11,7 @@ public interface TeamCommandService {

void deleteTeam(Long teamId, Member member);

Long addTeamMember(Long teamId, Long newMemberId, Member member);
Long addTeamMemberByLeader(Long teamId, Long newMemberId, Member member);

void deleteTeamMemberByLeader(Long teamId, Long memberId, Member leader);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TeamCommandServiceImpl implements TeamCommandService {
private final MemberScheduleRepository memberScheduleRepository;
private final ParticipationRepository participationRepository;
private final ScheduleCommandService scheduleCommandService;
private final int teamCapacityLimit = 50;
private final int teamCapacityLimit = 15;

@Override
public Long createTeam(TeamRequest createTeamRequest, Member member) {
Expand All @@ -46,7 +46,6 @@ private Team buildTeam(TeamRequest createTeamRequest, Member member) {
.description(createTeamRequest.getDescription())
.coverImageUrl(createTeamRequest.getCoverImageUrl())
.teamColor(TeamColor.valueOf(createTeamRequest.getTeamColor()))
.maxTeamSize(createTeamRequest.getMaxTeamSize())
.leader(member)
.build();
}
Expand All @@ -56,7 +55,6 @@ public Long updateTeam(Long teamId, TeamRequest updateTeamRequest, Member member
Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));
validateCallerIsLeader(team, member);
validateTeamMemberIsOverRequestSize(updateTeamRequest, team);
team.update(updateTeamRequest);
return team.getId();
}
Expand All @@ -74,17 +72,20 @@ public void deleteTeam(Long teamId, Member member) {
}

@Override
public Long addTeamMember(Long teamId, Long newMemberId, Member member) {
//no usages인데 지워도 되나요
public Long addTeamMemberByLeader(Long teamId, Long newMemberId, Member leader) {
Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));
Member newMember = memberRepository.findById(newMemberId)
.orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Participation participation = buildParticipation(newMember, team);
participation.setStatus(ParticipationStatus.ACCEPTED);

validateCallerIsLeader(team, member);
validateTeamMemberCount(team);
validateCallerIsLeader(team, leader);
validateMemberDuplication(team, newMember);
validateLimitOfTeamCapacity(team);
addMemberToTeam(team, member);
addMemberToTeam(team, leader);
participationRepository.save(participation);

return team.getId();
}
Expand Down Expand Up @@ -120,10 +121,18 @@ public void changeTeamLeader(Long teamId, Long memberId, Member leader) {
.orElseThrow(() -> new TeamHandler(ErrorStatus.TEAM_NOT_FOUND));
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Participation leaderParticipation = Participation.builder()
.member(leader)
.team(team)
.status(ParticipationStatus.ACCEPTED)
.build();

validateCallerIsLeader(team, leader);
validateRemovedIsLeader(memberId, team);
validateMemberBelongsToTeam(team, member);
team.updateLeader(member);
participationRepository.save(leaderParticipation);
participationRepository.deleteByMemberAndTeam(member, team);
}

@Override
Expand Down Expand Up @@ -154,7 +163,6 @@ public void respondToParticipation(Long teamId, Long memberId, Member leader,
ErrorStatus.TEAM_PARTICIPATION_NOT_FOUND));

if (accept) {
validateTeamMemberCount(team);
validateLimitOfTeamCapacity(team);
participation.setStatus(ParticipationStatus.ACCEPTED);
addMemberToTeam(team, member);
Expand Down Expand Up @@ -194,25 +202,12 @@ private void validateNonExistenceOfParticipationRequest(Team team, Member member
}
}

private static void validateTeamMemberCount(Team team) {
if (team.getTeamMembers().size() == team.getMaxTeamSize()) {
throw new TeamHandler(ErrorStatus.TEAM_MEMBER_CANNOT_BE_EXCEEDED);
}
}

private static void validateRemovedIsLeader(Long memberId, Team team) {
if (team.getLeader().getId().equals(memberId)) {
throw new TeamHandler(ErrorStatus.TEAM_LEADER_CANNOT_BE_REMOVED);
}
}

private static void validateTeamMemberIsOverRequestSize(TeamRequest request, Team team) {
if (team.getTeamMembers().size() > request.getMaxTeamSize()) {
throw new TeamHandler(
ErrorStatus.TEAM_SIZE_IS_OVER_THAN_REQUEST_SIZE);
}
}

private void validateLimitOfTeamCapacity(Team team) {
if (team.getTeamMembers().size() == teamCapacityLimit) {
throw new TeamHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ApiResponseDto<Boolean> deleteTeamMemberByMyself(@PathVariable Long teamI
@ApiErrorCodeExample({
ErrorStatus._INTERNAL_SERVER_ERROR
})
@PutMapping("/{teamId}/leader/{memberId}")
@PutMapping("/{teamId}/leader/{newLeaderId}")
public ApiResponseDto<Boolean> changeTeamLeader(@PathVariable("teamId") Long teamId,
@PathVariable("newLeaderId") Long newLeaderId,
@AuthUser Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static TeamDetailDto toDetailDto(Team team) {
.description(team.getDescription())
.coverImageUrl(MediaUtil.getCoverImg(team))
.teamColor(team.getTeamColor())
.maxTeamSize(team.getMaxTeamSize())
.teamSize(team.getTeamMembers().size())
.leader(MemberConverter.toMemberSummaryDto(team.getLeader()))
.teamMemberList(
Expand All @@ -37,7 +36,6 @@ public static TeamSummaryDto toSummaryDto(Team team) {
.coverImageUrl(MediaUtil.getCoverImg(team))
.description(team.getDescription())
.teamColor(team.getTeamColor())
.maxTeamSize(team.getMaxTeamSize())
.teamSize(team.getTeamMembers().size())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.waggle.domain.schedule.entity.TeamColor;
import com.example.waggle.global.annotation.valid.enums.ValidEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -17,8 +16,6 @@
public class TeamRequest {
private String name;
private String description;
@Min(value = 1, message = "팀인원수는 최소 1명입니다.(팀 리더 포함 인원 수)")
private Integer maxTeamSize;
private String coverImageUrl;

@ValidEnum(target = TeamColor.class)
Expand Down

0 comments on commit 68a41ff

Please sign in to comment.