Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 내 수집함 마이디자인 포함하도록 수정 #95

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;

public class MyCollectionConverter{
Expand All @@ -21,5 +23,22 @@ 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())
.stampName(stamp.getName())
.stampImageUrl(stamp.getImageUrl())
.acquiredAt(stamp.getCreatedAt())
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Setter
@RequiredArgsConstructor
@Table(name = "myLetterPaper")
public class MyLetterPaper {
public class MyLetterPaper extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mPaper_id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aromanticcat/umcproject/entity/MyStamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Builder
@RequiredArgsConstructor
@Table(name = "myStamp")
public class MyStamp {
public class MyStamp extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mStamp_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
@@ -1,8 +1,12 @@
package aromanticcat.umcproject.repository;

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

public interface MyStampRepository extends JpaRepository<MyStamp, Long> {

Page<MyStamp> findByMemberId(Long memberId, Pageable pageable);

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package aromanticcat.umcproject.service;
package aromanticcat.umcproject.service.myCollectionService;

import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;

import java.util.List;

public interface MyCollectionService {

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(Long memberId, int page, int pageSize);
List<MyCollectionResponseDTO.AcquiredStampResultDTO> findStampList(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
@@ -0,0 +1,114 @@
package aromanticcat.umcproject.service.myCollectionService;

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;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional
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, boolean onlyMyDesign) {
Pageable pageable = PageRequest.of(page, pageSize);
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> responseDTOs;

if(onlyMyDesign) {
Page<MyLetterPaper> myLetterPaperPage = myLetterPaperRepository.findByMemberId(memberId, pageable);
List<MyLetterPaper> myLetterPaperList = myLetterPaperPage.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());

responseDTOs = new ArrayList<>();
responseDTOs.addAll(myLetterPaperDTOs);
responseDTOs.addAll(acquiredLetterPaperDTOs);
}
return responseDTOs;

}

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

if(onlyMyDesign){
Page<MyStamp> myStampPage = myStampRepository.findByMemberId(memberId, pageable);

List<MyStamp> myStampList = myStampPage.getContent();

responseDTOs = myStampList.stream()
.map(myStamp -> MyCollectionConverter.toMyStampResultDTO(myStamp))
.collect(Collectors.toList());
}else{
// 사용자가 구매한 우표 목록 조회
Page<AcquiredItem> acquiredStampPage = acquiredItemRepository.findByMemberIdAndStampIdIsNotNull(memberId, pageable);
List<AcquiredItem> acquiredStampList = acquiredStampPage.getContent();

// 마이 디자인 우표 목록 조회
Page<MyStamp> myStampPage = myStampRepository.findByMemberId(memberId, pageable);
List<MyStamp> myStampList = myStampPage.getContent();

// MyStamp와 AcquredItem에서 가져온 우표 목록 병합
List<MyCollectionResponseDTO.AcquiredStampResultDTO> myStampDTOs = myStampList.stream()
.map(myStamp -> MyCollectionConverter.toMyStampResultDTO(myStamp))
.collect(Collectors.toList());

List<MyCollectionResponseDTO.AcquiredStampResultDTO> acquiredStampDTOs = acquiredStampList.stream()
.map(stamp -> MyCollectionConverter.toAcquiredStampResultDTO(stamp))
.collect(Collectors.toList());

responseDTOs = new ArrayList<>();
responseDTOs.addAll(myStampDTOs);
responseDTOs.addAll(acquiredStampDTOs);
}

return responseDTOs;

}




}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aromanticcat.umcproject.service;
package aromanticcat.umcproject.service.myCollectionService;

import aromanticcat.umcproject.S3.S3Service;
import aromanticcat.umcproject.entity.Member;
Expand All @@ -7,7 +7,6 @@
import aromanticcat.umcproject.repository.MemberRepository;
import aromanticcat.umcproject.repository.MyLetterPaperRepository;
import aromanticcat.umcproject.repository.MyStampRepository;
import aromanticcat.umcproject.repository.StampRepository;
import aromanticcat.umcproject.web.dto.MyDesignRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aromanticcat.umcproject.service;
package aromanticcat.umcproject.service.storeService;

import aromanticcat.umcproject.web.dto.store.StoreResponseDTO;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aromanticcat.umcproject.service;
package aromanticcat.umcproject.service.storeService;

import aromanticcat.umcproject.converter.StoreConverter;
import aromanticcat.umcproject.entity.AcquiredItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aromanticcat.umcproject.web.controller;

import aromanticcat.umcproject.apiPayload.ApiResponse;
import aromanticcat.umcproject.service.MyCollectionService;
import aromanticcat.umcproject.service.myCollectionService.MyCollectionService;
import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
Expand All @@ -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 All @@ -41,18 +42,19 @@ public ApiResponse<List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO>> g

@GetMapping("/stamp")
@Operation(summary = "내 수집함 우표 조회 API",
description = "페이징을 포함합니다. query String으로 page(기본값 0)와 pageSize(기본값 12)를 주세요.")
description = "페이징을 포함합니다. query String으로 page(기본값 0)와 pageSize(기본값 12), onlyMyDesign(기본값 false)를 주세요.")
public ApiResponse<List<MyCollectionResponseDTO.AcquiredStampResultDTO>> getMyStampList(
@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.AcquiredStampResultDTO> stampList = myCollectionService.findStampList(userId, page, pageSize);

List<MyCollectionResponseDTO.AcquiredStampResultDTO> stampList = myCollectionService.findStampList(userId, page, pageSize, onlyMyDesign);
return ApiResponse.onSuccess(stampList);


} catch (Exception e) {
return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aromanticcat.umcproject.web.controller;

import aromanticcat.umcproject.apiPayload.ApiResponse;
import aromanticcat.umcproject.service.MyDesignService;
import aromanticcat.umcproject.service.myCollectionService.MyDesignService;
import aromanticcat.umcproject.web.dto.MyDesignRequest;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aromanticcat.umcproject.web.controller;

import aromanticcat.umcproject.apiPayload.ApiResponse;
import aromanticcat.umcproject.service.StoreService;
import aromanticcat.umcproject.service.storeService.StoreService;
import aromanticcat.umcproject.web.dto.store.StoreResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
Expand Down
Loading