Skip to content

Commit

Permalink
[umc-artistack#13] feat: 스택 조회 API 페이징, query string 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeeeyeon committed Aug 23, 2022
1 parent 98348ce commit f63dc15
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -143,25 +146,32 @@ public DataResponseDto<Object> getProjectLikeUsers(

/**
* 스택 조회 API - 제이
* [Get] /projects/{projectId}/prev
* [Get] /projects/{projectId}/next
* [Get] /projects/{projectId}/prev?current=true
* [Get] /projects/{projectId}/next?current=true
*/
@ApiOperation(value = "스택 조회")
@ApiImplicitParams( value = {
@ApiImplicitParam(name = "projectId", value = "현재 프로젝트 id", required = true, dataType = "long", paramType = "path"),
@ApiImplicitParam(name = "sequence", value = "순서(prev or next)", required = true, dataType = "string", paramType = "path")})
@GetMapping("/{projectId}/{sequence}")
public DataResponseDto<Object> getStack(@PathVariable Long projectId, @PathVariable String sequence) {
public DataResponseDto<Object> getStack(
@PageableDefault(size = 6) Pageable pageable,
@PathVariable Long projectId, @PathVariable String sequence,
@RequestParam(defaultValue = "true") Boolean current) {
// validation
// 1. query parameter가 next, prev를 제외한 다른 값이 들어올 경우
if (!(sequence.equals("next") || sequence.equals("prev"))) {
throw new GeneralException(Code.INVALID_SEQUENCE, "sequence는 prev나 next만 사용할 수 있습니다.");
}

try {
List<UserDto> stackers = projectService.getStackers(projectId, sequence);
List<UserDto> stackers = projectService.getStackers(projectId, sequence, current);

return DataResponseDto.of(stackers);
final int start = (int) pageable.getOffset();
final int end = Math.min((start + pageable.getPageSize()), stackers.size());
final Page<UserDto> page = new PageImpl<>(stackers.subList(start, end), pageable, stackers.size());

return DataResponseDto.of(page);

} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit f63dc15

Please sign in to comment.