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

✨ 페이지 정보 추가, 상점 아이템 업로드 API 추가, 코인 조회 추가 #172

Merged
merged 12 commits into from
Feb 19, 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
22 changes: 10 additions & 12 deletions src/main/java/aromanticcat/umcproject/entity/LetterPaper.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package aromanticcat.umcproject.entity;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
@Table(name = "letter_paper")
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class LetterPaper extends BaseEntity {

@Id
Expand All @@ -32,11 +30,11 @@ public class LetterPaper extends BaseEntity {
@OneToMany(mappedBy = "letterPaper")
private List<Letter> letters;

@Builder
public LetterPaper(String imageUrl, String name, Integer price) {
this.imageUrl = imageUrl;
this.name = name;
this.price = price;
}
// @Builder
// public LetterPaper(String imageUrl, String name, Integer price) {
// this.imageUrl = imageUrl;
// this.name = name;
// this.price = price;
// }

}
10 changes: 4 additions & 6 deletions src/main/java/aromanticcat/umcproject/entity/Stamp.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package aromanticcat.umcproject.entity;

import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "stamp")
public class Stamp extends BaseEntity {

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

import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;

import java.util.List;
import org.springframework.data.domain.Page;

public interface MyCollectionService {

List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(String memberEmail, int page, int pageSize, boolean onlyMyDesign);
List<MyCollectionResponseDTO.AcquiredStampResultDTO> findStampList(String memberEmail, int page, int pageSize, boolean onlyMyDesign);
Page<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPaperList(String memberEmail, int page, int pageSize, boolean onlyMyDesign);
Page<MyCollectionResponseDTO.AcquiredStampResultDTO> findStampList(String memberEmail, int page, int pageSize, boolean onlyMyDesign);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import aromanticcat.umcproject.web.dto.MyCollectionResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand All @@ -30,18 +31,19 @@ public class MyCollectionServiceImpl implements MyCollectionService {

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

if(onlyMyDesign) {
Page<MyLetterPaper> myLetterPaperPage = myLetterPaperRepository.findByMemberEmail(email, pageable);
List<MyLetterPaper> myLetterPaperList = myLetterPaperPage.getContent();

responseDTOs = myLetterPaperList.stream()
List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> myLetterPaperDTOs = myLetterPaperPage.getContent().stream()
.map(myLetterPaper -> MyCollectionConverter.toMyLetterPaperResultDTO(myLetterPaper))
.collect(Collectors.toList());
}else {

return new PageImpl<>(myLetterPaperDTOs, pageable, myLetterPaperPage.getTotalElements());
} else {
// 사용자가 구매한 편지지 목록 조회
Page<AcquiredItem> acquiredLetterPaperPage = acquiredItemRepository.findByMemberEmailAndLetterPaperIdIsNotNull(email, pageable);
List<AcquiredItem> acquiredLetterPaperList = acquiredLetterPaperPage.getContent();
Expand All @@ -62,26 +64,30 @@ public List<MyCollectionResponseDTO.AcquiredLetterPaperResultDTO> findLetterPape
responseDTOs = new ArrayList<>();
responseDTOs.addAll(myLetterPaperDTOs);
responseDTOs.addAll(acquiredLetterPaperDTOs);
return new PageImpl<>(responseDTOs, pageable, myLetterPaperPage.getTotalElements() + acquiredLetterPaperPage.getTotalElements());

}
return responseDTOs;



}

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

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

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

responseDTOs = myStampList.stream()
List<MyCollectionResponseDTO.AcquiredStampResultDTO> myStampDTOs = myStampPage.getContent().stream()
.map(myStamp -> MyCollectionConverter.toMyStampResultDTO(myStamp))
.collect(Collectors.toList());
}else{

return new PageImpl<>(myStampDTOs, pageable, myStampPage.getTotalElements());

}else{
// 사용자가 구매한 우표 목록 조회
Page<AcquiredItem> acquiredStampPage = acquiredItemRepository.findByMemberEmailAndStampIdIsNotNull(email, pageable);
List<AcquiredItem> acquiredStampList = acquiredStampPage.getContent();
Expand All @@ -102,9 +108,10 @@ public List<MyCollectionResponseDTO.AcquiredStampResultDTO> findStampList(String
responseDTOs = new ArrayList<>();
responseDTOs.addAll(myStampDTOs);
responseDTOs.addAll(acquiredStampDTOs);
}

return responseDTOs;
return new PageImpl<>(responseDTOs, pageable, myStampPage.getTotalElements() + acquiredStampPage.getTotalElements());

}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package aromanticcat.umcproject.service.nangmanLetterboxService;

import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanCollectionResponseDTO;

import java.util.List;
import org.springframework.data.domain.Page;

public interface NangmanCollectionService {

List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> findCollection(int page, int pageSize, String sort);
Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> findCollection(int page, int pageSize, String sort);

NangmanCollectionResponseDTO.LetterAndReplyResultDTO findCollectionDetails(Long nangmanLetterId);

void likeCollection(Long nangmanLetterId,String emojiType);

List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyLetterList(String email, int page, int pageSize);
Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyLetterPage(String email, int page, int pageSize);

List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyReplyList(String email, int page, int pageSize);
Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyReplyPage(String email, int page, int pageSize);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanCollectionResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand All @@ -26,25 +27,21 @@ public class NangmanCollectionServiceImpl implements NangmanCollectionService{

@Override
@Transactional
public List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> findCollection(int page, int pageSize, String sort){
public Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> findCollection(int page, int pageSize, String sort){
Pageable pageable = PageRequest.of(page, pageSize);
Page<NangmanLetter> letterPage;

if(sort.equals("popular")){
Page<NangmanLetter> letterPage = nangmanLetterRepository.findPopularLetters(pageable);

List<NangmanLetter> letterList = letterPage.getContent();
return letterList.stream()
.map(letter -> NangmanCollectionConverter.toPreviewBothResultDTO(letter))
.collect(Collectors.toList());
if (sort.equals("popular")) {
letterPage = nangmanLetterRepository.findPopularLetters(pageable);
} else {
letterPage = nangmanLetterRepository.findLatestLetters(pageable);
}

} else{
Page<NangmanLetter> letterPage = nangmanLetterRepository.findLatestLetters(pageable);
List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> resultDTOList = letterPage.getContent().stream()
.map(letter -> NangmanCollectionConverter.toPreviewBothResultDTO(letter))
.collect(Collectors.toList());

List<NangmanLetter> letterList = letterPage.getContent();
return letterList.stream()
.map(letter -> NangmanCollectionConverter.toPreviewBothResultDTO(letter))
.collect(Collectors.toList());
}
return new PageImpl<>(resultDTOList, pageable, letterPage.getTotalElements());
}

@Override
Expand Down Expand Up @@ -97,31 +94,25 @@ private boolean isValidEmojiType(String emojiType) {
// 사용자 ID로 해당 사용자가 작성한 편지 목록 조회
@Override
@Transactional
public List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyLetterList(String email, int page, int pageSize){
public Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyLetterPage(String email, int page, int pageSize){

Pageable pageable = PageRequest.of(page, pageSize);

Page<NangmanLetter> myLetterPage = nangmanLetterRepository.findByMemberEmail(email, pageable);
List<NangmanLetter> myLetterList = myLetterPage.getContent();

return myLetterList.stream()
.map(letter -> NangmanCollectionConverter.toPreviewBothResultDTO(letter))
.collect(Collectors.toList());
return myLetterPage.map(letter -> NangmanCollectionConverter.toPreviewBothResultDTO(letter));

}

@Override
@Transactional
public List<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyReplyList(String email, int page, int pageSize){
public Page<NangmanCollectionResponseDTO.PreviewLetterAndReplyResultDTO> getMyReplyPage(String email, int page, int pageSize){

Pageable pageable = PageRequest.of(page, pageSize);

Page<NangmanReply> myReplyPage = nangmanReplyRepository.findByMemberEmail(email, pageable);
List<NangmanReply> myReplyList = myReplyPage.getContent();

// 각 답장(+ 연결된 편지)에 대해 미리보기로 생성
return myReplyList.stream()
.map(reply -> NangmanCollectionConverter.toPreviewBothResultDTO(reply.getNangmanLetter()))
.collect(Collectors.toList());
return myReplyPage.map(reply -> NangmanCollectionConverter.toPreviewBothResultDTO(reply.getNangmanLetter()));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package aromanticcat.umcproject.service.nangmanLetterboxService;

import aromanticcat.umcproject.entity.NangmanLetter;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterboxRequestDTO;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterBoxResponseDTO;

import java.util.List;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterboxRequestDTO;
import org.springframework.data.domain.Page;

public interface NangmanLetterboxService {

NangmanLetter sendLetter(String email, NangmanLetterboxRequestDTO.SendLetterDTO requestDTO);

List<NangmanLetter> getLetterList(String email, int page, int pageSize);
Page<NangmanLetter> getLetterPage(String email, int page, int pageSize);

NangmanLetter getLetter(Long nangmanLetterid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import aromanticcat.umcproject.repository.MemberRepository;
import aromanticcat.umcproject.repository.NangmanLetterRepository;
import aromanticcat.umcproject.repository.NangmanReplyRepository;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterboxRequestDTO;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterBoxResponseDTO;
import aromanticcat.umcproject.web.dto.nangmanLetterbox.NangmanLetterboxRequestDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -17,7 +17,6 @@

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -53,14 +52,14 @@ public NangmanLetter sendLetter(String email, NangmanLetterboxRequestDTO.SendLet

@Override
@Transactional
public List<NangmanLetter> getLetterList(String email, int page, int pageSize){
public Page<NangmanLetter> getLetterPage(String email, int page, int pageSize){
// 페이지 번호와 페이지 크기를 이용하여 페이징된 편지 목록 조회
Pageable pageable = PageRequest.of(page, pageSize);

// 사용자가 쓴 고민편지 제외하고 목록 반환
Page<NangmanLetter> letterPage = nangmanLetterRepository.findByHasResponseFalseAndMemberEmailNot(email, pageable);

return letterPage.getContent();
return letterPage;
}


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

import aromanticcat.umcproject.web.dto.store.StoreResponseDTO;
import org.springframework.data.domain.Page;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.io.IOException;

public interface StoreService {

List<StoreResponseDTO.LetterPaperResultDTO> findLetterPaperList(String email, int page, int pageSize, String sort);
Page<StoreResponseDTO.LetterPaperResultDTO> findLetterPaperList(String email, int page, int pageSize, String sort);

List<StoreResponseDTO.StampResultDTO> findStampList(String email, int page, int pageSize, String sort);
Page<StoreResponseDTO.StampResultDTO> findStampList(String email, int page, int pageSize, String sort);

void purchasedLetterPaper(String email, Long letterPaperId);

void purchasedStamp(String email, Long stampId);

Long uploadLetterPaper(MultipartFile file, String name, int price) throws IOException;
Long uploadStamp(MultipartFile file, String name, int price) throws IOException;

int findUserCoin(String email);


}
Loading
Loading