-
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
Refactor Word Dict Response Value
- Loading branch information
Showing
7 changed files
with
111 additions
and
12 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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/dnd/spaced/domain/word/application/dto/response/ListWordInfoDto.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,32 @@ | ||
package com.dnd.spaced.domain.word.application.dto.response; | ||
|
||
import com.dnd.spaced.domain.word.domain.Word; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ListWordInfoDto( | ||
Long id, | ||
String name, | ||
String meaning, | ||
String category, | ||
int commentCount, | ||
int viewCount, | ||
String example, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt | ||
) { | ||
|
||
public static ListWordInfoDto from(Word word) { | ||
return new ListWordInfoDto( | ||
word.getId(), | ||
word.getName(), | ||
word.getMeaning(), | ||
word.getCategory().getName(), | ||
word.getCommentCount(), | ||
word.getViewCount(), | ||
word.getExample(), | ||
word.getCreatedAt(), | ||
word.getUpdatedAt() | ||
); | ||
} | ||
} |
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/dnd/spaced/domain/word/presentation/dto/response/ListWordInfoResponse.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,61 @@ | ||
package com.dnd.spaced.domain.word.presentation.dto.response; | ||
|
||
import com.dnd.spaced.domain.word.application.dto.response.ListWordInfoDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public record ListWordInfoResponse( | ||
|
||
@Schema(description = "용어 정보") | ||
List<WordInfoResponse> words, | ||
|
||
@Schema(description = "마지막으로 조회한 용어 이름", nullable = true) | ||
String lastWordName | ||
) { | ||
|
||
public static ListWordInfoResponse from(List<ListWordInfoDto> dtos) { | ||
if (dtos == null || dtos.isEmpty()) { | ||
return new ListWordInfoResponse(Collections.emptyList(), null); | ||
} | ||
|
||
List<WordInfoResponse> words = dtos.stream() | ||
.map(WordInfoResponse::from) | ||
.toList(); | ||
|
||
return new ListWordInfoResponse(words, words.get(words.size() - 1).name()); | ||
} | ||
|
||
private record WordInfoResponse( | ||
@Schema(description = "용어 ID") | ||
Long id, | ||
|
||
@Schema(description = "용어 이름") | ||
String name, | ||
|
||
@Schema(description = "용어 뜻") | ||
String meaning, | ||
|
||
@Schema(description = "용어 카테고리", allowableValues = {"개발", "비즈니스", "디자인"}) | ||
String category, | ||
|
||
@Schema(description = "댓글 개수") | ||
int commentCount, | ||
|
||
@Schema(description = "조회수") | ||
int viewCount | ||
) { | ||
|
||
public static WordInfoResponse from(ListWordInfoDto dto) { | ||
return new WordInfoResponse( | ||
dto.id(), | ||
dto.name(), | ||
dto.meaning(), | ||
dto.category(), | ||
dto.commentCount(), | ||
dto.viewCount() | ||
); | ||
} | ||
} | ||
} |