-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✏️ [FIX] 레큐북 즐겨찾기 여부까지 넘겨주는 API 추가 #76
- Loading branch information
Showing
4 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ain/java/org/sopt/lequuServer/domain/book/dto/response/BookDetailFavoriteResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.sopt.lequuServer.domain.book.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.sopt.lequuServer.domain.book.model.Book; | ||
import org.sopt.lequuServer.domain.member.model.Member; | ||
import org.sopt.lequuServer.domain.note.dto.response.NoteDetailResponseDto; | ||
import org.sopt.lequuServer.domain.note.model.Note; | ||
import org.sopt.lequuServer.domain.sticker.dto.response.PostedStickerDetailResponseDto; | ||
import org.sopt.lequuServer.domain.sticker.model.PostedSticker; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.util.Comparator.comparing; | ||
|
||
public record BookDetailFavoriteResponseDto( | ||
|
||
@Schema(description = "레큐북 고유 id", example = "1") | ||
Long bookId, | ||
|
||
@Schema(description = "레큐북 즐겨찾기 등록 여부", example = "true") | ||
Boolean isFavorite, | ||
|
||
@Schema(description = "최애 사진", example = "https://dzfv99wxq6tx0.cloudfront.net/books/favorite_image/b4006561-382b-479e-ae1d-e841922e883f.jpg") | ||
String favoriteImage, | ||
|
||
@Schema(description = "최애 이름", example = "LeoJ") | ||
String favoriteName, | ||
|
||
@Schema(description = "레큐북 제목", example = "1번째 레큐북") | ||
String title, | ||
|
||
@Schema(description = "레큐북 소개", example = "레큐북의 내용입니다.") | ||
String description, | ||
|
||
@Schema(description = "레큐북 생성 일시", example = "2024.01.11") | ||
String bookDate, | ||
|
||
@Schema(description = "레큐북 작성자 닉네임", example = "예딘") | ||
String bookNickname, | ||
|
||
@Schema(description = "레큐북 배경색", example = "#F5F5F5") | ||
String bookBackgroundColor, | ||
|
||
@Schema(description = "레큐 노트 개수", example = "100") | ||
int noteNum, | ||
|
||
List<NoteDetailResponseDto> noteList, | ||
|
||
List<PostedStickerDetailResponseDto> postedStickerList | ||
) { | ||
public static BookDetailFavoriteResponseDto of(Member member, Book book) { | ||
String bookDate = formatLocalDate(book); | ||
|
||
List<Note> sortedNotes = book.getNotes().stream() | ||
.sorted(comparing(Note::getCreatedAt).reversed()) | ||
.toList(); | ||
|
||
// 레큐노트 리스트 가공 | ||
int renderTypeCounter = 1; | ||
List<NoteDetailResponseDto> noteList = new ArrayList<>(); | ||
for (Note note : sortedNotes) { | ||
noteList.add(NoteDetailResponseDto.of(note, renderTypeCounter)); | ||
renderTypeCounter = (renderTypeCounter % 6 == 0) ? 1 : renderTypeCounter + 1; | ||
} | ||
|
||
// 부착된 스티커 리스트 가공 | ||
List<PostedSticker> postedStickers = book.getPostedStickers(); | ||
List<PostedStickerDetailResponseDto> postedStickerList = new ArrayList<>(); | ||
for (PostedSticker postedSticker : postedStickers) { | ||
postedStickerList.add(PostedStickerDetailResponseDto.of(postedSticker)); | ||
} | ||
|
||
Boolean isFavorite = member.getFavorites().stream() | ||
.anyMatch(favorite -> favorite.getBook().equals(book)); | ||
|
||
return new BookDetailFavoriteResponseDto(book.getId(), isFavorite, | ||
book.getFavoriteImage(), book.getFavoriteName(), | ||
book.getTitle(), book.getDescription(), bookDate, book.getMember().getNickname(), | ||
book.getBackgroundColor(), book.getNotes().size(), noteList, postedStickerList | ||
); | ||
} | ||
|
||
private static String formatLocalDate(Book book) { | ||
LocalDateTime createdAt = book.getCreatedAt(); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); | ||
return createdAt.format(formatter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters