Merge branch 'backend' of github.com:TeamBNBN/edufocus into be/Board

This commit is contained in:
yulmam 2024-07-18 16:17:22 +09:00
commit 3857cf7d69
14 changed files with 247 additions and 8 deletions

View File

@ -16,8 +16,7 @@ import java.util.List;
public class Lecture {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="lecture_id")
@Column
private Long id;
@ManyToOne

View File

@ -1,4 +1,46 @@
package com.edufocus.edufocus.quiz.controller;
import com.edufocus.edufocus.quiz.entity.*;
import com.edufocus.edufocus.quiz.service.QuizService;
import com.edufocus.edufocus.quiz.service.QuizSetService;
import com.edufocus.edufocus.user.model.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/quiz")
@Slf4j
@RequiredArgsConstructor
public class QuizController {
private final QuizService quizService;
private final QuizSetService quizSetService;
private final UserService userService;
@PostMapping
public ResponseEntity<?> createQuizSet(@RequestBody QuizSetCreateRequest quizSetCreateRequest) {
Long userId = 1L;
String title = quizSetCreateRequest.getTitle();
String image = quizSetCreateRequest.getImage();
SetCreateRequest setCreateRequest = new SetCreateRequest(userId, title, image);
QuizSet quizSet = quizSetService.createQuizSet(setCreateRequest);
for (QuizCreateRequest quizCreateRequest : quizSetCreateRequest.getQuizzes()) {
quizService.createQuiz(quizSet.getId(), quizCreateRequest);
}
return new ResponseEntity<>(HttpStatus.CREATED);
}
}

View File

@ -0,0 +1,20 @@
package com.edufocus.edufocus.quiz.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class MutipleQuizCreateRequest extends QuizCreateRequest {
private String choice1;
private String choice2;
private String choice3;
private String choice4;
}

View File

@ -11,7 +11,7 @@ public class Quiz {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private Long id;
@ManyToOne
@JoinColumn(name = "quizset_id")

View File

@ -0,0 +1,23 @@
package com.edufocus.edufocus.quiz.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class QuizCreateRequest {
private String title;
private String description;
private boolean isSingle;
private String answer;
private String image;
}

View File

@ -15,7 +15,7 @@ public class QuizSet {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")

View File

@ -0,0 +1,22 @@
package com.edufocus.edufocus.quiz.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.List;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class QuizSetCreateRequest {
private Long UserId;
private String title;
private String image;
private List<QuizCreateRequest> quizzes;
}

View File

@ -0,0 +1,18 @@
package com.edufocus.edufocus.quiz.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SetCreateRequest {
private Long UserId;
private String title;
private String image;
}

View File

@ -1,4 +1,7 @@
package com.edufocus.edufocus.quiz.repository;
public interface QuizRepository {
import com.edufocus.edufocus.quiz.entity.Quiz;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuizRepository extends JpaRepository<Quiz, Long> {
}

View File

@ -1,4 +1,8 @@
package com.edufocus.edufocus.quiz.repository;
public interface QuizSetRepository {
import com.edufocus.edufocus.quiz.entity.QuizSet;
import org.springframework.data.jpa.repository.JpaRepository;
public interface QuizSetRepository extends JpaRepository<QuizSet, Long> {
}

View File

@ -1,4 +1,14 @@
package com.edufocus.edufocus.quiz.service;
import com.edufocus.edufocus.quiz.entity.MutipleQuizCreateRequest;
import com.edufocus.edufocus.quiz.entity.QuizCreateRequest;
import org.springframework.stereotype.Service;
@Service
public interface QuizService {
void createQuiz(long quizSetId, QuizCreateRequest
QuizCreateRequest);
boolean deleteQuiz(long quizId);
}

View File

@ -1,4 +1,49 @@
package com.edufocus.edufocus.quiz.service;
public class QuizServiceImpl {
import com.edufocus.edufocus.quiz.entity.MutipleQuizCreateRequest;
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.repository.QuizRepository;
import com.edufocus.edufocus.quiz.repository.QuizSetRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@Transactional
@RequiredArgsConstructor
public class QuizServiceImpl implements QuizService {
private final QuizRepository quizRepository;
private final QuizSetRepository quizSetRepository;
@Override
public void createQuiz(long quizSetId, QuizCreateRequest quizCreateRequest) {
QuizSet quizSet = quizSetRepository.findById(quizSetId).get();
Quiz quiz = new Quiz();
quiz.setTitle(quizCreateRequest.getTitle());
quiz.setDescription(quizCreateRequest.getDescription());
quiz.setAnswer(quizCreateRequest.getAnswer());
quiz.setImage(quizCreateRequest.getImage());
quiz.setQuizSet(quizSet);
quizRepository.save(quiz);
}
@Override
public boolean deleteQuiz(long quizId) {
// 유저 아이디 정보 조회 검증 로직 추가 예정
// jwt -> 로그인 유저 정보 조회
// quizId -> 퀴즈 정보 조회 -> 퀴즈셋 정보 조회
// 퀴즈셋 생성자와 로그인 유저의 id값이 일치하는지 확인 -> 불일치시 삭제 실패
quizRepository.deleteById(quizId);
return true;
}
}

View File

@ -1,4 +1,16 @@
package com.edufocus.edufocus.quiz.service;
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.quiz.entity.SetCreateRequest;
import org.springframework.stereotype.Service;
@Service
public interface QuizSetService {
QuizSet createQuizSet(SetCreateRequest setCreateRequest);
void updateQuizSet(QuizSet quizSet);
void deleteQuizSet(long quizSetId);
}

View File

@ -1,4 +1,45 @@
package com.edufocus.edufocus.quiz.service;
public class QuizSetServiceImpl {
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.quiz.entity.SetCreateRequest;
import com.edufocus.edufocus.quiz.repository.QuizSetRepository;
import com.edufocus.edufocus.user.model.entity.User;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@Transactional
@RequiredArgsConstructor
public class QuizSetServiceImpl implements QuizSetService {
private final QuizSetRepository quizSetRepository;
private final UserRepository userRepository;
@Override
public QuizSet createQuizSet(SetCreateRequest setCreateRequest) {
QuizSet quizSet = new QuizSet();
User user = userRepository.findById(setCreateRequest.getUserId()).get();
quizSet.setUser(user);
quizSet.setTitle(setCreateRequest.getTitle());
quizSet.setImage(setCreateRequest.getImage());
return quizSetRepository.save(quizSet);
}
@Override
public void updateQuizSet(QuizSet quizSet) {
}
@Override
public void deleteQuizSet(long quizSetId) {
quizSetRepository.deleteById(quizSetId);
}
}