-
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 #15 from goormthon-Univ/develop
quiz / logout bug fix
- Loading branch information
Showing
21 changed files
with
680 additions
and
77 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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/beotkkot/qtudy/controller/quiz/QuizController.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,52 @@ | ||
package com.beotkkot.qtudy.controller.quiz; | ||
|
||
import com.beotkkot.qtudy.dto.request.quiz.GenerateQuizRequestDto; | ||
import com.beotkkot.qtudy.dto.request.quiz.GradeQuizRequestDto; | ||
import com.beotkkot.qtudy.dto.response.quiz.GetPostQuizResponseDto; | ||
import com.beotkkot.qtudy.dto.response.quiz.QuizGradeResponseDto; | ||
import com.beotkkot.qtudy.service.quiz.QuizService; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@Slf4j | ||
public class QuizController { | ||
|
||
private final QuizService quizService; | ||
|
||
// 퀴즈 생성 및 저장 | ||
@PostMapping("/quiz") | ||
public ResponseEntity<?> generateQuiz(@RequestBody GenerateQuizRequestDto dto) { | ||
try { | ||
return ResponseEntity.ok().body(quizService.generateQuiz(dto)); | ||
} catch (HttpClientErrorException | JsonProcessingException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
} | ||
|
||
// 태그별 퀴즈 출력 | ||
@GetMapping("/quiz/tag-quiz/{tagName}") | ||
public ResponseEntity<? super GetPostQuizResponseDto> getTagQuiz(@PathVariable String tagName) { | ||
ResponseEntity<? super GetPostQuizResponseDto> response = quizService.getTagQuiz(tagName); | ||
return response; | ||
} | ||
|
||
// 게시글 별 퀴즈 출력 | ||
@GetMapping("/quiz/post-quiz/{postId}") | ||
public ResponseEntity<? super GetPostQuizResponseDto> getPostQuiz(@PathVariable Long postId) { | ||
ResponseEntity<? super GetPostQuizResponseDto> response = quizService.getPostQuiz(postId); | ||
return response; | ||
} | ||
|
||
// 정답 채점 | ||
@PostMapping("/quiz/grade") | ||
public ResponseEntity<? super QuizGradeResponseDto> gradeQuiz(@RequestBody GradeQuizRequestDto dto) { | ||
ResponseEntity<? super QuizGradeResponseDto> response = quizService.gradeQuiz(dto); | ||
return response; | ||
} | ||
} |
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,34 @@ | ||
package com.beotkkot.qtudy.domain.quiz; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Builder | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
public class Quiz { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long quizId; | ||
|
||
@Column(nullable = false) | ||
private Long postId; | ||
|
||
@Column(nullable = false, columnDefinition = "TEXT") | ||
private String tags; | ||
|
||
@Column(nullable = false, columnDefinition = "TEXT") | ||
private String question; | ||
|
||
@Column(/*nullable = false,*/ columnDefinition = "TEXT") | ||
private String answer; | ||
|
||
@Column(/*nullable = false,*/ columnDefinition = "TEXT") | ||
private String explanation; | ||
|
||
@Column(nullable = false, columnDefinition = "TEXT") | ||
private String options; | ||
} |
18 changes: 0 additions & 18 deletions
18
src/main/java/com/beotkkot/qtudy/dto/auth/UserResponse.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...eotkkot/qtudy/dto/auth/KakaoUserInfo.java → ...tkkot/qtudy/dto/object/KakaoUserInfo.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.beotkkot.qtudy.dto.object; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class QuizDto { | ||
private String question; | ||
private String answer; | ||
private List<String> options; | ||
private String explanation; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/beotkkot/qtudy/dto/object/QuizGradeListItem.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,41 @@ | ||
package com.beotkkot.qtudy.dto.object; | ||
|
||
import com.beotkkot.qtudy.domain.quiz.Quiz; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class QuizGradeListItem { | ||
private Long quizId; | ||
private List<String> tags; | ||
private String question; | ||
private String answer; | ||
private boolean correct; | ||
private int userAnswer; | ||
private List<String> options; | ||
private String explanation; | ||
|
||
public static QuizGradeListItem of(Quiz quiz, boolean correct, int userAnswer) { | ||
List<String> tags = Arrays.asList(quiz.getTags().split("\\s*,\\s*")); | ||
List<String> options = Arrays.asList(quiz.getOptions().split("\\s*,\\s*")); | ||
|
||
return QuizGradeListItem.builder() | ||
.quizId(quiz.getQuizId()) | ||
.tags(tags) | ||
.question(quiz.getQuestion()) | ||
.answer(quiz.getAnswer()) | ||
.correct(correct) | ||
.userAnswer(userAnswer) | ||
.options(options) | ||
.explanation(quiz.getExplanation()) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/beotkkot/qtudy/dto/object/QuizListItem.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,37 @@ | ||
package com.beotkkot.qtudy.dto.object; | ||
|
||
import com.beotkkot.qtudy.domain.quiz.Quiz; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class QuizListItem { | ||
private Long quizId; | ||
private List<String> tags; | ||
private String question; | ||
private String answer; | ||
private List<String> options; | ||
private String explanation; | ||
|
||
public static QuizListItem of(Quiz quiz) { | ||
List<String> tags = Arrays.asList(quiz.getTags().split("\\s*,\\s*")); | ||
List<String> options = Arrays.asList(quiz.getOptions().split("\\s*,\\s*")); | ||
|
||
return QuizListItem.builder() | ||
.quizId(quiz.getQuizId()) | ||
.tags(tags) | ||
.question(quiz.getQuestion()) | ||
.answer(quiz.getAnswer()) | ||
.options(options) | ||
.explanation(quiz.getExplanation()) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/beotkkot/qtudy/dto/request/quiz/ChatMessageRequestDto.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,14 @@ | ||
package com.beotkkot.qtudy.dto.request.quiz; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ChatMessageRequestDto { | ||
private String role; | ||
private String content; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/beotkkot/qtudy/dto/request/quiz/GenerateQuizRequestDto.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,14 @@ | ||
package com.beotkkot.qtudy.dto.request.quiz; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GenerateQuizRequestDto { | ||
private Long postId; | ||
private String tags; | ||
private String summary; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/beotkkot/qtudy/dto/request/quiz/GradeQuizRequestDto.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,16 @@ | ||
package com.beotkkot.qtudy.dto.request.quiz; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GradeQuizRequestDto { | ||
private List<Long> quizIdList; | ||
private List<String> answerList; | ||
private List<Integer> userAnswerList; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/beotkkot/qtudy/dto/request/quiz/PostQuizRequestDto.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,15 @@ | ||
package com.beotkkot.qtudy.dto.request.quiz; | ||
|
||
import com.beotkkot.qtudy.dto.object.QuizDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PostQuizRequestDto { | ||
private Long postId; | ||
private String tags; | ||
private QuizDto quizDto; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/beotkkot/qtudy/dto/response/auth/AuthResponseDto.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,30 @@ | ||
package com.beotkkot.qtudy.dto.response.auth; | ||
|
||
import com.beotkkot.qtudy.common.ResponseCode; | ||
import com.beotkkot.qtudy.common.ResponseMessage; | ||
import com.beotkkot.qtudy.dto.response.ResponseDto; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Getter | ||
public class AuthResponseDto extends ResponseDto { | ||
private AuthResponseDto() { | ||
super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS); | ||
} | ||
|
||
public static ResponseEntity<AuthResponseDto> success() { | ||
AuthResponseDto result = new AuthResponseDto(); | ||
return ResponseEntity.status(HttpStatus.OK).body(result); | ||
} | ||
|
||
public static ResponseEntity<ResponseDto> notExistUser() { | ||
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER); | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result); | ||
} | ||
|
||
public static ResponseEntity<ResponseDto> noAuthentication() { | ||
ResponseDto result = new ResponseDto(ResponseCode.AUTHORIZATION_FAIL, ResponseMessage.AUTHORIZATION_FAIL); | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result); | ||
} | ||
} |
Oops, something went wrong.