-
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.
Browse files
Browse the repository at this point in the history
[FEAT] 레큐북 상세 조회 API 구현
- Loading branch information
Showing
12 changed files
with
159 additions
and
22 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
69 changes: 69 additions & 0 deletions
69
src/main/java/org/sopt/lequuServer/domain/book/dto/response/BookDetailResponseDto.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,69 @@ | ||
package org.sopt.lequuServer.domain.book.dto.response; | ||
|
||
import org.sopt.lequuServer.domain.book.model.Book; | ||
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.*; | ||
|
||
public record BookDetailResponseDto( | ||
Long bookId, | ||
String favoriteImage, | ||
String favoriteName, | ||
String title, | ||
String description, | ||
String bookDate, | ||
String bookNickname, | ||
int bookBackgroundColor, | ||
int noteNum, | ||
List<NoteDetailResponseDto> noteList, | ||
List<PostedStickerDetailResponseDto> postedStickerList | ||
) { | ||
public static BookDetailResponseDto of(Book book) { | ||
String bookDate = formatLocalDate(book); | ||
|
||
// 레큐노트 리스트를 noteId 기준 내림차순으로 정렬 | ||
List<Note> sortedNotes = book.getNotes().stream() | ||
.sorted(comparing(Note::getId).reversed()) | ||
.toList(); | ||
|
||
// 레큐노트 리스트 가공 | ||
int renderTypeCounter = 1; | ||
List<NoteDetailResponseDto> noteList = new ArrayList<>(); | ||
for (Note note : sortedNotes) { | ||
String background = note.getBackground(); | ||
|
||
if (background.endsWith(".jpg")) { | ||
noteList.add(NoteDetailResponseDto.of(note, renderTypeCounter, -1, background)); | ||
} else { | ||
noteList.add(NoteDetailResponseDto.of(note, renderTypeCounter, Integer.parseInt(background), "")); | ||
} | ||
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)); | ||
} | ||
|
||
return new BookDetailResponseDto(book.getId(), 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
12 changes: 12 additions & 0 deletions
12
src/main/java/org/sopt/lequuServer/domain/note/dto/response/NoteCreateResponseDto.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,12 @@ | ||
package org.sopt.lequuServer.domain.note.dto.response; | ||
|
||
import org.sopt.lequuServer.domain.note.model.Note; | ||
|
||
public record NoteCreateResponseDto( | ||
Long noteId, | ||
String bookUuid | ||
) { | ||
public static NoteCreateResponseDto of(Note note) { | ||
return new NoteCreateResponseDto(note.getId(), note.getBook().getUuid()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sopt/lequuServer/domain/note/dto/response/NoteDetailResponseDto.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,29 @@ | ||
package org.sopt.lequuServer.domain.note.dto.response; | ||
|
||
import org.sopt.lequuServer.domain.note.model.Note; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public record NoteDetailResponseDto( | ||
Long noteId, | ||
int renderType, | ||
String content, | ||
String noteDate, | ||
String noteNickname, | ||
int noteBackgroundColor, | ||
String noteBackgroundImage | ||
) { | ||
public static NoteDetailResponseDto of(Note note, int renderType, int noteBackgroundColor, String noteBackgroundImage) { | ||
String noteDate = formatLocalDate(note); | ||
|
||
return new NoteDetailResponseDto(note.getId(), renderType, note.getContent(), noteDate, | ||
note.getMember().getNickname(), noteBackgroundColor, noteBackgroundImage); | ||
} | ||
|
||
private static String formatLocalDate(Note note) { | ||
LocalDateTime createdAt = note.getCreatedAt(); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); | ||
return createdAt.format(formatter); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/org/sopt/lequuServer/domain/note/dto/response/NoteResponseDto.java
This file was deleted.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
...java/org/sopt/lequuServer/domain/sticker/dto/response/PostedStickerDetailResponseDto.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,15 @@ | ||
package org.sopt.lequuServer.domain.sticker.dto.response; | ||
|
||
import org.sopt.lequuServer.domain.sticker.model.PostedSticker; | ||
|
||
public record PostedStickerDetailResponseDto( | ||
Long postedStickerId, | ||
String stickerImage, | ||
int positionX, | ||
int positionY | ||
) { | ||
public static PostedStickerDetailResponseDto of(PostedSticker postedSticker) { | ||
return new PostedStickerDetailResponseDto(postedSticker.getId(), postedSticker.getSticker().getStickerImage(), | ||
postedSticker.getPositionX(), postedSticker.getPositionY()); | ||
} | ||
} |
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