Skip to content

Commit

Permalink
✨ 내 수집함 - 편지지 -> 마이디자인만 조회 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
u-genuine committed Feb 6, 2024
1 parent 09d700e commit 36a7e25
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aromanticcat.umcproject.converter;

import aromanticcat.umcproject.entity.AcquiredItem;
import aromanticcat.umcproject.entity.MyLetterPaper;
import aromanticcat.umcproject.entity.MyStamp;
import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;

Expand All @@ -22,7 +23,14 @@ public static MyCollectionResponseDTO.AcquiredStampResultDTO toAcquiredStampResu
.acquiredAt(stamp.getCreatedAt())
.build();
}

public static MyCollectionResponseDTO.AcquiredLetterPaperResultDTO toMyLetterPaperResultDTO(MyLetterPaper myLetterPaper){
return MyCollectionResponseDTO.AcquiredLetterPaperResultDTO.builder()
.letterPaperId(myLetterPaper.getMPaper_id())
.letterPaperName(myLetterPaper.getName())
.letterPaperImageUrl(myLetterPaper.getImageUrl())
.acquiredAt(myLetterPaper.getCreatedAt())
.build();
}
public static MyCollectionResponseDTO.AcquiredStampResultDTO toMyStampResultDTO(MyStamp stamp){
return MyCollectionResponseDTO.AcquiredStampResultDTO.builder()
.stampId(stamp.getMStamp_id())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package aromanticcat.umcproject.repository;

import aromanticcat.umcproject.entity.Letterbox;
import aromanticcat.umcproject.entity.MyLetterPaper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MyLetterPaperRepository extends JpaRepository<MyLetterPaper, Long> {
Page<MyLetterPaper> findByMemberId(Long memberId, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

public interface MyCollectionService {

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(Long memberId, int page, int pageSize);
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(Long memberId, int page, int pageSize, boolean onlyMyDesign);
List<MyCollectionResponseDTO.AcquiredStampResultDTO> findStampList(Long memberId, int page, int pageSize, boolean onlyMyDesign);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import aromanticcat.umcproject.converter.MyCollectionConverter;
import aromanticcat.umcproject.entity.AcquiredItem;
import aromanticcat.umcproject.entity.MyLetterPaper;
import aromanticcat.umcproject.entity.MyStamp;
import aromanticcat.umcproject.repository.AcquiredItemRepository;
import aromanticcat.umcproject.repository.MyLetterPaperRepository;
import aromanticcat.umcproject.repository.MyStampRepository;
import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,21 +25,44 @@
public class MyCollectionServiceImpl implements MyCollectionService {

private final AcquiredItemRepository acquiredItemRepository;
private final MyLetterPaperRepository myLetterPaperRepository;
private final MyStampRepository myStampRepository;

@Override
@Transactional
public List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(Long memberId, int page, int pageSize) {
public List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(Long memberId, int page, int pageSize, boolean onlyMyDesign) {
Pageable pageable = PageRequest.of(page, pageSize);
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> responseDTOs;

// 사용자가 구매한 편지지 목록 조회
Page<AcquiredItem> acquiredLetterPaperPage = acquiredItemRepository.findByMemberIdAndLetterPaperIdIsNotNull(memberId, pageable);
if(onlyMyDesign) {
Page<MyLetterPaper> myLetterPaperPage = myLetterPaperRepository.findByMemberId(memberId, pageable);
List<MyLetterPaper> myLetterPaperList = myLetterPaperPage.getContent();

List<AcquiredItem> acquiredLetterPaperList = acquiredLetterPaperPage.getContent();
responseDTOs = myLetterPaperList.stream()
.map(myLetterPaper -> MyCollectionConverter.toMyLetterPaperResultDTO(myLetterPaper))
.collect(Collectors.toList());
}else {
// 사용자가 구매한 편지지 목록 조회
Page<AcquiredItem> acquiredLetterPaperPage = acquiredItemRepository.findByMemberIdAndLetterPaperIdIsNotNull(memberId, pageable);
List<AcquiredItem> acquiredLetterPaperList = acquiredLetterPaperPage.getContent();

// 마이 디자인 편지지 목록 조회
Page<MyLetterPaper> myLetterPaperPage = myLetterPaperRepository.findByMemberId(memberId, pageable);
List<MyLetterPaper> myLetterPaperList = myLetterPaperPage.getContent();

// MyLetterPaper와 AcquredItem에서 가져온 편지지 목록 병합
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> myLetterPaperDTOs = myLetterPaperList.stream()
.map(myLetterPaper -> MyCollectionConverter.toMyLetterPaperResultDTO(myLetterPaper))
.collect(Collectors.toList());

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> acquiredLetterPaperDTOs = acquiredLetterPaperList.stream()
.map(letterPaper -> MyCollectionConverter.toAcquiredLetterPaperResultDTO(letterPaper))
.collect(Collectors.toList());

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> responseDTOs = acquiredLetterPaperList.stream()
.map(letterPaper -> MyCollectionConverter.toAcquiredLetterPaperResultDTO(letterPaper))
.collect(Collectors.toList());
responseDTOs = new ArrayList<>();
responseDTOs.addAll(myLetterPaperDTOs);
responseDTOs.addAll(acquiredLetterPaperDTOs);
}
return responseDTOs;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public class MyCollectionController {
description = "페이징을 포함합니다. query String으로 page(기본값 0)와 pageSize(기본값 12)를 주세요.")
public ApiResponse<List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO>> getMyLetterPaperList(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "12") int pageSize) {
@RequestParam(defaultValue = "12") int pageSize,
@RequestParam(defaultValue = "false")boolean onlyMyDesign) {
try {
// 로그인한 사용자의 아이디를 가져오는 메서드
Long userId = getCurrentUserId();

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> letterPaperList = myCollectionService.findLetterPaperList(userId, page, pageSize);
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> letterPaperList = myCollectionService.findLetterPaperList(userId, page, pageSize, onlyMyDesign);

return ApiResponse.onSuccess(letterPaperList);

Expand Down

0 comments on commit 36a7e25

Please sign in to comment.