Skip to content

Commit

Permalink
Merge pull request #245 from Gongjakso/fix/team
Browse files Browse the repository at this point in the history
fix: QA 사항 업데이트
  • Loading branch information
dl-00-e8 authored Sep 23, 2024
2 parents 8970f67 + a9f3698 commit 0173906
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -89,7 +90,11 @@ public ApplicationResponse<TeamRes> getTeam(@AuthenticationPrincipal PrincipalDe
return ApplicationResponse.ok(teamService.getTeam(principalDetails == null ? null : principalDetails.getMember(), contestId, teamId));
}

@Operation(summary = "팀 리스트 조회 API", description = "특정 공모전에 해당하는 팀 리스트를 조회하는 API (오프셋 기반 페이지네이션)")
@Operation(summary = "팀 리스트 조회 API",
description = "특정 공모전에 해당하는 팀 리스트를 조회하는 API (오프셋 기반 페이지네이션)",
parameters = {
@Parameter(name = "sort", description = "정렬 기준 (예시- 생성 시각 내림차순 createdAt,desc / 인기순 오름차순 scrap,asc", required = false),
})
@GetMapping("/contest/{contest_id}/team/list")
public ApplicationResponse<Page<SimpleTeamRes>> getTeamList(@PathVariable(value = "contest_id") Long contestId,
@RequestParam(value = "province", required = false) String province,
Expand All @@ -98,7 +103,12 @@ public ApplicationResponse<Page<SimpleTeamRes>> getTeamList(@PathVariable(value
return ApplicationResponse.ok(teamService.getTeamListWithContest(contestId, province, district, pageable));
}

@Operation(summary = "팀 리스트 조회 API", description = "공모전에 상관없이 팀 리스트를 조회하는 API (검색 기능 존재 / 오프셋 기반 페이지네이션)")
@Operation(summary = "팀 리스트 조회 API",
method = "GET",
description = "공모전에 상관없이 팀 리스트를 조회하는 API (검색 기능 존재 / 오프셋 기반 페이지네이션)",
parameters = {
@Parameter(name = "sort", description = "정렬 기준 (예시- 생성 시각 내림차순 createdAt,desc / 인기순 오름차순 scrap,asc", required = false),
})
@GetMapping("/team/list")
public ApplicationResponse<Page<SimpleTeamRes>> getTeamList(@RequestParam(value = "province", required = false) String province,
@RequestParam(value = "district", required = false) String district,
Expand All @@ -110,7 +120,7 @@ public ApplicationResponse<Page<SimpleTeamRes>> getTeamList(@RequestParam(value
@Operation(summary = "내가 모집 중인 팀 리스트 조회 API", description = "공모전에 상관없이 내가 모집 중인 팀 리스트를 조회하는 API (오프셋 기반 페이지네이션)")
@GetMapping("/team/my-recruit")
public ApplicationResponse<Page<SimpleTeamRes>> getMyRecruitTeamList(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PageableDefault(size = 8) Pageable pageable) {
@PageableDefault(size = 8) Pageable pageable) {
return ApplicationResponse.ok(teamService.getMyRecruitTeamList(principalDetails.getMember(), pageable));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import com.gongjakso.server.domain.team.dto.response.SimpleTeamRes;
import com.gongjakso.server.domain.team.entity.Team;
import com.gongjakso.server.domain.team.enumerate.TeamStatus;
import com.gongjakso.server.global.exception.ApplicationException;
import com.gongjakso.server.global.exception.ErrorCode;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -50,7 +55,7 @@ public Page<SimpleTeamRes> findPaginationWithContest(Long contestId, String prov
team.deletedAt.isNull(),
builder
)
.orderBy(team.createdAt.desc())
.orderBy(getSort(pageable).toArray(OrderSpecifier[]::new))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand Down Expand Up @@ -89,7 +94,7 @@ public Page<SimpleTeamRes> findPaginationWithoutContest(String province, String
.from(team)
.where(team.deletedAt.isNull()
.and(builder))
.orderBy(team.createdAt.desc())
.orderBy(getSort(pageable).toArray(OrderSpecifier[]::new))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -110,11 +115,14 @@ public Page<SimpleTeamRes> findPaginationWithoutContest(String province, String
}

public Page<SimpleTeamRes> findRecruitPagination(Long memberId, Pageable pageable) {
List<TeamStatus> teamStatusList = Arrays.asList(TeamStatus.RECRUITING, TeamStatus.EXTENSION);

List<Team> teamList = queryFactory
.select(team)
.from(team)
.where(
team.member.id.eq(memberId),
team.status.in(teamStatusList),
team.deletedAt.isNull()
)
.orderBy(team.createdAt.desc())
Expand Down Expand Up @@ -232,4 +240,29 @@ public Page<SimpleTeamRes> findScrapPagination(Long memberId, Pageable pageable)

return new PageImpl<>(content, pageable, (total != null) ? total : 0);
}

private List<OrderSpecifier<?>> getSort(Pageable pageable) {
List<OrderSpecifier<?>> orderSpecifierList = new ArrayList<>();

if(pageable.getSort().isEmpty()) {
orderSpecifierList.add(team.createdAt.desc());
return orderSpecifierList;
}

for(Sort.Order order : pageable.getSort()) {
System.out.println(order.getProperty());
switch (order.getProperty()) {
case "createdAt":
orderSpecifierList.add((order.isAscending()) ? team.createdAt.asc() : team.createdAt.desc());
break;
case "scrap":
orderSpecifierList.add((order.isAscending()) ? team.scrapCount.asc() : team.scrapCount.desc());
break;
default:
throw new ApplicationException(ErrorCode.INVALID_SORT_EXCEPTION);
}
}

return orderSpecifierList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ErrorCode {
ALREADY_DELETE_EXCEPTION(HttpStatus.BAD_REQUEST, 2004, "이미 삭제된 리소스입니다."),
FORBIDDEN_EXCEPTION(HttpStatus.FORBIDDEN, 2005, "인가되지 않는 요청입니다."),
ALREADY_EXIST_EXCEPTION(HttpStatus.BAD_REQUEST, 2006, "이미 존재하는 리소스입니다."),
INVALID_SORT_EXCEPTION(HttpStatus.BAD_REQUEST, 2007, "올바르지 않은 정렬 값입니다."),

// 3000: Auth Error
KAKAO_TOKEN_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 3000, "토큰 발급에서 오류가 발생했습니다."),
Expand Down

0 comments on commit 0173906

Please sign in to comment.