Skip to content

Commit

Permalink
Merge pull request #115 from dnd-side-project/fix/#113
Browse files Browse the repository at this point in the history
Change Examples Type To List
  • Loading branch information
miraexhoi authored Sep 5, 2024
2 parents a840fc9 + 603be99 commit c6fccbc
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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;
}
Expand All @@ -44,7 +44,7 @@ public static AdminWordResponse toResponseDto(Word word) {
word.getPronunciation(),
word.getMeaning(),
word.getCategory().name(),
word.getExample()
word.getExamples()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> examples
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -21,5 +23,5 @@ public record AdminWordResponse(
String category,

@Schema(description = "예문")
String example
List<String> examples
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -10,7 +11,7 @@ public record BookmarkWordInfoDto(
String meaning,
String category,
int viewCount,
String example,
List<String> examples,
LocalDateTime createdAt,
LocalDateTime updatedAt,
Long bookmarkId
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<BookmarkWordDto> findAllBy(BookmarkConditionDto dto) {
word.meaning,
word.category,
word.viewCount,
word.example,
word.examples,
word.createdAt,
word.updatedAt,
bookmark.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -11,7 +12,7 @@ public record BookmarkWordDto(
String meaning,
Category category,
int viewCount,
String example,
List<String> examples,
LocalDateTime createdAt,
LocalDateTime updatedAt,
Long bookmarkId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -12,7 +13,7 @@ public record DetailWordInfoDto(
int viewCount,
int commentCount,
int bookmarkCount,
String example,
List<String> examples,
boolean isMarked,
LocalDateTime createdAt,
LocalDateTime updatedAt
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/com/dnd/spaced/domain/word/domain/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,7 +38,8 @@ public class Word extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private Category category;

private String example;
@ElementCollection
private List<String> examples;

private int viewCount = 0;

Expand All @@ -56,17 +53,17 @@ private Word(
String englishPronunciation,
String meaning,
String categoryName,
String example
List<String> examples
) {
validateContent(name, meaning, example);
validateContent(name, meaning, examples.toString());

this.name = name;
this.pronunciation = Pronunciation.builder()
.english(englishPronunciation)
.build();
this.meaning = meaning;
this.category = Category.findBy(categoryName);
this.example = example;
this.examples = examples;
}

public void addComment() {
Expand Down Expand Up @@ -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<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Optional<WordInfoWithBookmarkDto> findWithBookmarkBy(Long wordId, Long ac
word.pronunciation,
word.meaning,
word.category,
word.example,
word.examples,
word.viewCount,
word.commentCount,
word.bookmarkCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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,
String name,
Pronunciation pronunciation,
String meaning,
Category category,
String example,
List<String> examples,
int viewCount,
int commentCount,
int bookmarkCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -12,7 +14,7 @@ public record DetailWordInfoResponse(
String name,

@Schema(description = "용어 예문")
String example,
List<String> examples,

@Schema(description = "용어 발음 정보")
PronunciationInfoResponse pronunciationInfo,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit c6fccbc

Please sign in to comment.