From 603be995597a3d6eff8a247d00bf592d5144289d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Thu, 5 Sep 2024 12:38:39 +0900 Subject: [PATCH] refactor :: change examples type to list --- .../admin/application/AdminServiceMapper.java | 6 ++--- .../dto/request/AdminWordRequestDto.java | 4 +++- .../dto/response/AdminWordResponse.java | 4 +++- .../dto/response/BookmarkWordInfoDto.java | 5 ++-- .../QuerydslBookmarkRepository.java | 2 +- .../dto/response/BookmarkWordDto.java | 3 ++- .../dto/response/BookmarkWordResponse.java | 2 +- .../dto/response/DetailWordInfoDto.java | 5 ++-- .../dto/response/ListWordInfoDto.java | 2 +- .../dto/response/MultipleWordInfoDto.java | 2 +- .../dnd/spaced/domain/word/domain/Word.java | 23 ++++++++----------- .../repository/QuerydslWordRepository.java | 2 +- .../dto/response/WordInfoWithBookmarkDto.java | 3 ++- .../dto/response/DetailWordInfoResponse.java | 6 +++-- 14 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/dnd/spaced/domain/admin/application/AdminServiceMapper.java b/src/main/java/com/dnd/spaced/domain/admin/application/AdminServiceMapper.java index 8dc5b89..57ec302 100644 --- a/src/main/java/com/dnd/spaced/domain/admin/application/AdminServiceMapper.java +++ b/src/main/java/com/dnd/spaced/domain/admin/application/AdminServiceMapper.java @@ -18,7 +18,7 @@ public static Word fromCreateRequest(AdminWordRequestDto dto) { .englishPronunciation(dto.pronunciation().getEnglish()) .meaning(dto.meaning()) .categoryName(Category.findBy(dto.category()).getName()) - .example(dto.example()) + .examples(dto.examples()) .build(); } @@ -28,7 +28,7 @@ public static Word fromUpdateRequest(AdminWordRequestDto dto, Word existingWord) dto.pronunciation().getEnglish(), dto.meaning(), Category.findBy(dto.category()).getName(), - dto.example() + dto.examples() ); return existingWord; } @@ -44,7 +44,7 @@ public static AdminWordResponse toResponseDto(Word word) { word.getPronunciation(), word.getMeaning(), word.getCategory().name(), - word.getExample() + word.getExamples() ); } } diff --git a/src/main/java/com/dnd/spaced/domain/admin/application/dto/request/AdminWordRequestDto.java b/src/main/java/com/dnd/spaced/domain/admin/application/dto/request/AdminWordRequestDto.java index 886f74d..b0364d0 100644 --- a/src/main/java/com/dnd/spaced/domain/admin/application/dto/request/AdminWordRequestDto.java +++ b/src/main/java/com/dnd/spaced/domain/admin/application/dto/request/AdminWordRequestDto.java @@ -2,10 +2,12 @@ import com.dnd.spaced.domain.word.domain.Pronunciation; +import java.util.List; + public record AdminWordRequestDto( String name, String meaning, Pronunciation pronunciation, String category, - String example + List examples ) {} diff --git a/src/main/java/com/dnd/spaced/domain/admin/presentation/dto/response/AdminWordResponse.java b/src/main/java/com/dnd/spaced/domain/admin/presentation/dto/response/AdminWordResponse.java index b8c14c3..e4fdaa8 100644 --- a/src/main/java/com/dnd/spaced/domain/admin/presentation/dto/response/AdminWordResponse.java +++ b/src/main/java/com/dnd/spaced/domain/admin/presentation/dto/response/AdminWordResponse.java @@ -3,6 +3,8 @@ import com.dnd.spaced.domain.word.domain.Pronunciation; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + public record AdminWordResponse( @Schema(description = "용어 ID") @@ -21,5 +23,5 @@ public record AdminWordResponse( String category, @Schema(description = "예문") - String example + List examples ) {} diff --git a/src/main/java/com/dnd/spaced/domain/bookmark/application/dto/response/BookmarkWordInfoDto.java b/src/main/java/com/dnd/spaced/domain/bookmark/application/dto/response/BookmarkWordInfoDto.java index 5c42725..b839b74 100644 --- a/src/main/java/com/dnd/spaced/domain/bookmark/application/dto/response/BookmarkWordInfoDto.java +++ b/src/main/java/com/dnd/spaced/domain/bookmark/application/dto/response/BookmarkWordInfoDto.java @@ -2,6 +2,7 @@ import com.dnd.spaced.domain.bookmark.domain.repository.dto.response.BookmarkWordDto; import java.time.LocalDateTime; +import java.util.List; public record BookmarkWordInfoDto( Long wordId, @@ -10,7 +11,7 @@ public record BookmarkWordInfoDto( String meaning, String category, int viewCount, - String example, + List examples, LocalDateTime createdAt, LocalDateTime updatedAt, Long bookmarkId @@ -24,7 +25,7 @@ public static BookmarkWordInfoDto from(BookmarkWordDto dto) { dto.meaning(), dto.category().getName(), dto.viewCount(), - dto.example(), + dto.examples(), dto.createdAt(), dto.updatedAt(), dto.bookmarkId() diff --git a/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/QuerydslBookmarkRepository.java b/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/QuerydslBookmarkRepository.java index f63571d..147305c 100644 --- a/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/QuerydslBookmarkRepository.java +++ b/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/QuerydslBookmarkRepository.java @@ -54,7 +54,7 @@ public List findAllBy(BookmarkConditionDto dto) { word.meaning, word.category, word.viewCount, - word.example, + word.examples, word.createdAt, word.updatedAt, bookmark.id diff --git a/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/dto/response/BookmarkWordDto.java b/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/dto/response/BookmarkWordDto.java index acb572a..83a06ea 100644 --- a/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/dto/response/BookmarkWordDto.java +++ b/src/main/java/com/dnd/spaced/domain/bookmark/domain/repository/dto/response/BookmarkWordDto.java @@ -3,6 +3,7 @@ import com.dnd.spaced.domain.word.domain.Category; import com.dnd.spaced.domain.word.domain.Pronunciation; import java.time.LocalDateTime; +import java.util.List; public record BookmarkWordDto( Long wordId, @@ -11,7 +12,7 @@ public record BookmarkWordDto( String meaning, Category category, int viewCount, - String example, + List examples, LocalDateTime createdAt, LocalDateTime updatedAt, Long bookmarkId diff --git a/src/main/java/com/dnd/spaced/domain/bookmark/presentation/dto/response/BookmarkWordResponse.java b/src/main/java/com/dnd/spaced/domain/bookmark/presentation/dto/response/BookmarkWordResponse.java index 1aefd69..594e318 100644 --- a/src/main/java/com/dnd/spaced/domain/bookmark/presentation/dto/response/BookmarkWordResponse.java +++ b/src/main/java/com/dnd/spaced/domain/bookmark/presentation/dto/response/BookmarkWordResponse.java @@ -40,7 +40,7 @@ public static BookmarkWordInfoResponse from(BookmarkWordInfoDto dto) { dto.meaning(), dto.category(), dto.viewCount(), - dto.example(), + dto.examples().toString(), dto.createdAt(), dto.updatedAt(), dto.bookmarkId() diff --git a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/DetailWordInfoDto.java b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/DetailWordInfoDto.java index d355519..7e8dc65 100644 --- a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/DetailWordInfoDto.java +++ b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/DetailWordInfoDto.java @@ -2,6 +2,7 @@ import com.dnd.spaced.domain.word.domain.repository.dto.response.WordInfoWithBookmarkDto; import java.time.LocalDateTime; +import java.util.List; public record DetailWordInfoDto( Long id, @@ -12,7 +13,7 @@ public record DetailWordInfoDto( int viewCount, int commentCount, int bookmarkCount, - String example, + List examples, boolean isMarked, LocalDateTime createdAt, LocalDateTime updatedAt @@ -28,7 +29,7 @@ public static DetailWordInfoDto from(WordInfoWithBookmarkDto dto) { dto.viewCount() + 1, dto.commentCount(), dto.bookmarkCount(), - dto.example(), + dto.examples(), dto.bookmarkId() != null, dto.createdAt(), dto.updatedAt() diff --git a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/ListWordInfoDto.java b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/ListWordInfoDto.java index de51d49..2d91edf 100644 --- a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/ListWordInfoDto.java +++ b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/ListWordInfoDto.java @@ -24,7 +24,7 @@ public static ListWordInfoDto from(Word word) { word.getCategory().getName(), word.getCommentCount(), word.getViewCount(), - word.getExample(), + word.getExamples().toString(), word.getCreatedAt(), word.getUpdatedAt() ); diff --git a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/MultipleWordInfoDto.java b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/MultipleWordInfoDto.java index 1a4a7f9..5112ce0 100644 --- a/src/main/java/com/dnd/spaced/domain/word/application/dto/response/MultipleWordInfoDto.java +++ b/src/main/java/com/dnd/spaced/domain/word/application/dto/response/MultipleWordInfoDto.java @@ -23,7 +23,7 @@ public static MultipleWordInfoDto from(Word word) { word.getMeaning(), word.getCategory().getName(), word.getViewCount(), - word.getExample(), + word.getExamples().toString(), word.getCreatedAt(), word.getUpdatedAt() ); diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/Word.java b/src/main/java/com/dnd/spaced/domain/word/domain/Word.java index 88dab48..17d36a7 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/Word.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/Word.java @@ -4,19 +4,15 @@ import com.dnd.spaced.domain.word.domain.exception.InvalidMeaningException; import com.dnd.spaced.domain.word.domain.exception.InvalidNameException; import com.dnd.spaced.global.entity.BaseTimeEntity; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -42,7 +38,8 @@ public class Word extends BaseTimeEntity { @Enumerated(EnumType.STRING) private Category category; - private String example; + @ElementCollection + private List examples; private int viewCount = 0; @@ -56,9 +53,9 @@ private Word( String englishPronunciation, String meaning, String categoryName, - String example + List examples ) { - validateContent(name, meaning, example); + validateContent(name, meaning, examples.toString()); this.name = name; this.pronunciation = Pronunciation.builder() @@ -66,7 +63,7 @@ private Word( .build(); this.meaning = meaning; this.category = Category.findBy(categoryName); - this.example = example; + this.examples = examples; } public void addComment() { @@ -105,13 +102,13 @@ private boolean isInvalidExample(String example) { return MIN_EXAMPLE_LENGTH > length || MAX_EXAMPLE_LENGTH < length; } - public void updateDetails(String name, String englishPronunciation, String meaning, String categoryName, String example) { + public void updateDetails(String name, String englishPronunciation, String meaning, String categoryName, List examples) { this.name = name; this.pronunciation = Pronunciation.builder() .english(englishPronunciation) .build(); this.meaning = meaning; this.category = Category.findBy(categoryName); - this.example = example; + this.examples = examples; } } diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java index d251e25..adb3dbb 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/repository/QuerydslWordRepository.java @@ -64,7 +64,7 @@ public Optional findWithBookmarkBy(Long wordId, Long ac word.pronunciation, word.meaning, word.category, - word.example, + word.examples, word.viewCount, word.commentCount, word.bookmarkCount, diff --git a/src/main/java/com/dnd/spaced/domain/word/domain/repository/dto/response/WordInfoWithBookmarkDto.java b/src/main/java/com/dnd/spaced/domain/word/domain/repository/dto/response/WordInfoWithBookmarkDto.java index fb0812c..47c62c1 100644 --- a/src/main/java/com/dnd/spaced/domain/word/domain/repository/dto/response/WordInfoWithBookmarkDto.java +++ b/src/main/java/com/dnd/spaced/domain/word/domain/repository/dto/response/WordInfoWithBookmarkDto.java @@ -3,6 +3,7 @@ import com.dnd.spaced.domain.word.domain.Category; import com.dnd.spaced.domain.word.domain.Pronunciation; import java.time.LocalDateTime; +import java.util.List; public record WordInfoWithBookmarkDto( Long wordId, @@ -10,7 +11,7 @@ public record WordInfoWithBookmarkDto( Pronunciation pronunciation, String meaning, Category category, - String example, + List examples, int viewCount, int commentCount, int bookmarkCount, diff --git a/src/main/java/com/dnd/spaced/domain/word/presentation/dto/response/DetailWordInfoResponse.java b/src/main/java/com/dnd/spaced/domain/word/presentation/dto/response/DetailWordInfoResponse.java index 0b4a23d..bf9b77a 100644 --- a/src/main/java/com/dnd/spaced/domain/word/presentation/dto/response/DetailWordInfoResponse.java +++ b/src/main/java/com/dnd/spaced/domain/word/presentation/dto/response/DetailWordInfoResponse.java @@ -3,6 +3,8 @@ import com.dnd.spaced.domain.word.application.dto.response.DetailWordInfoDto; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + public record DetailWordInfoResponse( @Schema(description = "용어 ID") @@ -12,7 +14,7 @@ public record DetailWordInfoResponse( String name, @Schema(description = "용어 예문") - String example, + List examples, @Schema(description = "용어 발음 정보") PronunciationInfoResponse pronunciationInfo, @@ -43,7 +45,7 @@ public static DetailWordInfoResponse from(DetailWordInfoDto dto) { return new DetailWordInfoResponse( dto.id(), dto.name(), - dto.example(), + dto.examples(), new PronunciationInfoResponse(dto.pronunciationInfo().english()), dto.meaning(), dto.category(),