merge backend

This commit is contained in:
kgc91747 2024-08-08 10:17:22 +09:00
commit b73b2b7920
27 changed files with 286 additions and 343 deletions

View File

@ -38,7 +38,7 @@ public class BoardController {
List<ResponseBoardSummaryDto> boardSummaries = boardService.findBoards(pageNo, category, lectureId);
if(boardSummaries.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(boardSummaries, HttpStatus.NO_CONTENT);
return new ResponseEntity<>(boardSummaries, HttpStatus.OK);
}

View File

@ -55,7 +55,7 @@ public class Board {
private Lecture lecture;
@OneToMany(mappedBy = "board")
@OneToMany(mappedBy = "board", cascade = CascadeType.ALL)
private List<Comment> comments;
public ResponseBoardSummaryDto makeSummaryDto(){

View File

@ -12,6 +12,7 @@ import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -39,7 +40,7 @@ public class BoardServiceImpl implements BoardService {
@Transactional
public List<ResponseBoardSummaryDto> findBoards(int pageNo, String category, long lectureId) {
Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE);
Pageable pageable = PageRequest.of(pageNo, PAGE_SIZE, Sort.by("created_at").descending());
List<Board> boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent();

View File

@ -1,10 +1,15 @@
package com.edufocus.edufocus.registration.entity;
import com.edufocus.edufocus.lecture.entity.Lecture;
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.report.entity.vo.Report;
import com.edufocus.edufocus.report.entity.vo.ReportSet;
import com.edufocus.edufocus.user.model.entity.vo.User;
import jakarta.persistence.*;
import lombok.*;
import java.util.UUID;
@Entity
@Getter
@Setter
@ -27,4 +32,18 @@ public class Registration {
@Enumerated(EnumType.STRING)
private RegistrationStatus status;
public boolean isAccepted(){
return status == RegistrationStatus.ACCEPTED;
}
public Report makeReport(ReportSet reportSet, QuizSet quizSet, long lectureId){
return Report.builder()
.allCount(0)
.correctCount(-1)
.lectureId(lectureId)
.user(user)
.build();
}
}

View File

@ -1,6 +1,7 @@
package com.edufocus.edufocus.registration.repository;
import com.edufocus.edufocus.registration.entity.Registration;
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@ -16,4 +17,6 @@ public interface RegistrationRepository extends JpaRepository<Registration, Long
List<Registration> findAllNotAcceptedByLectureId(@Param("lectureId") Long lectureId);
Registration findByUserIdAndLectureId(Long userId, Long lectureId);
List<Registration> findByLectureIdAndStatus(Long lectureId, RegistrationStatus status);
}

View File

@ -1,19 +1,10 @@
package com.edufocus.edufocus.report.controller;
import com.edufocus.edufocus.report.entity.dto.ReportDetailResponseDto;
import com.edufocus.edufocus.report.entity.dto.ReportListResponseDto;
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
import com.edufocus.edufocus.report.entity.vo.Report;
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
import com.edufocus.edufocus.report.entity.dto.*;
import com.edufocus.edufocus.report.service.ReportService;
import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.entity.vo.UserRole;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import com.edufocus.edufocus.user.model.service.UserService;
import com.edufocus.edufocus.user.model.service.UserServiceImpl;
import com.edufocus.edufocus.user.util.JWTUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@ -21,8 +12,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("/report")
@ -34,73 +25,61 @@ public class ReportController {
private final ReportService reportService;
private final JWTUtil jwtUtil;
private final UserService userService;
private final UserRepository userRepository;
//SUBMIT 할떄 LECTURE ID 저장해놓기
@PostMapping("/submit/{lectreId}/quizset/{quizsetId}")
public ResponseEntity<?> submit(@PathVariable("lectreId") Long lectureId, @PathVariable("quizsetId") Long quizestId, @RequestBody ReportRequset reportRequset, HttpServletRequest request) throws SQLException {
@PostMapping("/submit/quizSet/{reportSetId}")
public ResponseEntity<?> submit(@PathVariable("reportSetId") UUID reportSetId, @RequestBody ReportRequest reportRequest, HttpServletRequest request) {
String token = request.getHeader("Authorization");
Long userId = Long.parseLong(jwtUtil.getUserId(token));
User findUser = userRepository.findById(userId).orElse(null);
if (findUser.getRole() == UserRole.ADMIN) {
long userId = Long.parseLong(jwtUtil.getUserId(token));
if (userService.isTeacher(userId))
return new ResponseEntity<>("강사는 퀴즈제출을 할수 없습니다", HttpStatus.FORBIDDEN);
}
ReportResponse report = reportService.grading(userId, quizestId, reportRequset, lectureId);
reportService.grade(userId, reportSetId, reportRequest);
return new ResponseEntity<>(report, HttpStatus.CREATED);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping("/myreport")
public ResponseEntity<List<ReportListResponseDto>> myreport(HttpServletRequest request) throws SQLException {
@GetMapping("/student/{lectureId}")
public ResponseEntity<List<ReportResponse>> searchMyReport(@PathVariable long lectureId, HttpServletRequest request) {
String token = request.getHeader("Authorization");
Long userId = Long.parseLong(jwtUtil.getUserId(token));
long userId = Long.parseLong(jwtUtil.getUserId(token));
List<ReportResponse> reportResponses = reportService.findReports(lectureId, userId);
List<ReportListResponseDto> reportList = reportService.resultList(userId);
return new ResponseEntity<>(reportList, HttpStatus.CREATED);
if(reportResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
}
@GetMapping("/myreportdetail/{id}")
public ResponseEntity<ReportDetailResponseDto> myreportdetail(@PathVariable("id") Long reportId) throws SQLException {
@GetMapping("/reportDetail/{reportId}")
public ResponseEntity<ReportDetailResponseDto> searchDetailReport(@PathVariable("reportId") long reportId){
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
return new ResponseEntity<>(detailReport, HttpStatus.CREATED);
return new ResponseEntity<>(detailReport, HttpStatus.OK);
}
@GetMapping("/studentreport/{lecturid}")
public ResponseEntity<List<ReportListResponseDto>> studentreport(@PathVariable("lecturid") Long lectureId) throws SQLException {
@GetMapping("/teacher/reportSet/{lectureId}")
public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId){
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);
if(reportSetResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
List<ReportListResponseDto> reportList = reportService.studentResultList(lectureId);
return new ResponseEntity<>(reportList, HttpStatus.CREATED);
return new ResponseEntity<>(reportSetResponses, HttpStatus.OK);
}
@GetMapping("/studentreportdetail/{id}")
public ResponseEntity<ReportDetailResponseDto> studentdetailreport(@PathVariable("id") Long reportId) throws SQLException {
@GetMapping("/teacher/report/{reportSetId}")
public ResponseEntity<?> searchReports(@PathVariable("reportSetId") UUID reportSetId){
List<ReportResponse> reportResponses = reportService.findReports(reportSetId);
ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
return new ResponseEntity<>(detailReport, HttpStatus.CREATED);
if(reportResponses.isEmpty())
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
}
// 강좌에 대한 퀴즈셋
// lecture id가 똑같은 report들 제목 + 작성자 + 맞틀 개수 미리 보여주기
// @GetMapping("/detailreport/{id}")
// public ResponseEntity<ReportDetailResponseDto> (@PathVariable("id") Long reportId) throws SQLException {
//
// ReportDetailResponseDto detailReport = reportService.reportDetail(reportId);
// return new ResponseEntity<>(detailReport, HttpStatus.CREATED);
//
// } v 9
}

View File

@ -1,12 +0,0 @@
package com.edufocus.edufocus.report.entity.dto;
import lombok.Getter;
@Getter
public class AnswerInput {
String answer;
}

View File

@ -13,15 +13,9 @@ import java.util.List;
@Data
@Builder
public class QuizDto {
private long id;
private String question;
private String image;
private String answer;
private String userAnswer;
private List<ChoiceDto> choices;

View File

@ -1,6 +0,0 @@
package com.edufocus.edufocus.report.entity.dto;
public class QuizSubmissionDto {
private Long quizSetId;
private Long userId;
}

View File

@ -4,6 +4,7 @@ import com.edufocus.edufocus.quiz.entity.Quiz;
import lombok.Builder;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@ -13,7 +14,7 @@ public class ReportDetailResponseDto {
private int allCount;
private String title;
private int correctCount;
private Date testAt;
private LocalDateTime testAt;
private List<QuizDto> correctQuizzes;
private List<QuizDto> incorrectQuizzes;

View File

@ -1,17 +0,0 @@
package com.edufocus.edufocus.report.entity.dto;
import lombok.Builder;
import lombok.Data;
import java.util.Date;
@Data
@Builder
public class ReportListResponseDto {
private String title;
private Date date;
private Long reportId;
private String name;
private int allCount;
private int correctCount;
}

View File

@ -7,7 +7,7 @@ import java.util.List;
@Getter
@Setter
public class ReportRequset {
public class ReportRequest {
List<String> answer;

View File

@ -1,26 +1,20 @@
package com.edufocus.edufocus.report.entity.dto;
import com.edufocus.edufocus.report.entity.vo.Answer;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Getter
@Setter
@Builder
public class ReportResponse {
private Long quizesetId;
private Long userId;
private long reportId;
private String name;
private String title;
private int allCount;
private int correctCount;
private Date testAt;
private LocalDateTime date;
}

View File

@ -0,0 +1,18 @@
package com.edufocus.edufocus.report.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.UUID;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReportSetResponse {
private UUID reportSetId;
private String quizSetTitle;
private LocalDateTime testAt;
}

View File

@ -28,5 +28,4 @@ public class Answer {
@JoinColumn(name = "quiz_id")
private Quiz quiz;
}

View File

@ -1,11 +1,15 @@
package com.edufocus.edufocus.report.entity.vo;
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
import com.edufocus.edufocus.user.model.entity.vo.User;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Entity
@Getter
@ -14,16 +18,19 @@ import java.util.Date;
@AllArgsConstructor
@Builder
public class Report {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int allCount;
private int correctCount;
private Date testAt;
@CreatedDate
private LocalDateTime testAt;
private Long lectureId;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@ -32,4 +39,21 @@ public class Report {
@JoinColumn(name = "quizset_id")
private QuizSet quizSet;
@ManyToOne
@JoinColumn(name = "reportset_id")
private ReportSet reportSet;
@OneToMany(mappedBy = "report", cascade = CascadeType.ALL)
private List<Answer> answers;
public ReportResponse makeReportResponse(){
return ReportResponse.builder()
.reportId(id)
.name(user.getName())
.title(quizSet.getTitle())
.allCount(allCount)
.correctCount(correctCount)
.date(testAt)
.build();
}
}

View File

@ -0,0 +1,54 @@
package com.edufocus.edufocus.report.entity.vo;
import com.edufocus.edufocus.lecture.entity.Lecture;
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.report.entity.dto.ReportSetResponse;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReportSet {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
private UUID id;
@CreatedDate
private LocalDateTime createAt;
@OneToMany(mappedBy = "reportSet", cascade = CascadeType.ALL)
private List<Report> reports;
@ManyToOne
@JoinColumn(name = "lecture_id")
private Lecture lecture;
@ManyToOne
@JoinColumn(name = "quizSet_id")
private QuizSet quizSet;
public ReportSetResponse makeReportSetResponse() {
return ReportSetResponse.builder()
.reportSetId(id)
.quizSetTitle(quizSet.getTitle())
.testAt(createAt)
.build();
}
}

View File

@ -5,11 +5,17 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
public interface ReportRepository extends JpaRepository<Report, Long> {
List<Report> findByUser_Id(Long userId);
List<Report> findByUserId(long userId);
List<Report> findByLectureId(Long lectureId);
List<Report> findByLectureId(long lectureId);
Report findByReportSetIdAndUserId(UUID reportSetId, long userId);
List<Report> findByReportSetId(UUID reportSetId);
List<Report> findByLectureIdAndUserId(long lectureId, long userId);
}

View File

@ -0,0 +1,13 @@
package com.edufocus.edufocus.report.repository;
import com.edufocus.edufocus.report.entity.vo.ReportSet;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
public interface ReportSetRepository extends JpaRepository<ReportSet, UUID> {
List<ReportSet> findByLectureId(long userId);
}

View File

@ -1,21 +1,23 @@
package com.edufocus.edufocus.report.service;
import com.edufocus.edufocus.report.entity.dto.ReportDetailResponseDto;
import com.edufocus.edufocus.report.entity.dto.ReportListResponseDto;
import com.edufocus.edufocus.report.entity.dto.ReportResponse;
import com.edufocus.edufocus.report.entity.dto.ReportRequset;
import com.edufocus.edufocus.report.entity.dto.*;
import org.springframework.stereotype.Service;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
@Service
public interface ReportService {
ReportResponse grading(Long userId, Long quizesetId, ReportRequset reportRequset, Long lectureId) throws SQLException;
void grade(long userId, UUID reportSetId, ReportRequest reportRequest);
ReportDetailResponseDto reportDetail(Long userId) throws SQLException;
ReportDetailResponseDto reportDetail(long userId);
List<ReportListResponseDto> resultList(Long userId) throws SQLException;
List<ReportSetResponse> findReportSets(long lectureId);
List<ReportListResponseDto> studentResultList(Long lectureId) throws SQLException;
List<ReportResponse> findReports(UUID reportSetId);
List<ReportResponse> findReports(long lectureId, long userid);
UUID initReportSet(long lectureId, long quizSetId);
}

View File

@ -1,122 +1,96 @@
package com.edufocus.edufocus.report.service;
import com.edufocus.edufocus.lecture.repository.LectureRepository;
import com.edufocus.edufocus.quiz.entity.Choice;
import com.edufocus.edufocus.quiz.entity.Quiz;
import com.edufocus.edufocus.quiz.entity.QuizSet;
import com.edufocus.edufocus.quiz.repository.QuizRepository;
import com.edufocus.edufocus.quiz.repository.QuizSetRepository;
import com.edufocus.edufocus.quiz.service.QuizService;
import com.edufocus.edufocus.quiz.service.QuizSetService;
import com.edufocus.edufocus.registration.entity.Registration;
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
import com.edufocus.edufocus.registration.repository.RegistrationRepository;
import com.edufocus.edufocus.report.entity.dto.*;
import com.edufocus.edufocus.report.entity.vo.Answer;
import com.edufocus.edufocus.report.entity.vo.Report;
import com.edufocus.edufocus.report.entity.vo.ReportSet;
import com.edufocus.edufocus.report.repository.AnswerRepository;
import com.edufocus.edufocus.report.repository.ReportRepository;
import com.edufocus.edufocus.report.repository.ReportSetRepository;
import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Service;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
@Service
@Transactional
@RequiredArgsConstructor
public class ReportServiceImpl implements ReportService {
private final QuizSetService quizSetService;
private final QuizService quizService;
private final ReportRepository reportRepository;
private final QuizRepository quizRepository;
private final RegistrationRepository registrationRepository;
private final AnswerRepository answerRepository;
private final AnswerService answerService;
private final UserRepository userRepository;
private final ReportSetRepository reportSetRepository;
private final LectureRepository lectureRepository;
private final QuizSetRepository quizSetRepository;
@Override
public ReportResponse grading(Long userId, Long quizsetId, ReportRequset reportRequset, Long lectureId) throws SQLException {
public void grade(long userId, UUID reportSetId, ReportRequest reportRequest){
QuizSet quizSet = quizSetService.findQuizSet(quizsetId);
List<Quiz> quizList = quizSet.getQuizzes();
List<String> answerInputList = reportRequset.getAnswer();
ReportSet reportSet = reportSetRepository.findById(reportSetId).orElseThrow(NoSuchElementException::new);
Report report = reportRepository.findByReportSetIdAndUserId(reportSetId, userId);
List<Quiz> quizList = report.getQuizSet().getQuizzes();
List<String> answerInputList = reportRequest.getAnswer();
List<Answer> answerList = new ArrayList<>();
int allCount = quizList.size();
int correctCount = 0;
User testuser = userRepository.findById(userId).orElse(null);
for (int idx = 0; idx < answerInputList.size(); idx++) {
Quiz quiz = quizList.get(idx);
String inputAnswer = answerInputList.get(idx);
boolean isCollect;
Answer answer;
if (quiz.getAnswer().equals(inputAnswer)) {
correctCount++;
answer = Answer.builder()
.userAnswer(inputAnswer)
.isCorrect(true)
.report(null)
.quiz(quiz)
.build();
isCollect = true;
} else {
answer = Answer.builder()
.userAnswer(inputAnswer)
.isCorrect(false)
.report(null)
.quiz(quiz)
.build();
isCollect = false;
}
answer = Answer.builder()
.userAnswer(inputAnswer)
.isCorrect(isCollect)
.report(report)
.quiz(quiz)
.build();
answerList.add(answer);
}
Report report = Report.builder()
.user(testuser)
.quizSet(quizSet)
.allCount(allCount)
.correctCount(correctCount)
.testAt(new Date())
.lectureId(lectureId)
.build();
report.setAllCount(quizList.size());
report.setCorrectCount(correctCount);
report.setReportSet(reportSet);
reportRepository.save(report);
for (Answer answer : answerList) {
answer.setReport(report);
answerRepository.save(answer);
}
ReportResponse reportResponse = ReportResponse.builder()
.quizesetId(quizSet.getId())
.userId(testuser.getId())
.title(quizSet.getTitle())
.allCount(allCount)
.correctCount(correctCount)
.testAt(new Date())
.build();
return reportResponse;
answerRepository.saveAll(answerList);
}
@Override
public ReportDetailResponseDto reportDetail(Long repordId) {
public ReportDetailResponseDto reportDetail(long reportId) {
Report report = reportRepository.findById(repordId).orElse(null);
Report report = reportRepository.findById(reportId).orElseThrow(NoSuchElementException::new);
QuizSet quizSet = quizSetService.findQuizSet(report.getQuizSet().getId());
QuizSet quizSet = quizSetRepository.findById(report.getQuizSet().getId()).orElseThrow(NoSuchElementException::new);
List<QuizDto> correctQuiz = new ArrayList<>();
List<QuizDto> incorrectQuiz = new ArrayList<>();
@ -176,56 +150,54 @@ public class ReportServiceImpl implements ReportService {
return dto;
}
@Override
public List<ReportListResponseDto> resultList(Long userId) throws SQLException {
List<Report> reportList = reportRepository.findByUser_Id(userId);
List<ReportListResponseDto> reportListResponseDtoList = new ArrayList<>();
for (Report report : reportList) {
QuizSet quizSet = quizSetService.findQuizSet(report.getQuizSet().getId());
ReportListResponseDto dto = ReportListResponseDto.builder()
.title(quizSet.getTitle()) // Assuming QuizSet has a method getTitle()
.date(report.getTestAt())
.reportId(report.getId())// Assuming QuizSet has a method getDate()
.build();
reportListResponseDtoList.add(dto);
}
return reportListResponseDtoList;
public List<ReportSetResponse> findReportSets(long lectureId) {
List<ReportSet> reportSets = reportSetRepository.findByLectureId(lectureId);
return reportSets.stream()
.map(ReportSet::makeReportSetResponse)
.toList();
}
@Override
public List<ReportListResponseDto> studentResultList(Long lectureId) throws SQLException {
public List<ReportResponse> findReports(UUID reportSetId) {
List<Report> reports = reportRepository.findByReportSetId(reportSetId);
List<Report> reportList = reportRepository.findByLectureId(lectureId);
return reports.stream()
.map(Report::makeReportResponse)
.toList();
}
List<ReportListResponseDto> reportListResponseDtoList = new ArrayList<>();
@Override
public List<ReportResponse> findReports(long lectureId, long userId) {
List<Report> reports = reportRepository.findByLectureIdAndUserId(lectureId, userId);
return reports.stream()
.map(Report::makeReportResponse)
.toList();
}
for (Report report : reportList) {
@Override
public UUID initReportSet(long lectureId, long quizSetId) {
List<Registration> registrations = registrationRepository.findByLectureIdAndStatus(lectureId, RegistrationStatus.ACCEPTED);
System.out.println(report.toString());
QuizSet quizSet = quizSetService.findQuizSet(report.getQuizSet().getId());
ReportListResponseDto dto = ReportListResponseDto.builder()
.title(quizSet.getTitle())
.date(report.getTestAt())
.reportId(report.getId())
.allCount(report.getAllCount())
.correctCount(report.getCorrectCount())
.build();
reportListResponseDtoList.add(dto);
ReportSet reportSet = ReportSet.builder()
.lecture(lectureRepository.getReferenceById(lectureId))
.quizSet(quizSetRepository.getReferenceById(quizSetId))
.build();
}
reportSetRepository.save(reportSet);
return reportListResponseDtoList;
QuizSet quizSet = quizSetRepository.getReferenceById(quizSetId);
List<Report> reports = registrations.stream()
.filter(Registration::isAccepted)
.map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId))
.toList();
reportRepository.saveAll(reports);
return reportSet.getId();
}
}

View File

@ -28,5 +28,6 @@ public interface UserService {
boolean isEmailExist(String email);
void changeForgottenPassword(String email, String newPassword);
}

View File

@ -5,6 +5,7 @@ import com.edufocus.edufocus.user.model.entity.dto.InfoDto;
import com.edufocus.edufocus.user.model.entity.dto.PasswordDto;
import com.edufocus.edufocus.user.model.entity.dto.RequestJoinDto;
import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.entity.vo.UserRole;
import com.edufocus.edufocus.user.model.exception.UserException;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import com.edufocus.edufocus.user.util.PasswordUtils;
@ -157,5 +158,8 @@ public class UserServiceImpl implements UserService {
userRepository.save(user);
}
@Override
public boolean isTeacher(long id){
return userRepository.findById(id).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
}
}

View File

@ -2,40 +2,25 @@ package com.edufocus.edufocus.ws.controller;
import com.edufocus.edufocus.global.constant.RabbitMQConstant;
import com.edufocus.edufocus.user.util.JWTUtil;
import com.edufocus.edufocus.report.service.ReportService;
import com.edufocus.edufocus.ws.entity.dto.MessageDto;
import com.edufocus.edufocus.ws.entity.dto.QuizDto;
import com.edufocus.edufocus.ws.entity.dto.ChatUserDto;
import com.edufocus.edufocus.ws.service.ChatService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.messaging.SessionConnectedEvent;
import org.springframework.web.socket.messaging.SessionDisconnectEvent;
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
import org.springframework.web.socket.messaging.SessionUnsubscribeEvent;
import java.util.List;
import java.util.UUID;
@RestController
public class ChatController {
RabbitTemplate rabbitTemplate;
ReportService reportService;
public ChatController(RabbitTemplate rabbitTemplate){
public ChatController(RabbitTemplate rabbitTemplate, ReportService reportService){
this.rabbitTemplate = rabbitTemplate;
this.reportService = reportService;
}
@MessageMapping("chat.message.{lectureId}")
@ -47,6 +32,10 @@ public class ChatController {
@MessageMapping("chat.quiz.{lectureId}")
public void quizStart(@DestinationVariable long lectureId, QuizDto quizDto){
UUID reportSetId = reportService.initReportSet(lectureId, quizDto.getQuizSetId());
quizDto.setReportSetId(reportSetId);
rabbitTemplate.convertAndSend(RabbitMQConstant.CHAT_EXCHANGE.getConstant(),
RabbitMQConstant.ROUTING_KEY_PREFIX.getConstant() + lectureId,
quizDto);

View File

@ -4,9 +4,12 @@ package com.edufocus.edufocus.ws.entity.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.UUID;
@Getter
@Setter
public class QuizDto {
long userId;
long quizSetId;
UUID ReportSetId;
}

View File

@ -1,15 +0,0 @@
package com.edufocus.edufocus.ws.service;
import com.edufocus.edufocus.ws.entity.dto.ChatUserDto;
import java.util.List;
public interface ChatService {
public void saveChatUserInfo(long userId, long channelId, String sessionId);
public ChatUserDto getChatUserInfo(long userId);
public ChatUserDto getChatUserInfo(String sessionId);
public List<ChatUserDto> findChatUsers(long lectureId);
public boolean checkTeacher(ChatUserDto chatUser);
public void closeChatRoom(long chatRoomId);
public void deleteChatUserInfo(long userId);
}

View File

@ -1,83 +0,0 @@
package com.edufocus.edufocus.ws.service;
import com.edufocus.edufocus.lecture.entity.Lecture;
import com.edufocus.edufocus.lecture.repository.LectureRepository;
import com.edufocus.edufocus.user.model.entity.vo.User;
import com.edufocus.edufocus.user.model.repository.UserRepository;
import com.edufocus.edufocus.ws.entity.dto.ChatUserDto;
import com.edufocus.edufocus.ws.entity.vo.ChatUser;
import com.edufocus.edufocus.ws.repository.ChatUserRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ChatServiceImpl implements ChatService{
private final ChatUserRepository chatUserRepository;
private final UserRepository userRepository;
private final LectureRepository lectureRepository;
public ChatServiceImpl(ChatUserRepository chatUserRepository, UserRepository userRepository, LectureRepository lectureRepository) {
this.chatUserRepository = chatUserRepository;
this.userRepository = userRepository;
this.lectureRepository = lectureRepository;
}
@Override
public void saveChatUserInfo(long userId, long lectureId, String sessionId) {
User user = userRepository.getReferenceById(userId);
Lecture lecture = lectureRepository.getReferenceById(lectureId);
ChatUser chatUser = ChatUser.builder()
.user(user)
.lecture(lecture)
.sessionId(sessionId)
.build();
chatUserRepository.save(chatUser);
}
@Override
public ChatUserDto getChatUserInfo(long userId) {
ChatUser chatUser = chatUserRepository.findById(userId).orElseThrow(IllegalArgumentException::new);
return chatUser.makeChatUserDto();
}
@Override
public ChatUserDto getChatUserInfo(String sessionId) {
ChatUser chatUser = chatUserRepository.findBySessionId(sessionId);
return chatUser.makeChatUserDto();
}
@Override
public List<ChatUserDto> findChatUsers(long lectureId) {
return chatUserRepository.findByLectureId(lectureId)
.stream()
.map(ChatUser::makeChatUserDto)
.collect(Collectors.toList());
}
@Override
public boolean checkTeacher(ChatUserDto chatUser) {
Lecture lecture = lectureRepository.findByIdAndUserId(chatUser.getLectureId(), chatUser.getUserId());
return lecture != null;
}
@Override
public void closeChatRoom(long lectureId) {
chatUserRepository.deleteByLectureId(lectureId);
}
@Override
public void deleteChatUserInfo(long userId) {
ChatUser chatUser = chatUserRepository.getReferenceById(userId);
chatUserRepository.delete(chatUser);
}
}