-
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.
Merge pull request #96 from ShyPolarBear/refactor/quiz_dto_conversion
refactor: Quiz dto의 타입 캐스팅 책임 이동
- Loading branch information
Showing
9 changed files
with
90 additions
and
86 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
src/main/java/com/shy_polarbear/server/domain/quiz/dto/QuizType.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
15 changes: 8 additions & 7 deletions
15
src/main/java/com/shy_polarbear/server/domain/quiz/model/MultipleChoiceQuiz.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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
package com.shy_polarbear.server.domain.quiz.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.OneToMany; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Entity | ||
@DiscriminatorValue("M") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MultipleChoiceQuiz extends Quiz { | ||
@OneToMany(mappedBy = "multipleChoiceQuiz", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<MultipleChoice> multipleChoiceList = new ArrayList<>(); | ||
private final List<MultipleChoice> multipleChoiceList = new ArrayList<>(); | ||
|
||
@Builder | ||
public MultipleChoiceQuiz(String question, String explanation) { | ||
super(question, explanation); | ||
super(QuizType.MULTIPLE_CHOICE, question, explanation); | ||
} | ||
|
||
} |
14 changes: 6 additions & 8 deletions
14
src/main/java/com/shy_polarbear/server/domain/quiz/model/OXQuiz.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 |
---|---|---|
@@ -1,27 +1,25 @@ | ||
package com.shy_polarbear.server.domain.quiz.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.DiscriminatorValue; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
|
||
// TODO: Getter, constructor, builder은 어디서 만드는게 좋지? 자식쪽에서 하는게 맞을듯. Quiz에서 만들고 다 적용되면 좋긴한데. | ||
@Getter | ||
@Entity | ||
@DiscriminatorValue("OX") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class OXQuiz extends Quiz { | ||
|
||
@Enumerated(EnumType.STRING) | ||
private OXChoice answer; | ||
|
||
@Builder | ||
public OXQuiz(String question, String explanation, OXChoice answer) { | ||
super(question, explanation); | ||
super(QuizType.OX, question, explanation); | ||
this.answer = answer; | ||
} | ||
|
||
} |
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
33 changes: 30 additions & 3 deletions
33
src/main/java/com/shy_polarbear/server/domain/quiz/model/QuizType.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 |
---|---|---|
@@ -1,9 +1,36 @@ | ||
package com.shy_polarbear.server.domain.quiz.model; | ||
|
||
import com.shy_polarbear.server.domain.quiz.exception.QuizException; | ||
import com.shy_polarbear.server.global.common.util.EnumModel; | ||
import com.shy_polarbear.server.global.exception.ExceptionStatus; | ||
import java.util.Arrays; | ||
import lombok.AllArgsConstructor; | ||
|
||
public enum QuizType { | ||
@AllArgsConstructor | ||
public enum QuizType implements EnumModel<String> { | ||
OX("OX", 17), MULTIPLE_CHOICE("MULTIPLE_CHOICE", 17); | ||
|
||
// OX, 객관식 | ||
TRUE_FALSE, MULTIPLE_CHOICE | ||
private final String value; | ||
private final int timeLimit; | ||
|
||
public static QuizType of(String param) { | ||
return Arrays.stream(QuizType.values()) | ||
.filter(v -> v.getValue().equals(param.toUpperCase())) | ||
.findFirst() | ||
.orElseThrow(() -> new QuizException(ExceptionStatus.CLIENT_ERROR)); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return this.name(); | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return this.value; | ||
} | ||
|
||
public int getTimeLimit() { | ||
return this.timeLimit; | ||
} | ||
} |
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
5 changes: 2 additions & 3 deletions
5
src/main/java/com/shy_polarbear/server/global/common/constants/BusinessLogicConstants.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
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