Skip to content

Commit

Permalink
[FEAT] add team leader position in createTeam API request
Browse files Browse the repository at this point in the history
  • Loading branch information
nogamsung committed Feb 13, 2024
1 parent edf4588 commit 21f39d5
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TeamController {
"- 401 = TOKEN_UNAUTHENTICATED\n" +
"- 403 = TOKEN_UNAUTHORIZED\n" +
"- 404 = USER_NOT_FOUND\n" +
"- 409 = EXISTING_CURRENT_TEAM || NON_EXISTING_POSITION || TEAM_LEADER_POSITION_UNAVAILABLE\n" +
"- 409 = EXISTING_CURRENT_TEAM || TEAM_LEADER_POSITION_UNAVAILABLE\n" +
"- 500 = SERVER_ERROR\n" +
"- 503 = ONGOING_INSPECTION")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.gabojait.gabojaitspring.domain.team.Team;
import com.gabojait.gabojaitspring.domain.team.TeamMember;
import com.gabojait.gabojaitspring.domain.user.Position;
import com.gabojait.gabojaitspring.domain.user.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;

@Getter
@Setter
Expand All @@ -33,22 +37,28 @@ public class TeamCreateRequest {
@Pattern(regexp = "^https\\:\\/\\/open\\.kakao\\.com\\/.+$", message = "오픈 채팅 URL은 카카오 오픈 채팅 형식만 가능합니다.")
private String openChatUrl;

@ApiModelProperty(position = 5, required = true, value = "디자이너 최대 수")
@ApiModelProperty(position = 5, required = true, value = "포지션", example = "MANAGER",
allowableValues = "DESIGNER, BACKEND, FRONTEND, MANAGER")
@Pattern(regexp = "^(DESIGNER|BACKEND|FRONTEND|MANAGER|NONE)",
message = "포지션은 'DESIGNER', 'BACKEND', 'FRONTEND', 'MANAGER', 또는 'NONE' 중 하나여야 됩니다.")
private String position;

@ApiModelProperty(position = 6, required = true, value = "디자이너 최대 수")
@NotNull(message = "디자이너 최대 수는 필수 입력입니다.")
@PositiveOrZero(message = "디자이너 최대 수는 0 또는 양수만 가능합니다.")
private Byte designerMaxCnt;

@ApiModelProperty(position = 6, required = true, value = "백엔드 최대 수")
@ApiModelProperty(position = 7, required = true, value = "백엔드 최대 수")
@NotNull(message = "백엔드 최대 수는 필수 입력입니다.")
@PositiveOrZero(message = "백엔드 최대 수는 0 또는 양수만 가능합니다.")
private Byte backendMaxCnt;

@ApiModelProperty(position = 7, required = true, value = "프런트 최대 수")
@ApiModelProperty(position = 8, required = true, value = "프런트 최대 수")
@NotNull(message = "프런트 최대 수는 필수 입력입니다.")
@PositiveOrZero(message = "프런트 최대 수는 0 또는 양수만 가능합니다.")
private Byte frontendMaxCnt;

@ApiModelProperty(position = 8, required = true, value = "매니저 최대 수")
@ApiModelProperty(position = 9, required = true, value = "매니저 최대 수")
@NotNull(message = "매니저 최대 수는 필수 입력입니다.")
@PositiveOrZero(message = "매니저 최대 수는 0 또는 양수만 가능합니다.")
private Byte managerMaxCnt;
Expand All @@ -68,7 +78,7 @@ public Team toTeamEntity() {

public TeamMember toTeamMemberEntity(User user, Team team) {
return TeamMember.builder()
.position(user.getPosition())
.position(Position.valueOf(this.position))
.isLeader(true)
.user(user)
.team(team)
Expand All @@ -80,6 +90,7 @@ private TeamCreateRequest(String projectName,
String projectDescription,
String expectation,
String openChatUrl,
String position,
byte designerMaxCnt,
byte backendMaxCnt,
byte frontendMaxCnt,
Expand All @@ -88,6 +99,7 @@ private TeamCreateRequest(String projectName,
this.projectDescription = projectDescription;
this.expectation = expectation;
this.openChatUrl = openChatUrl;
this.position = position;
this.designerMaxCnt = designerMaxCnt;
this.backendMaxCnt = backendMaxCnt;
this.frontendMaxCnt = frontendMaxCnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TeamService {
/**
* 팀 생성 |
* 404(USER_NOT_FOUND)
* 409(EXISTING_CURRENT_TEAM / NON_EXISTING_POSITION / TEAM_LEADER_POSITION_UNAVAILABLE)
* 409(EXISTING_CURRENT_TEAM / TEAM_LEADER_POSITION_UNAVAILABLE)
* @param userId 회원 식별자
* @param request 팀 생성 요청
* @return 팀 생성 응답
Expand All @@ -53,7 +53,6 @@ public TeamCreateResponse createTeam(long userId, TeamCreateRequest request) {
User user = findUser(userId);

validateHasNoCurrentTeam(user.getId());
validateHasPosition(user);
validateLeaderPosition(request, user);

Team team = request.toTeamEntity();
Expand Down Expand Up @@ -290,16 +289,6 @@ private void validateHasNoCurrentTeam(long userId) {
throw new CustomException(EXISTING_CURRENT_TEAM);
}

/**
* 현재 포지션 존재 검증 |
* 409(NON_EXISTING_POSITION)
* @param user 회원
*/
private void validateHasPosition(User user) {
if (!user.hasPosition())
throw new CustomException(NON_EXISTING_POSITION);
}

/**
* 현재 팀장 여부 검증 |
* 403(REQUEST_FORBIDDEN)
Expand All @@ -317,7 +306,7 @@ private void validateLeader(TeamMember teamMember) {
* @param user 회원
*/
private void validateLeaderPosition(TeamCreateRequest request, User user) {
switch (user.getPosition()) {
switch (Position.valueOf(request.getPosition())) {
case DESIGNER:
if (request.getDesignerMaxCnt() <= 0)
throw new CustomException(TEAM_LEADER_POSITION_UNAVAILABLE);
Expand Down
Loading

0 comments on commit 21f39d5

Please sign in to comment.