feat: quiz 사진 등록 추가, 퀴즈 타입 코드 변경
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 8.4 KiB |
@ -1,19 +1,20 @@
|
||||
package com.edufocus.edufocus.quiz.controller;
|
||||
|
||||
import com.edufocus.edufocus.quiz.entity.*;
|
||||
import com.edufocus.edufocus.quiz.repository.QuizRepository;
|
||||
import com.edufocus.edufocus.quiz.service.QuizService;
|
||||
import com.edufocus.edufocus.quiz.service.QuizSetService;
|
||||
import com.edufocus.edufocus.user.model.service.UserService;
|
||||
import com.edufocus.edufocus.user.util.JWTUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/quiz")
|
||||
@ -25,21 +26,32 @@ public class QuizController {
|
||||
|
||||
private final QuizSetService quizSetService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final JWTUtil jwtUtil;
|
||||
private final QuizRepository quizRepository;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createQuizSet(@RequestHeader("Authorization") String accessToken, @RequestBody QuizSetCreateRequest quizSetCreateRequest) {
|
||||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<?> createQuizSet(@RequestHeader("Authorization") String accessToken, @RequestPart QuizSetCreateRequest quizSetCreateRequest
|
||||
, @RequestPart(value = "image", required = false) MultipartFile image) throws IOException {
|
||||
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
|
||||
|
||||
String title = quizSetCreateRequest.getTitle();
|
||||
String image = quizSetCreateRequest.getImage();
|
||||
|
||||
SetCreateRequest setCreateRequest = new SetCreateRequest(userId, title, image);
|
||||
SetCreateRequest setCreateRequest = new SetCreateRequest(userId, title);
|
||||
|
||||
QuizSet quizSet = quizSetService.createQuizSet(setCreateRequest);
|
||||
if (image != null && !image.isEmpty()) {
|
||||
String uid = UUID.randomUUID().toString();
|
||||
|
||||
String currentPath = "backend/src/main/resources/images/";
|
||||
File checkPathFile = new File(currentPath);
|
||||
if (!checkPathFile.exists()) {
|
||||
checkPathFile.mkdirs();
|
||||
}
|
||||
|
||||
File savingImage = new File(currentPath + uid + "_" + image.getOriginalFilename());
|
||||
image.transferTo(savingImage.toPath());
|
||||
String savePath = savingImage.toPath().toString();
|
||||
|
||||
quizSet.setImage(savePath);
|
||||
}
|
||||
|
||||
for (QuizCreateRequest quizCreateRequest : quizSetCreateRequest.getQuizzes()) {
|
||||
quizService.createQuiz(quizSet.getId(), quizCreateRequest);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.edufocus.edufocus.quiz.entity;
|
||||
|
||||
import com.edufocus.edufocus.user.model.entity.UserRole;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import jakarta.persistence.*;
|
||||
@ -31,8 +32,8 @@ public class Quiz {
|
||||
@Column
|
||||
private String answer;
|
||||
|
||||
@Column (name = "is_single")
|
||||
private boolean isSingle;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private QuizType quizType;
|
||||
|
||||
@Column
|
||||
private String image;
|
||||
|
@ -15,9 +15,7 @@ public class QuizCreateRequest {
|
||||
|
||||
private String answer;
|
||||
|
||||
private boolean isSingle;
|
||||
|
||||
private String image;
|
||||
private String quizType;
|
||||
|
||||
private String choice1;
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.edufocus.edufocus.quiz.entity;
|
||||
|
||||
public enum QuizType {
|
||||
SINGLE, MULTIPLE
|
||||
}
|
@ -13,6 +13,4 @@ public class SetCreateRequest {
|
||||
|
||||
private String title;
|
||||
|
||||
private String image;
|
||||
|
||||
}
|
||||
|
@ -3,14 +3,13 @@ package com.edufocus.edufocus.quiz.service;
|
||||
import com.edufocus.edufocus.quiz.entity.Quiz;
|
||||
import com.edufocus.edufocus.quiz.entity.QuizCreateRequest;
|
||||
import com.edufocus.edufocus.quiz.entity.QuizSet;
|
||||
import com.edufocus.edufocus.quiz.entity.QuizType;
|
||||
import com.edufocus.edufocus.quiz.repository.QuizRepository;
|
||||
import com.edufocus.edufocus.quiz.repository.QuizSetRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
@ -28,11 +27,11 @@ public class QuizServiceImpl implements QuizService {
|
||||
.title(quizCreateRequest.getTitle())
|
||||
.description(quizCreateRequest.getDescription())
|
||||
.answer(quizCreateRequest.getAnswer())
|
||||
.image(quizCreateRequest.getImage())
|
||||
.quizType(QuizType.valueOf(quizCreateRequest.getQuizType()))
|
||||
.quizSet(quizSet)
|
||||
.build();
|
||||
|
||||
if (!quiz.isSingle()) {
|
||||
if (!quiz.getQuizType().equals(QuizType.MULTIPLE)) {
|
||||
quiz.setChoice1(quizCreateRequest.getChoice1());
|
||||
quiz.setChoice2(quizCreateRequest.getChoice2());
|
||||
quiz.setChoice3(quizCreateRequest.getChoice3());
|
||||
|
@ -17,7 +17,6 @@ public class QuizSetServiceImpl implements QuizSetService {
|
||||
private final QuizSetRepository quizSetRepository;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final QuizRepository quizRepository;
|
||||
|
||||
|
||||
@Override
|
||||
@ -29,7 +28,6 @@ public class QuizSetServiceImpl implements QuizSetService {
|
||||
quizSet.setUser(user);
|
||||
|
||||
quizSet.setTitle(setCreateRequest.getTitle());
|
||||
quizSet.setImage(setCreateRequest.getImage());
|
||||
|
||||
return quizSetRepository.save(quizSet);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class WebConfiguration implements WebMvcConfigurer {
|
||||
registry.addInterceptor(jwtInterceptor)
|
||||
|
||||
.addPathPatterns("/**") // 모든 경로에 대해 인터셉터 적용
|
||||
.excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**"); // 인증 없이 접근 가능한 경로 설정
|
||||
.excludePathPatterns("/v3/api-docs/**","/swagger-resources/**","/webjars/**","/swagger-ui/**","/auth/**", "/board/**", "/user/**","/lecture/**","/qna/**", "/quiz/**"); // 인증 없이 접근 가능한 경로 설정
|
||||
|
||||
///v3/api-docs/**, /swagger-resources/**, /webjars/**
|
||||
}
|
||||
|