Skip to content

Commit

Permalink
[DOCS] 내 포트폴리오 목록 API 스웨거 (#254)
Browse files Browse the repository at this point in the history
* [RENAME] Dto 클래스명 변경

* [DOCS] 내 포트폴리오 목록 조회 API 스웨거 작성

* [RENAME] PaginationDto로 변경

* [ADD] Portfolio용 PaginationDto 추가

* [CHORE] 충돌 해결
  • Loading branch information
Goder-0 authored Apr 16, 2024
1 parent 1494b35 commit 4e24e67
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.request.CreatePortfolioRequestDto;
import synk.meeteam.domain.portfolio.portfolio.dto.request.UpdatePortfolioRequestDto;
import synk.meeteam.domain.portfolio.portfolio.dto.response.GetPortfolioResponseDto;
import synk.meeteam.domain.user.user.entity.User;
import synk.meeteam.global.dto.PaginationPortfolioDto;
import synk.meeteam.security.AuthUser;

@Tag(name = "Portfolio", description = "포트폴리오 관련 API")
Expand Down Expand Up @@ -44,4 +48,15 @@ public interface PortfolioApi {
ResponseEntity<Long> modifyPortfolio(@AuthUser User user,
@PathVariable Long portfolioId,
@RequestBody @Valid UpdatePortfolioRequestDto requestDto);

@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "포트폴리오 목록 조회 성공"),
}
)
@Operation(summary = "내 포트폴리오 목록 조회 API")
ResponseEntity<PaginationPortfolioDto<SimplePortfolioDto>> getMyPortfolios(
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@AuthUser User user);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package synk.meeteam.domain.portfolio.portfolio.api;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -9,12 +11,16 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.request.CreatePortfolioRequestDto;
import synk.meeteam.domain.portfolio.portfolio.dto.request.UpdatePortfolioRequestDto;
import synk.meeteam.domain.portfolio.portfolio.dto.response.GetPortfolioResponseDto;
import synk.meeteam.domain.portfolio.portfolio.service.PortfolioFacade;
import synk.meeteam.domain.user.user.entity.User;
import synk.meeteam.global.dto.PageInfo;
import synk.meeteam.global.dto.PaginationPortfolioDto;
import synk.meeteam.security.AuthUser;

@RestController
Expand Down Expand Up @@ -44,4 +50,26 @@ public ResponseEntity<Long> modifyPortfolio(@AuthUser User user, @PathVariable("
@RequestBody @Valid UpdatePortfolioRequestDto requestDto) {
return ResponseEntity.ok(portfolioFacade.editPortfolio(portfolioId, user, requestDto));
}

@GetMapping
@Override
public ResponseEntity<PaginationPortfolioDto<SimplePortfolioDto>> getMyPortfolios(
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@AuthUser User user) {
return ResponseEntity.ok().body(new PaginationPortfolioDto<>(
List.of(
new SimplePortfolioDto(
1L,
"Meeteam",
"https://image.png",
"개발",
"역할",
true,
1
)
),
new PageInfo(1, 24, 1L, 1)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Data
@NoArgsConstructor
public class GetProfilePortfolioDto {
public class SimplePortfolioDto {
@Schema(description = "포트폴리오 id", example = "1")
private Long id;
@Schema(description = "제목", example = "Meeteam")
Expand All @@ -26,9 +26,9 @@ public class GetProfilePortfolioDto {

@Builder
@QueryProjection
public GetProfilePortfolioDto(Long id, String title, String mainImageUrl, String field, String role,
boolean isPinned,
int pinOrder) {
public SimplePortfolioDto(Long id, String title, String mainImageUrl, String field, String role,
boolean isPinned,
int pinOrder) {
this.id = id;
this.title = title;
this.mainImageUrl = mainImageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.LocalDate;
import java.util.List;
import synk.meeteam.domain.common.skill.dto.SkillDto;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio_link.dto.PortfolioLinkDto;

public record GetPortfolioResponseDto(
Expand Down Expand Up @@ -39,7 +39,7 @@ public record GetPortfolioResponseDto(
String proceedType,
List<SkillDto> skills,
List<PortfolioLinkDto> links,
List<GetProfilePortfolioDto> otherPortfolios,
List<SimplePortfolioDto> otherPortfolios,
@Schema(description = "작성자여부", example = "true")
boolean isWriter
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package synk.meeteam.domain.portfolio.portfolio.dto.response;

import java.util.List;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.global.dto.SliceInfo;

public record GetUserPortfolioResponseDto(
List<GetProfilePortfolioDto> portfolios,
List<SimplePortfolioDto> portfolios,
SliceInfo pageInfo
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.mapstruct.ReportingPolicy;
import synk.meeteam.domain.common.field.entity.Field;
import synk.meeteam.domain.common.role.entity.Role;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = "spring")
public interface PortfolioMapper {
Expand All @@ -24,5 +24,5 @@ static String toRole(Role role) {
@Mapping(target = "field", qualifiedByName = "toField")
@Mapping(target = "role", qualifiedByName = "toRole")
@Mapping(source = "portfolio.isPin", target = "isPinned")
GetProfilePortfolioDto toGetProfilePortfolioDto(Portfolio portfolio, String mainImageUrl);
SimplePortfolioDto toGetProfilePortfolioDto(Portfolio portfolio, String mainImageUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.entity.Portfolio;
import synk.meeteam.domain.user.user.entity.User;

public interface PortfolioCustomRepository {
Slice<GetProfilePortfolioDto> findUserPortfoliosByUserOrderByCreatedAtDesc(Pageable pageable, User user);
Slice<SimplePortfolioDto> findUserPortfoliosByUserOrderByCreatedAtDesc(Pageable pageable, User user);

List<Portfolio> findAllByCreatedByAndIsPinTrueOrderByIds(Long userId, List<Long> portfolioIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.stereotype.Repository;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.QGetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.QSimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.entity.Portfolio;
import synk.meeteam.domain.user.user.entity.User;

Expand All @@ -39,9 +39,9 @@ public List<Portfolio> findAllByCreatedByAndIsPinTrueOrderByIds(Long userId, Lis
}

@Override
public Slice<GetProfilePortfolioDto> findUserPortfoliosByUserOrderByCreatedAtDesc(Pageable pageable, User user) {
List<GetProfilePortfolioDto> contents = queryFactory
.select(new QGetProfilePortfolioDto(
public Slice<SimplePortfolioDto> findUserPortfoliosByUserOrderByCreatedAtDesc(Pageable pageable, User user) {
List<SimplePortfolioDto> contents = queryFactory
.select(new QSimplePortfolioDto(
portfolio.id,
portfolio.title,
portfolio.mainImageFileName,
Expand All @@ -61,7 +61,7 @@ public Slice<GetProfilePortfolioDto> findUserPortfoliosByUserOrderByCreatedAtDes
return new SliceImpl<>(contents, pageable, hasNextPage(contents, pageable.getPageSize()));
}

private boolean hasNextPage(List<GetProfilePortfolioDto> contents, int pageSize) {
private boolean hasNextPage(List<SimplePortfolioDto> contents, int pageSize) {
if (contents.size() > pageSize) {
contents.remove(pageSize);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import synk.meeteam.domain.common.field.repository.FieldRepository;
import synk.meeteam.domain.common.role.entity.Role;
import synk.meeteam.domain.common.role.repository.RoleRepository;
import synk.meeteam.domain.portfolio.portfolio.dto.GetProfilePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.SimplePortfolioDto;
import synk.meeteam.domain.portfolio.portfolio.dto.command.CreatePortfolioCommand;
import synk.meeteam.domain.portfolio.portfolio.dto.command.UpdatePortfolioCommand;
import synk.meeteam.domain.portfolio.portfolio.dto.response.GetUserPortfolioResponseDto;
Expand Down Expand Up @@ -69,7 +69,7 @@ public List<Portfolio> getMyPinPortfolio(Long userId) {
public GetUserPortfolioResponseDto getMyAllPortfolio(int page, int size, User user) {
int pageNumber = page - 1;
Pageable pageable = PageRequest.of(pageNumber, size);
Slice<GetProfilePortfolioDto> userPortfolioDtos = portfolioRepository.findUserPortfoliosByUserOrderByCreatedAtDesc(
Slice<SimplePortfolioDto> userPortfolioDtos = portfolioRepository.findUserPortfoliosByUserOrderByCreatedAtDesc(
pageable, user);
SliceInfo pageInfo = new SliceInfo(page, size, userPortfolioDtos.hasNext());
return new GetUserPortfolioResponseDto(userPortfolioDtos.getContent(), pageInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import synk.meeteam.domain.recruitment.recruitment_post.dto.response.SimpleRecruitmentPostDto;
import synk.meeteam.domain.user.user.entity.User;
import synk.meeteam.global.dto.PageNationDto;
import synk.meeteam.global.dto.PaginationDto;
import synk.meeteam.security.AuthUser;

@Tag(name = "management", description = "내 구인글 관리 관련 API")
Expand All @@ -22,7 +22,7 @@ public interface PostManagementApi {
)
@Operation(summary = "북마크한 구인글 조회")
@SecurityRequirement(name = "Authorization")
PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User user,
PaginationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed);
Expand All @@ -34,7 +34,7 @@ PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User user,
)
@Operation(summary = "내가 신청한 구인글 조회")
@SecurityRequirement(name = "Authorization")
PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User user,
PaginationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed);
Expand All @@ -46,7 +46,7 @@ PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User user,
)
@Operation(summary = "내가 작성한 구인글 조회")
@SecurityRequirement(name = "Authorization")
PageNationDto<SimpleRecruitmentPostDto> getMyPost(@AuthUser User user,
PaginationDto<SimpleRecruitmentPostDto> getMyPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import synk.meeteam.domain.recruitment.recruitment_post.dto.response.SimpleRecruitmentPostDto;
import synk.meeteam.domain.recruitment.recruitment_post.service.RecruitmentPostService;
import synk.meeteam.domain.user.user.entity.User;
import synk.meeteam.global.dto.PageNationDto;
import synk.meeteam.global.dto.PageInfo;
import synk.meeteam.global.dto.PaginationDto;
import synk.meeteam.security.AuthUser;

@RestController
Expand All @@ -22,7 +23,7 @@ public class PostManagementController implements PostManagementApi {

@GetMapping("/bookmark")
@Override
public PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User user,
public PaginationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed) {
Expand All @@ -31,7 +32,7 @@ public PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(@AuthUser User us

@GetMapping("/applied")
@Override
public PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User user,
public PaginationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed) {
Expand All @@ -40,7 +41,7 @@ public PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(@AuthUser User use

@GetMapping("/myPost")
@Override
public PageNationDto<SimpleRecruitmentPostDto> getMyPost(@AuthUser User user,
public PaginationDto<SimpleRecruitmentPostDto> getMyPost(@AuthUser User user,
@RequestParam(value = "size", required = false, defaultValue = "24") @Valid @Min(1) int size,
@RequestParam(value = "page", required = false, defaultValue = "1") @Valid @Min(1) int page,
@RequestParam(value = "is-closed", required = false) Boolean isClosed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import synk.meeteam.domain.recruitment.recruitment_post.repository.vo.RecruitmentPostVo;
import synk.meeteam.domain.user.user.entity.User;
import synk.meeteam.global.dto.PageInfo;
import synk.meeteam.global.dto.PageNationDto;
import synk.meeteam.global.dto.PaginationDto;
import synk.meeteam.global.entity.Scope;
import synk.meeteam.global.util.Encryption;
import synk.meeteam.infra.s3.S3FileName;
Expand Down Expand Up @@ -129,7 +129,7 @@ public void incrementResponseCount(Long postId, Long userId, long responseCount)
}

@Transactional
public PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(int size, int page, User user, Boolean isClosed) {
public PaginationDto<SimpleRecruitmentPostDto> getBookmarkPost(int size, int page, User user, Boolean isClosed) {
Page<RecruitmentPostVo> postVos = recruitmentPostRepository.findMyBookmarkPost(PageRequest.of(page - 1, size),
user, isClosed);
PageInfo pageInfo = new PageInfo(page, size, postVos.getTotalElements(), postVos.getTotalPages());
Expand All @@ -139,11 +139,11 @@ public PageNationDto<SimpleRecruitmentPostDto> getBookmarkPost(int size, int pag
String imageUrl = s3Service.createPreSignedGetUrl(S3FileName.USER, postVo.getWriterProfileImg());
return simpleRecruitmentPostMapper.toSimpleRecruitmentPostDto(postVo, writerEncryptedId, imageUrl);
}).toList();
return new PageNationDto<>(contents, pageInfo);
return new PaginationDto<>(contents, pageInfo);
}

@Transactional
public PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(int size, int page, User user, Boolean isClosed) {
public PaginationDto<SimpleRecruitmentPostDto> getAppliedPost(int size, int page, User user, Boolean isClosed) {
Page<RecruitmentPostVo> postVos = recruitmentPostRepository.findMyAppliedPost(PageRequest.of(page - 1, size),
user, isClosed);
PageInfo pageInfo = new PageInfo(page, size, postVos.getTotalElements(), postVos.getTotalPages());
Expand All @@ -153,11 +153,11 @@ public PageNationDto<SimpleRecruitmentPostDto> getAppliedPost(int size, int page
String imageUrl = s3Service.createPreSignedGetUrl(S3FileName.USER, postVo.getWriterProfileImg());
return simpleRecruitmentPostMapper.toSimpleRecruitmentPostDto(postVo, writerEncryptedId, imageUrl);
}).toList();
return new PageNationDto<>(contents, pageInfo);
return new PaginationDto<>(contents, pageInfo);
}

@Transactional
public PageNationDto<SimpleRecruitmentPostDto> getMyPost(int size, int page, User user, Boolean isClosed) {
public PaginationDto<SimpleRecruitmentPostDto> getMyPost(int size, int page, User user, Boolean isClosed) {
Page<RecruitmentPostVo> postVos = recruitmentPostRepository.findMyPost(PageRequest.of(page - 1, size),
user, isClosed);
PageInfo pageInfo = new PageInfo(page, size, postVos.getTotalElements(), postVos.getTotalPages());
Expand All @@ -167,6 +167,6 @@ public PageNationDto<SimpleRecruitmentPostDto> getMyPost(int size, int page, Use
String imageUrl = s3Service.createPreSignedGetUrl(S3FileName.USER, postVo.getWriterProfileImg());
return simpleRecruitmentPostMapper.toSimpleRecruitmentPostDto(postVo, writerEncryptedId, imageUrl);
}).toList();
return new PageNationDto<>(contents, pageInfo);
return new PaginationDto<>(contents, pageInfo);
}
}
Loading

0 comments on commit 4e24e67

Please sign in to comment.