Skip to content

Commit

Permalink
style: 함수의 파일 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzl54 committed Oct 30, 2023
1 parent 4df9d73 commit 8120a63
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.techeer.checkIt.domain.book.mapper;

import com.techeer.checkIt.domain.book.dto.Response.BookReadingRes;
import com.techeer.checkIt.domain.book.dto.Response.BookRes;
import com.techeer.checkIt.domain.book.dto.Response.BookSearchLikeRes;
import com.techeer.checkIt.domain.book.dto.Response.BookSearchRes;
Expand Down Expand Up @@ -64,4 +65,17 @@ public Page<BookSearchLikeRes> BookSearchLikeResDtoPage(Page<Book> books) {
.map(this::toBookSearchLikeDto)
.collect(Collectors.toList()));
}
public BookReadingRes toDtoByBook(Book book) {
return BookReadingRes.builder()
.id(book.getId())
.title(book.getTitle())
.author(book.getAuthor())
.publisher(book.getPublisher())
.coverImageUrl(book.getCoverImageUrl())
.height(book.getHeight())
.width(book.getWidth())
.pages(book.getPages())
.likes(book.getLikeCount())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public List<BookSearchRes> findBookByTitle(String title) {
public Page<BookSearchRes> sortedBooksByTime() {
PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Order.desc("createdAt")));
Page<BookDocument> newBooks = bookSearchRepository.findAll(pageRequest);
return bookMapper.toPageDtoList(newBooks);
return bookMapper.toBookSearchResDtoPage(newBooks);
}

public Page<BookSearchLikeRes> sortedBooksByLike() {
PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Order.desc("likeCount")));
Page<Book> newBooks = bookJpaRepository.findAll(pageRequest);
return bookMapper.toPageDtoList2(newBooks);
return bookMapper.BookSearchLikeResDtoPage(newBooks);
}

// id별 조회할 때
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

import com.techeer.checkIt.domain.book.dto.Response.BookReadingRes;
import com.techeer.checkIt.domain.book.entity.Book;
import com.techeer.checkIt.domain.book.mapper.BookMapper;
import com.techeer.checkIt.domain.reading.dto.response.ReadingRes;
import com.techeer.checkIt.domain.reading.dto.response.UpdateLastPageAndPercentageRes;
import com.techeer.checkIt.domain.reading.dto.response.UpdateReadingAndReadingVolumeRes;
import com.techeer.checkIt.domain.reading.entity.Reading;
import com.techeer.checkIt.domain.reading.entity.ReadingStatus;
import com.techeer.checkIt.domain.readingVolume.entity.ReadingVolume;
import com.techeer.checkIt.domain.user.entity.User;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class ReadingMapper {

private final BookMapper bookMapper;

public Reading toEntity(User user, Book book, int lastPage, ReadingStatus status) {
return Reading.builder()
.user(user)
Expand All @@ -39,21 +45,6 @@ public BookReadingRes toDto(Reading reading) {
.build();
}

// TODO: int likes, boolean likeStatus 을 안 받기 때문에 값 안 가져옴
public BookReadingRes toDtoByBook(Book book) {
return BookReadingRes.builder()
.id(book.getId())
.title(book.getTitle())
.author(book.getAuthor())
.publisher(book.getPublisher())
.coverImageUrl(book.getCoverImageUrl())
.height(book.getHeight())
.width(book.getWidth())
.pages(book.getPages())
.likes(book.getLikeCount())
.build();
}

public ReadingRes toReadingList(List<Reading> readings, ReadingStatus status) {
List<BookReadingRes> bookInfos = readings.stream().map(this::toDto).collect(Collectors.toList());

Expand All @@ -64,7 +55,7 @@ public ReadingRes toReadingList(List<Reading> readings, ReadingStatus status) {
}

public ReadingRes toReadingListByBook(List<Book> books, ReadingStatus status) {
List<BookReadingRes> bookInfos = books.stream().map(this::toDtoByBook).collect(Collectors.toList());
List<BookReadingRes> bookInfos = books.stream().map(bookMapper::toDtoByBook).collect(Collectors.toList());

return ReadingRes.builder()
.bookInfos(bookInfos)
Expand Down

0 comments on commit 8120a63

Please sign in to comment.