Skip to content

Commit

Permalink
Merge pull request #215 from Gongjakso/fix/team
Browse files Browse the repository at this point in the history
fix: Team API 업데이트 및 오류 수정
  • Loading branch information
dl-00-e8 authored Sep 21, 2024
2 parents 52c21cc + 73c1537 commit 31358bb
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ public ApplicationResponse<Page<SimpleTeamRes>> getScrapTeamList(@Authentication
@PageableDefault(size = 8) Pageable pageable) {
return ApplicationResponse.ok(teamService.getScrapTeamList(principalDetails.getMember(), pageable));
}

@Operation(summary = "팀 활동 상태 변경 API", description = "팀의 활동 상태를 변경한다.")
@PatchMapping("/contest/{contest_id}/team/{team_id}/change-status")
public ApplicationResponse<TeamRes> changeTeamStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(value = "contest_id") Long contestId,
@PathVariable(value = "team_id") Long teamId,
@RequestParam(value = "status") String status) {
return ApplicationResponse.ok(teamService.changeTeamStatus(principalDetails.getMember(), contestId, teamId, status));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ public record SimpleTeamRes(
@Schema(description = "팀 제목", example = "광화문광장 숏폼 공모전 참여자 모집")
String title,

@Schema(description = "멤버 ID", example = "1")
Long memberId,
@Schema(description = "팀장 ID", example = "1")
Long leaderId,

@Schema(description = "멤버 이름", example = "홍길동")
String memberName,
@Schema(description = "팀장 이름", example = "홍길동")
String leaderName,

@Schema(description = "공모전 ID", example = "1")
Long contestId,

@Schema(description = "팀 상태", example = "모집 중|모집 연장|모집 취소|모집 마감|활동 중|활동 종료")
String status,

@Schema(description = "모집 마감일", example = "2024-12-31")
LocalDate recruitFinishedAt,
Expand Down Expand Up @@ -52,8 +58,10 @@ public static SimpleTeamRes of(Team team) {
return SimpleTeamRes.builder()
.id(team.getId())
.title(team.getTitle())
.memberId(team.getMember().getId())
.memberName(team.getMember().getName())
.leaderId(team.getMember().getId())
.leaderName(team.getMember().getName())
.contestId(team.getContest().getId())
.status(team.getStatus().getDescription())
.recruitFinishedAt(team.getRecruitFinishedAt())
.startedAt(team.getStartedAt())
.finishedAt(team.getFinishedAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public record TeamRes(
@Schema(description = "팀 ID", example = "1")
Long id,

@Schema(description = "멤버 ID", example = "1")
Long memberId,
@Schema(description = "팀장 ID", example = "1")
Long leaderId,

@Schema(description = "멤버 이름", example = "홍길동")
String memberName,
@Schema(description = "팀장 이름", example = "홍길동")
String leaderName,

@Schema(description = "공모전 ID", example = "1")
Long contestId,
Expand All @@ -36,6 +36,9 @@ public record TeamRes(
@Schema(description = "팀 내용", example = "광화문광장 숏폼 공모전 참여자 모집합니다.")
String body,

@Schema(description = "팀 상태", example = "모집 중|모집 연장|모집 취소|모집 마감|활동 중|활동 종료")
String status,

@Schema(description = "총 인원", example = "5")
int totalCount,

Expand Down Expand Up @@ -66,6 +69,9 @@ public record TeamRes(
@Schema(description = "컨택 링크", example = "https://open.kakao.com/o/gongjakso")
String channelLink,

@Schema(description = "공모전 공고 링크", example = "https://www.ictfestival.or.kr/")
String contestLink,

@Schema(description = "스크랩 수", example = "10")
int scrapCount,

Expand Down Expand Up @@ -106,12 +112,13 @@ public static TeamRes of(Team team, String teamRole) {

return TeamRes.builder()
.id(team.getId())
.memberId(team.getMember().getId())
.memberName(team.getMember().getName())
.leaderId(team.getMember().getId())
.leaderName(team.getMember().getName())
.contestId(team.getContest().getId())
.contestTitle(team.getContest().getTitle())
.title(team.getTitle())
.body(team.getTitle())
.status(team.getStatus().getDescription())
.totalCount(team.getTotalCount())
.passCount(team.getPassCount())
.meetingMethod(team.getMeetingMethod().getDescription())
Expand All @@ -122,6 +129,7 @@ public static TeamRes of(Team team, String teamRole) {
.startedAt(team.getStartedAt())
.finishedAt(team.getFinishedAt())
.channelLink(team.getChannelLink())
.contestLink(team.getContest().getContestLink())
.scrapCount(team.getScrapCount())
.teamRole(teamRole)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Team(Member member,
this.contest = contest;
this.title = title;
this.body = body;
this.status = TeamStatus.ACTIVE;
this.status = TeamStatus.RECRUITING;
this.totalCount = totalCount;
this.passCount = 0;
this.meetingMethod = meetingMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package com.gongjakso.server.domain.team.enumerate;

import com.gongjakso.server.global.exception.ApplicationException;
import com.gongjakso.server.global.exception.ErrorCode;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public enum TeamStatus {

ACTIVE("모집 중"),
RECRUITING("모집 중"),
EXTENSION("모집 연장"),
CANCELED("모집 취소"),
CLOSED("모집 마감"),;
CLOSED("모집 마감"),
ACTIVE("활동 중"),
FINISHED("활동 종료");

private final String description;

TeamStatus(String description) {
this.description = description;
}

/**
* 활동 중 또는 활동 종료를 업데이트할 때 유효성 검사하는 메소드
* @param status 입력받은 활동 문자열 (한국어)
* @return 해당 문자열에 해당하는 ENUM 값
*/
public static TeamStatus checkActiveORFinished(String status) {
if(status.equals(ACTIVE.getDescription())) {
return ACTIVE;
} else if(status.equals(FINISHED.getDescription())) {
return FINISHED;
}
throw new ApplicationException(ErrorCode.INVALID_TEAM_STATUS_EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public Optional<Team> findTeamById(Long id) {
public Page<SimpleTeamRes> findPaginationWithContest(Long contestId, String province, String district, Pageable pageable) {
BooleanBuilder builder = new BooleanBuilder();

if(province != null) {
if(province != null && !province.isEmpty()) {
builder.and(team.province.eq(province));
}
if(district != null) {
if(district != null && !district.isEmpty()) {
builder.and(team.district.eq(district));
}

Expand All @@ -60,6 +60,7 @@ public Page<SimpleTeamRes> findPaginationWithContest(Long contestId, String prov
Long total = queryFactory.select(team.count())
.from(team)
.where(
team.contest.id.eq(contestId),
team.deletedAt.isNull(),
builder
)
Expand All @@ -71,13 +72,13 @@ public Page<SimpleTeamRes> findPaginationWithContest(Long contestId, String prov
public Page<SimpleTeamRes> findPaginationWithoutContest(String province, String district, String keyword, Pageable pageable) {
BooleanBuilder builder = new BooleanBuilder();

if(province != null) {
if(province != null && !province.isEmpty()) {
builder.and(team.province.eq(province));
}
if(district != null) {
if(district != null && !district.isEmpty()) {
builder.and(team.district.eq(district));
}
if (keyword != null) {
if (keyword != null && !keyword.isEmpty()) {
builder.and(team.title.containsIgnoreCase(keyword).or(team.body.containsIgnoreCase(keyword)));
}

Expand All @@ -98,7 +99,6 @@ public Page<SimpleTeamRes> findPaginationWithoutContest(String province, String
Long total = queryFactory.select(team.count())
.from(team)
.where(
team.title.containsIgnoreCase(keyword),
team.deletedAt.isNull(),
builder
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,26 @@ public Page<SimpleTeamRes> getScrapTeamList(Member member, Pageable pageable) {
// Business Logic & Response
return teamRepository.findScrapPagination(member.getId(), pageable);
}

public TeamRes changeTeamStatus(Member member, Long contestId, Long teamId, String status) {
// Validation
contestRepository.findByIdAndDeletedAtIsNull(contestId)
.orElseThrow(() -> new ApplicationException(ErrorCode.CONTEST_NOT_FOUND_EXCEPTION));
Team team = teamRepository.findByIdAndDeletedAtIsNull(teamId)
.orElseThrow(() -> new ApplicationException(ErrorCode.TEAM_NOT_FOUND_EXCEPTION));
if (!team.getContest().getId().equals(contestId)) {
throw new ApplicationException(ErrorCode.INVALID_VALUE_EXCEPTION);
}
if (!team.getMember().getId().equals(member.getId())) {
throw new ApplicationException(ErrorCode.FORBIDDEN_EXCEPTION);
}
TeamStatus teamStatus = TeamStatus.checkActiveORFinished(status);

// Business Logic
team.updateTeamStatus(teamStatus);
Team updatedTeam = teamRepository.save(team);

// Response
return TeamRes.of(updatedTeam, "LEADER");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ErrorCode {
// 5000: Team Error
TEAM_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, 5000, "존재하지 않는 팀입니다."),
INVALID_POSITION_EXCEPTION(HttpStatus.BAD_REQUEST, 5001, "올바르지 않은 포지션입니다."),
INVALID_TEAM_STATUS_EXCEPTION(HttpStatus.BAD_REQUEST, 5002, "올바르지 않은 팀 상태입니다."),

// 6000: Portfolio Error
PORTFOLIO_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, 6000, "포트폴리오를 찾을 수 없습니다."),
Expand Down

0 comments on commit 31358bb

Please sign in to comment.