From 1a8b1a9e0666390a13a5739f7cb9e29c8ae2e015 Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Mon, 30 Oct 2023 22:41:20 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=EC=9D=B8=EA=B8=B0=EC=9E=88=EB=8A=94?= =?UTF-8?q?=20=EC=B1=85=20=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20like=5Fstatu?= =?UTF-8?q?s=20=EB=82=98=EC=98=A4=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/dto/Response/BookReadingRes.java | 24 +++++++++++++++++++ .../reading/dto/response/ReadingRes.java | 3 ++- .../domain/reading/mapper/ReadingMapper.java | 17 ++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/techeer/checkIt/domain/book/dto/Response/BookReadingRes.java diff --git a/src/main/java/com/techeer/checkIt/domain/book/dto/Response/BookReadingRes.java b/src/main/java/com/techeer/checkIt/domain/book/dto/Response/BookReadingRes.java new file mode 100644 index 0000000..19073ec --- /dev/null +++ b/src/main/java/com/techeer/checkIt/domain/book/dto/Response/BookReadingRes.java @@ -0,0 +1,24 @@ +package com.techeer.checkIt.domain.book.dto.Response; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class BookReadingRes { + private Long id; + private String title; + private String author; + private String publisher; + private String coverImageUrl; + private int height; + private int width; + private int pages; + private int likes; +} diff --git a/src/main/java/com/techeer/checkIt/domain/reading/dto/response/ReadingRes.java b/src/main/java/com/techeer/checkIt/domain/reading/dto/response/ReadingRes.java index a71b7a6..3fba7bd 100644 --- a/src/main/java/com/techeer/checkIt/domain/reading/dto/response/ReadingRes.java +++ b/src/main/java/com/techeer/checkIt/domain/reading/dto/response/ReadingRes.java @@ -1,5 +1,6 @@ package com.techeer.checkIt.domain.reading.dto.response; +import com.techeer.checkIt.domain.book.dto.Response.BookReadingRes; import com.techeer.checkIt.domain.book.dto.Response.BookRes; import com.techeer.checkIt.domain.reading.entity.ReadingStatus; import lombok.AccessLevel; @@ -13,6 +14,6 @@ @Builder @AllArgsConstructor(access = AccessLevel.PRIVATE) public class ReadingRes { - private List bookInfos; + private List bookInfos; private ReadingStatus status; } diff --git a/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java b/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java index 40cca87..7697671 100644 --- a/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java +++ b/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java @@ -1,8 +1,7 @@ package com.techeer.checkIt.domain.reading.mapper; +import com.techeer.checkIt.domain.book.dto.Response.BookReadingRes; import com.techeer.checkIt.domain.book.entity.Book; -import com.techeer.checkIt.domain.book.dto.Response.BookRes; - 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; @@ -26,8 +25,8 @@ public Reading toEntity(User user, Book book, int lastPage, ReadingStatus status .status(status) .build(); } - public BookRes toDto(Reading reading) { - return BookRes.builder() + public BookReadingRes toDto(Reading reading) { + return BookReadingRes.builder() .id(reading.getBook().getId()) .title(reading.getBook().getTitle()) .author(reading.getBook().getAuthor()) @@ -36,12 +35,13 @@ public BookRes toDto(Reading reading) { .height(reading.getBook().getHeight()) .width(reading.getBook().getWidth()) .pages(reading.getBook().getPages()) + .likes(reading.getBook().getLikeCount()) .build(); } // TODO: int likes, boolean likeStatus 을 안 받기 때문에 값 안 가져옴 - public BookRes toDtoByBook(Book book) { - return BookRes.builder() + public BookReadingRes toDtoByBook(Book book) { + return BookReadingRes.builder() .id(book.getId()) .title(book.getTitle()) .author(book.getAuthor()) @@ -50,11 +50,12 @@ public BookRes toDtoByBook(Book book) { .height(book.getHeight()) .width(book.getWidth()) .pages(book.getPages()) + .likes(book.getLikeCount()) .build(); } public ReadingRes toReadingList(List readings, ReadingStatus status) { - List bookInfos = readings.stream().map(this::toDto).collect(Collectors.toList()); + List bookInfos = readings.stream().map(this::toDto).collect(Collectors.toList()); return ReadingRes.builder() .bookInfos(bookInfos) @@ -63,7 +64,7 @@ public ReadingRes toReadingList(List readings, ReadingStatus status) { } public ReadingRes toReadingListByBook(List books, ReadingStatus status) { - List bookInfos = books.stream().map(this::toDtoByBook).collect(Collectors.toList()); + List bookInfos = books.stream().map(this::toDtoByBook).collect(Collectors.toList()); return ReadingRes.builder() .bookInfos(bookInfos) From e470bbc27354e4047d57f54b57b77860e1a06ada Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Mon, 30 Oct 2023 22:47:07 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EC=9A=94=EC=B2=AD=EC=8B=9C=20Result?= =?UTF-8?q?Code=EA=B0=80=20=EB=8B=A4=EB=A5=B4=EA=B2=8C=20=EB=82=98?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/book/controller/BookController.java | 3 ++- .../domain/review/controller/ReviewController.java | 14 +++++++++----- .../techeer/checkIt/global/result/ResultCode.java | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/techeer/checkIt/domain/book/controller/BookController.java b/src/main/java/com/techeer/checkIt/domain/book/controller/BookController.java index 257e41e..dfd5a9d 100644 --- a/src/main/java/com/techeer/checkIt/domain/book/controller/BookController.java +++ b/src/main/java/com/techeer/checkIt/domain/book/controller/BookController.java @@ -19,6 +19,7 @@ import java.util.List; +import static com.techeer.checkIt.global.result.ResultCode.GET_LIKE_BOOK_SUCCESS; import static com.techeer.checkIt.global.result.ResultCode.GET_NEW_BOOK_SUCCESS; import static com.techeer.checkIt.global.result.ResultCode.UPDATE_BOOK_LIKE_SUCCESS; import static com.techeer.checkIt.global.result.ResultCode.GET_ONE_BOOK_SUCCESS; @@ -72,6 +73,6 @@ public ResponseEntity updateLikeById( @GetMapping("/like") public ResponseEntity getLikeBooksList() { Page books = bookService.sortedBooksByLike(); - return ResponseEntity.ok(ResultResponse.of(GET_NEW_BOOK_SUCCESS, books)); + return ResponseEntity.ok(ResultResponse.of(GET_LIKE_BOOK_SUCCESS, books)); } } diff --git a/src/main/java/com/techeer/checkIt/domain/review/controller/ReviewController.java b/src/main/java/com/techeer/checkIt/domain/review/controller/ReviewController.java index b7b0989..a6e7911 100644 --- a/src/main/java/com/techeer/checkIt/domain/review/controller/ReviewController.java +++ b/src/main/java/com/techeer/checkIt/domain/review/controller/ReviewController.java @@ -8,7 +8,6 @@ import com.techeer.checkIt.domain.user.entity.User; import com.techeer.checkIt.domain.user.entity.UserDetail; import com.techeer.checkIt.domain.user.service.UserService; -import com.techeer.checkIt.global.result.ResultCode; import com.techeer.checkIt.global.result.ResultResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -26,6 +25,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import static com.techeer.checkIt.global.result.ResultCode.GET_REVIEW_SUCCESS; +import static com.techeer.checkIt.global.result.ResultCode.REVIEW_CREATE_SUCCESS; +import static com.techeer.checkIt.global.result.ResultCode.REVIEW_DELETE_SUCCESS; +import static com.techeer.checkIt.global.result.ResultCode.REVIEW_UPDATE_SUCCESS; + @Api(tags = "리뷰 API") @RestController @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -45,7 +49,7 @@ public ResponseEntity createReview( Book book = bookService.findById(createReviewReq.getBookId()); reviewService.createReview(user, book, createReviewReq); ReviewRes reviewRes = reviewService.findReviewByUserNameIdBookId(user, createReviewReq.getBookId()); - return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_CREATE_SUCCESS, reviewRes)); + return ResponseEntity.ok(ResultResponse.of(REVIEW_CREATE_SUCCESS, reviewRes)); } @ApiOperation(value = "리뷰 조회 API") @@ -56,7 +60,7 @@ public ResponseEntity getReviewByUserNameBookId( ){ User user = userService.findUserByUsername(userDetail.getUsername()); ReviewRes reviewRes = reviewService.findReviewByUserNameIdBookId(user, bookId); - return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_CREATE_SUCCESS, reviewRes)); + return ResponseEntity.ok(ResultResponse.of(GET_REVIEW_SUCCESS, reviewRes)); } @ApiOperation(value = "리뷰 삭제 API") @@ -67,7 +71,7 @@ public ResponseEntity deleteReviewByUserNameBookId( ){ User user = userService.findUserByUsername(userDetail.getUsername()); reviewService.deleteReview(user, bookId); - return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_DELETE_SUCCESS)); + return ResponseEntity.ok(ResultResponse.of(REVIEW_DELETE_SUCCESS)); } @ApiOperation(value = "리뷰 내용 변경 API") @@ -79,7 +83,7 @@ public ResponseEntity updateReview( User user = userService.findUserByUsername(userDetail.getUsername()); reviewService.updateReview(user, createReviewReq); ReviewRes reviewRes = reviewService.findReviewByUserNameIdBookId(user, createReviewReq.getBookId()); - return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_DELETE_SUCCESS, reviewRes)); + return ResponseEntity.ok(ResultResponse.of(REVIEW_UPDATE_SUCCESS, reviewRes)); } } diff --git a/src/main/java/com/techeer/checkIt/global/result/ResultCode.java b/src/main/java/com/techeer/checkIt/global/result/ResultCode.java index 432f5a6..99b4b0c 100644 --- a/src/main/java/com/techeer/checkIt/global/result/ResultCode.java +++ b/src/main/java/com/techeer/checkIt/global/result/ResultCode.java @@ -23,6 +23,7 @@ public enum ResultCode { GET_NEW_BOOK_SUCCESS("B001","신규 도서 조회 성공"), UPDATE_BOOK_LIKE_SUCCESS("B002","좋아요 갱신 성공"), GET_ONE_BOOK_SUCCESS("B003","책 조회 성공"), + GET_LIKE_BOOK_SUCCESS("B004","인기있는 도서 조회 성공"), // Reading From 4df9d73bb4b366a4c4aedc9119355dfb93e5d68b Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Mon, 30 Oct 2023 22:50:07 +0900 Subject: [PATCH 3/4] =?UTF-8?q?style:=20=ED=95=A8=EC=88=98=EB=AA=85?= =?UTF-8?q?=EC=9D=84=20=ED=8C=8C=EC=95=85=ED=95=98=EA=B8=B0=20=EC=89=AC?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/techeer/checkIt/domain/book/mapper/BookMapper.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java b/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java index fd776a1..460616e 100644 --- a/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java +++ b/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java @@ -54,14 +54,12 @@ public List toSearchDtoList(List books){ .map(this::toBookSearchDto) .collect(Collectors.toList()); } - // toPageDtoList = toBookSearchResDtoPage - public Page toPageDtoList(Page books) { + public Page toBookSearchResDtoPage(Page books) { return new PageImpl<>(books.stream() .map(this::toBookSearchDto) .collect(Collectors.toList())); } - // toPageDtoList2 = BookSearchLikeResDtoPage - public Page toPageDtoList2(Page books) { + public Page BookSearchLikeResDtoPage(Page books) { return new PageImpl<>(books.stream() .map(this::toBookSearchLikeDto) .collect(Collectors.toList())); From 8120a63dedb7c3fddaef5ef9717cb55102ceb4f7 Mon Sep 17 00:00:00 2001 From: fnzl54 Date: Mon, 30 Oct 2023 23:11:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?style:=20=ED=95=A8=EC=88=98=EC=9D=98=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/book/mapper/BookMapper.java | 14 +++++++++++ .../domain/book/service/BookService.java | 4 ++-- .../domain/reading/mapper/ReadingMapper.java | 23 ++++++------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java b/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java index 460616e..173da27 100644 --- a/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java +++ b/src/main/java/com/techeer/checkIt/domain/book/mapper/BookMapper.java @@ -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; @@ -64,4 +65,17 @@ public Page BookSearchLikeResDtoPage(Page 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(); + } } diff --git a/src/main/java/com/techeer/checkIt/domain/book/service/BookService.java b/src/main/java/com/techeer/checkIt/domain/book/service/BookService.java index b4ae563..6c20259 100644 --- a/src/main/java/com/techeer/checkIt/domain/book/service/BookService.java +++ b/src/main/java/com/techeer/checkIt/domain/book/service/BookService.java @@ -38,13 +38,13 @@ public List findBookByTitle(String title) { public Page sortedBooksByTime() { PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Order.desc("createdAt"))); Page newBooks = bookSearchRepository.findAll(pageRequest); - return bookMapper.toPageDtoList(newBooks); + return bookMapper.toBookSearchResDtoPage(newBooks); } public Page sortedBooksByLike() { PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Order.desc("likeCount"))); Page newBooks = bookJpaRepository.findAll(pageRequest); - return bookMapper.toPageDtoList2(newBooks); + return bookMapper.BookSearchLikeResDtoPage(newBooks); } // id별 조회할 때 diff --git a/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java b/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java index 7697671..c98418f 100644 --- a/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java +++ b/src/main/java/com/techeer/checkIt/domain/reading/mapper/ReadingMapper.java @@ -2,6 +2,7 @@ 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; @@ -9,14 +10,19 @@ 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) @@ -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 readings, ReadingStatus status) { List bookInfos = readings.stream().map(this::toDto).collect(Collectors.toList()); @@ -64,7 +55,7 @@ public ReadingRes toReadingList(List readings, ReadingStatus status) { } public ReadingRes toReadingListByBook(List books, ReadingStatus status) { - List bookInfos = books.stream().map(this::toDtoByBook).collect(Collectors.toList()); + List bookInfos = books.stream().map(bookMapper::toDtoByBook).collect(Collectors.toList()); return ReadingRes.builder() .bookInfos(bookInfos)