-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] 이미지 퀴즈 추가 #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[feat] 이미지 퀴즈 추가 #186
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfa1a44
feat: 이미지 퀴즈 추가
dlsrks1021 09ea374
chore: Java 스타일 수정
d43dfca
chore: Java 스타일 수정
61b4120
chore: question이 필요하지 않은 quiz에 대해 findQuizById를 사용하도록 수정
dlsrks1021 12c5b69
chore: Java 스타일 수정
1844386
chore: room.getGameSetting.getQuizId를 room.getQuizId 메서드로 교체
dlsrks1021 39fd1a7
chore: deleteQuiz의 이미지 삭제 메서드를 deleteQuestion으로 대체
dlsrks1021 52f2bc3
chore: Java 스타일 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/io/f1/backend/domain/game/dto/response/GameStartResponse.java
This file contains hidden or 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,7 +1,8 @@ | ||
| package io.f1.backend.domain.game.dto.response; | ||
|
|
||
| import io.f1.backend.domain.quiz.dto.GameQuestionResponse; | ||
| import io.f1.backend.domain.quiz.entity.QuizType; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record GameStartResponse(List<GameQuestionResponse> questions) {} | ||
| public record GameStartResponse(QuizType quizType, List<GameQuestionResponse> questions) {} |
17 changes: 1 addition & 16 deletions
17
backend/src/main/java/io/f1/backend/domain/question/api/QuestionController.java
This file contains hidden or 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,26 +1,11 @@ | ||
| package io.f1.backend.domain.question.api; | ||
|
|
||
| import io.f1.backend.domain.question.app.QuestionService; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/questions") | ||
| @RequiredArgsConstructor | ||
| public class QuestionController { | ||
|
|
||
| private final QuestionService questionService; | ||
|
|
||
| @DeleteMapping("/{questionId}") | ||
| public ResponseEntity<Void> deleteQuestion(@PathVariable Long questionId) { | ||
| questionService.deleteQuestion(questionId); | ||
|
|
||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
| public class QuestionController {} |
79 changes: 43 additions & 36 deletions
79
backend/src/main/java/io/f1/backend/domain/question/app/QuestionService.java
This file contains hidden or 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,72 +1,79 @@ | ||
| package io.f1.backend.domain.question.app; | ||
|
|
||
| import static io.f1.backend.domain.question.mapper.QuestionMapper.questionRequestToQuestion; | ||
| import static io.f1.backend.domain.question.mapper.TextQuestionMapper.questionRequestToTextQuestion; | ||
| import static io.f1.backend.domain.quiz.app.QuizService.verifyUserAuthority; | ||
|
|
||
| import io.f1.backend.domain.question.dao.ContentQuestionRepository; | ||
| import io.f1.backend.domain.question.dao.QuestionRepository; | ||
| import io.f1.backend.domain.question.dao.TextQuestionRepository; | ||
| import io.f1.backend.domain.question.dto.QuestionRequest; | ||
| import io.f1.backend.domain.question.dto.QuestionUpdateRequest; | ||
| import io.f1.backend.domain.question.dto.ContentQuestionRequest; | ||
| import io.f1.backend.domain.question.dto.ContentQuestionUpdateRequest; | ||
| import io.f1.backend.domain.question.entity.ContentQuestion; | ||
| import io.f1.backend.domain.question.entity.Question; | ||
| import io.f1.backend.domain.question.entity.TextQuestion; | ||
| import io.f1.backend.domain.quiz.entity.Quiz; | ||
| import io.f1.backend.domain.quiz.entity.QuizType; | ||
| import io.f1.backend.global.exception.CustomException; | ||
| import io.f1.backend.global.exception.errorcode.QuestionErrorCode; | ||
| import io.f1.backend.global.util.FileManager; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class QuestionService { | ||
|
|
||
| private final QuestionRepository questionRepository; | ||
| private final TextQuestionRepository textQuestionRepository; | ||
|
|
||
| @Transactional | ||
| public void saveQuestion(Quiz quiz, QuestionRequest request) { | ||
| private final ContentQuestionRepository contentQuestionRepository; | ||
|
|
||
| Question question = questionRequestToQuestion(quiz, request); | ||
| public void saveContentQuestion(Quiz quiz, ContentQuestionRequest request) { | ||
| Question question = new Question(quiz, request.getAnswer()); | ||
| quiz.addQuestion(question); | ||
| questionRepository.save(question); | ||
|
|
||
| TextQuestion textQuestion = questionRequestToTextQuestion(question, request.getContent()); | ||
| textQuestionRepository.save(textQuestion); | ||
| question.addTextQuestion(textQuestion); | ||
| ContentQuestion contentQuestion = request.toContentQuestion(question); | ||
| contentQuestionRepository.save(contentQuestion); | ||
| question.addContentQuestion(contentQuestion); | ||
| } | ||
|
|
||
| public void updateQuestions(Quiz quiz, QuestionUpdateRequest request) { | ||
|
|
||
| public void updateContentQuestions(Quiz quiz, ContentQuestionUpdateRequest request) { | ||
| if (request.getId() == null) { | ||
| saveQuestion(quiz, QuestionRequest.of(request)); | ||
| saveContentQuestion( | ||
| quiz, ContentQuestionRequest.of(request.getContent(), request.getAnswer())); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| Question question = | ||
| questionRepository | ||
| .findById(request.getId()) | ||
| .orElseThrow( | ||
| () -> new CustomException(QuestionErrorCode.QUESTION_NOT_FOUND)); | ||
| Question question = getQuestionWithContent(request.getId()); | ||
|
|
||
| if (request.getContent() != null) { | ||
| ContentQuestion contentQuestion = question.getContentQuestion(); | ||
| contentQuestion.changeContent(request.getContent()); | ||
| } | ||
|
|
||
| TextQuestion textQuestion = question.getTextQuestion(); | ||
| textQuestion.changeContent(request.getContent()); | ||
| question.changeAnswer(request.getAnswer()); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void deleteQuestion(Long questionId) { | ||
| public void deleteQuestion(Long questionId, QuizType quizType) { | ||
| Question question; | ||
|
|
||
| Question question = | ||
| questionRepository | ||
| .findById(questionId) | ||
| .orElseThrow( | ||
| () -> new CustomException(QuestionErrorCode.QUESTION_NOT_FOUND)); | ||
|
|
||
| verifyUserAuthority(question.getQuiz()); | ||
| if (quizType.name().equals("IMAGE")) { | ||
| question = getQuestionWithContent(questionId); | ||
| String filePath = question.getContentQuestion().getContent(); | ||
| FileManager.deleteFile(filePath); | ||
| } else { | ||
| question = getQuestion(questionId); | ||
| } | ||
|
|
||
| questionRepository.delete(question); | ||
| } | ||
|
|
||
| private Question getQuestion(Long questionId) { | ||
| return questionRepository | ||
| .findById(questionId) | ||
| .orElseThrow(() -> new CustomException(QuestionErrorCode.QUESTION_NOT_FOUND)); | ||
| } | ||
|
|
||
| private Question getQuestionWithContent(Long questionId) { | ||
| return questionRepository | ||
| .findByIdWithContent(questionId) | ||
| .orElseThrow(() -> new CustomException(QuestionErrorCode.QUESTION_NOT_FOUND)); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/io/f1/backend/domain/question/dao/ContentQuestionRepository.java
This file contains hidden or 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,7 @@ | ||
| package io.f1.backend.domain.question.dao; | ||
|
|
||
| import io.f1.backend.domain.question.entity.ContentQuestion; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ContentQuestionRepository extends JpaRepository<ContentQuestion, Long> {} |
This file contains hidden or 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
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/io/f1/backend/domain/question/dao/TextQuestionRepository.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/io/f1/backend/domain/question/dto/ContentQuestionRequest.java
This file contains hidden or 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,28 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import io.f1.backend.domain.question.entity.ContentQuestion; | ||
| import io.f1.backend.domain.question.entity.Question; | ||
| import io.f1.backend.domain.quiz.entity.Quiz; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class ContentQuestionRequest { | ||
| private String content; | ||
| private String answer; | ||
|
|
||
| public static ContentQuestionRequest of(String content, String answer) { | ||
| return new ContentQuestionRequest(content, answer); | ||
| } | ||
|
|
||
| public ContentQuestion toContentQuestion(Question question) { | ||
| return new ContentQuestion(question, content); | ||
| } | ||
|
|
||
| public Question toQuestion(Quiz quiz) { | ||
| return new Question(quiz, answer); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/io/f1/backend/domain/question/dto/ContentQuestionUpdateRequest.java
This file contains hidden or 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,17 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class ContentQuestionUpdateRequest { | ||
| private Long id; | ||
| private String content; | ||
| private String answer; | ||
|
|
||
| public static ContentQuestionUpdateRequest of(Long id, String content, String answer) { | ||
| return new ContentQuestionUpdateRequest(id, content, answer); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/io/f1/backend/domain/question/dto/ImageQuestionRequest.java
This file contains hidden or 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,8 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import io.f1.backend.global.validation.TrimmedSize; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record ImageQuestionRequest( | ||
| @TrimmedSize(min = 1, max = 30) @NotBlank(message = "정답을 입력해주세요.") String answer) {} |
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/io/f1/backend/domain/question/dto/ImageQuestionUpdateRequest.java
This file contains hidden or 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,22 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import io.f1.backend.global.validation.TrimmedSize; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ImageQuestionUpdateRequest { | ||
| private Long id; | ||
|
|
||
| private boolean imageFile; | ||
|
|
||
| @TrimmedSize(min = 1, max = 30) | ||
| @NotBlank(message = "정답을 입력해주세요.") | ||
| private String answer; | ||
|
|
||
| public boolean hasImageFile() { | ||
| return imageFile; | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
backend/src/main/java/io/f1/backend/domain/question/dto/QuestionDeleteRequest.java
This file contains hidden or 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,5 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record QuestionDeleteRequest(List<Long> questionIds) {} |
30 changes: 0 additions & 30 deletions
30
backend/src/main/java/io/f1/backend/domain/question/dto/QuestionRequest.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/io/f1/backend/domain/question/dto/TextQuestionUpdateRequest.java
This file contains hidden or 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,23 @@ | ||
| package io.f1.backend.domain.question.dto; | ||
|
|
||
| import io.f1.backend.global.validation.TrimmedSize; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class TextQuestionUpdateRequest { | ||
|
|
||
| private Long id; | ||
|
|
||
| @TrimmedSize(min = 5, max = 30) | ||
| @NotBlank(message = "문제를 입력해주세요.") | ||
| private String content; | ||
|
|
||
| @TrimmedSize(min = 1, max = 30) | ||
| @NotBlank(message = "정답을 입력해주세요.") | ||
| private String answer; | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.