From ccc2b998dac1e9b268ffe3d969d741226e1f89a6 Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:24:52 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20reportSet=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/board/entity/vo/Board.java | 2 +- .../edufocus/quiz/entity/QuizSet.java | 2 +- .../registration/entity/Registration.java | 19 ++ .../repository/RegistrationRepository.java | 3 + .../report/controller/ReportController.java | 91 ++++------ .../report/entity/dto/AnswerInput.java | 12 -- .../edufocus/report/entity/dto/QuizDto.java | 6 - .../report/entity/dto/QuizSubmissionDto.java | 6 - .../entity/dto/ReportDetailResponseDto.java | 3 +- .../entity/dto/ReportListResponseDto.java | 17 -- ...{ReportRequset.java => ReportRequest.java} | 2 +- .../report/entity/dto/ReportResponse.java | 14 +- .../report/entity/dto/ReportSetResponse.java | 18 ++ .../edufocus/report/entity/vo/Answer.java | 1 - .../edufocus/report/entity/vo/Report.java | 30 +++- .../edufocus/report/entity/vo/ReportSet.java | 54 ++++++ .../report/repository/ReportRepository.java | 10 +- .../repository/ReportSetRepository.java | 13 ++ .../report/service/ReportService.java | 18 +- .../report/service/ReportServiceImpl.java | 168 ++++++++---------- .../user/model/service/UserService.java | 2 + .../user/model/service/UserServiceImpl.java | 6 +- .../ws/controller/ChatController.java | 29 +-- .../edufocus/ws/entity/dto/QuizDto.java | 3 + .../edufocus/ws/service/ChatService.java | 15 -- .../edufocus/ws/service/ChatServiceImpl.java | 83 --------- 26 files changed, 285 insertions(+), 342 deletions(-) delete mode 100644 backend/src/main/java/com/edufocus/edufocus/report/entity/dto/AnswerInput.java delete mode 100644 backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizSubmissionDto.java delete mode 100644 backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportListResponseDto.java rename backend/src/main/java/com/edufocus/edufocus/report/entity/dto/{ReportRequset.java => ReportRequest.java} (91%) create mode 100644 backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportSetResponse.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/report/repository/ReportSetRepository.java delete mode 100644 backend/src/main/java/com/edufocus/edufocus/ws/service/ChatService.java delete mode 100644 backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index e1e4ac6..c2a2519 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -55,7 +55,7 @@ public class Board { private Lecture lecture; - @OneToMany(mappedBy = "board") + @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) private List comments; public ResponseBoardSummaryDto makeSummaryDto(){ diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java index 90d13ac..557dc57 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/entity/QuizSet.java @@ -28,7 +28,7 @@ public class QuizSet { @Column private String title; - @OneToMany(mappedBy = "quizSet", orphanRemoval = true) + @OneToMany(mappedBy = "quizSet", orphanRemoval = true, fetch = FetchType.EAGER) @JsonManagedReference private List quizzes; diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java index 88af158..0b01d55 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java @@ -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(); + + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java index ef2c721..327893d 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java @@ -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 findAllNotAcceptedByLectureId(@Param("lectureId") Long lectureId); Registration findByUserIdAndLectureId(Long userId, Long lectureId); + + List findByLectureIdAndStatus(Long lectureId, RegistrationStatus status); } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java b/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java index 9c789bf..bc9b5f2 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/controller/ReportController.java @@ -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> myreport(HttpServletRequest request) throws SQLException { + @GetMapping("/student/{lectureId}") + public ResponseEntity> 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 reportResponses = reportService.findReports(lectureId, userId); - List 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 myreportdetail(@PathVariable("id") Long reportId) throws SQLException { - + @GetMapping("/reportDetail/{reportId}") + public ResponseEntity 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> studentreport(@PathVariable("lecturid") Long lectureId) throws SQLException { - - - List reportList = reportService.studentResultList(lectureId); - - return new ResponseEntity<>(reportList, HttpStatus.CREATED); - + @GetMapping("/teacher/reportSet/{lectureId}") + public ResponseEntity> searchReportSets(@PathVariable("lectureId") long lectureId){ + List reportSetResponses = reportService.findReportSets(lectureId); + + if(reportSetResponses.isEmpty()) + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + + return new ResponseEntity<>(reportSetResponses, HttpStatus.OK); } - - @GetMapping("/studentreportdetail/{id}") - public ResponseEntity studentdetailreport(@PathVariable("id") Long reportId) throws SQLException { - - ReportDetailResponseDto detailReport = reportService.reportDetail(reportId); - return new ResponseEntity<>(detailReport, HttpStatus.CREATED); - + + @GetMapping("/teacher/report/{reportSetId}") + public ResponseEntity searchReports(@PathVariable("reportSetId") UUID reportSetId){ + List reportResponses = reportService.findReports(reportSetId); + + if(reportResponses.isEmpty()) + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + + return new ResponseEntity<>(reportResponses, HttpStatus.OK); } - // 강좌에 대한 퀴즈셋 -// lecture id가 똑같은 report들 제목 + 작성자 + 맞틀 개수 미리 보여주기 -// @GetMapping("/detailreport/{id}") -// public ResponseEntity (@PathVariable("id") Long reportId) throws SQLException { -// -// ReportDetailResponseDto detailReport = reportService.reportDetail(reportId); -// return new ResponseEntity<>(detailReport, HttpStatus.CREATED); -// -// } v 9 - } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/AnswerInput.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/AnswerInput.java deleted file mode 100644 index b979e52..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/AnswerInput.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.edufocus.edufocus.report.entity.dto; - -import lombok.Getter; - -@Getter -public class AnswerInput { - - - String answer; - - -} diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java index 350e906..d73d6fb 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizDto.java @@ -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 choices; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizSubmissionDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizSubmissionDto.java deleted file mode 100644 index 24413b2..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/QuizSubmissionDto.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.edufocus.edufocus.report.entity.dto; - -public class QuizSubmissionDto { - private Long quizSetId; - private Long userId; -} diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java index a86b4e7..4dc0f76 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportDetailResponseDto.java @@ -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 correctQuizzes; private List incorrectQuizzes; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportListResponseDto.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportListResponseDto.java deleted file mode 100644 index 94fc3e2..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportListResponseDto.java +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequset.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequest.java similarity index 91% rename from backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequset.java rename to backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequest.java index 84e3e74..4f2c0bf 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequset.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportRequest.java @@ -7,7 +7,7 @@ import java.util.List; @Getter @Setter -public class ReportRequset { +public class ReportRequest { List answer; diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportResponse.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportResponse.java index 7d6a439..0740a0b 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportResponse.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportResponse.java @@ -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; } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportSetResponse.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportSetResponse.java new file mode 100644 index 0000000..ad300bf --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/dto/ReportSetResponse.java @@ -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; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java index 929adb0..53d0d35 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Answer.java @@ -28,5 +28,4 @@ public class Answer { @JoinColumn(name = "quiz_id") private Quiz quiz; - } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java index 1b81e78..dcc4b95 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/Report.java @@ -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 answers; + + public ReportResponse makeReportResponse(){ + return ReportResponse.builder() + .reportId(id) + .name(user.getName()) + .title(quizSet.getTitle()) + .allCount(allCount) + .correctCount(correctCount) + .date(testAt) + .build(); + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java new file mode 100644 index 0000000..2dedc12 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/report/entity/vo/ReportSet.java @@ -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 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(); + } +} diff --git a/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportRepository.java b/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportRepository.java index 66d2fb9..7665f28 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportRepository.java @@ -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 { - List findByUser_Id(Long userId); + List findByUserId(long userId); - List findByLectureId(Long lectureId); + List findByLectureId(long lectureId); + Report findByReportSetIdAndUserId(UUID reportSetId, long userId); + + List findByReportSetId(UUID reportSetId); + + List findByLectureIdAndUserId(long lectureId, long userId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportSetRepository.java b/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportSetRepository.java new file mode 100644 index 0000000..f1b484c --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/report/repository/ReportSetRepository.java @@ -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 { + List findByLectureId(long userId); +} diff --git a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportService.java b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportService.java index 7edcc4a..1e1b2b2 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportService.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportService.java @@ -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 resultList(Long userId) throws SQLException; + List findReportSets(long lectureId); - List studentResultList(Long lectureId) throws SQLException; + List findReports(UUID reportSetId); + + List findReports(long lectureId, long userid); + + UUID initReportSet(long lectureId, long quizSetId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java index 5543795..016bb34 100644 --- a/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/report/service/ReportServiceImpl.java @@ -1,123 +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 quizList = quizSet.getQuizzes(); - List answerInputList = reportRequset.getAnswer(); + ReportSet reportSet = reportSetRepository.findById(reportSetId).orElseThrow(NoSuchElementException::new); + + Report report = reportRepository.findByReportSetIdAndUserId(reportSetId, userId); + + List quizList = report.getQuizSet().getQuizzes(); + + List answerInputList = reportRequest.getAnswer(); List 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 correctQuiz = new ArrayList<>(); List incorrectQuiz = new ArrayList<>(); @@ -177,55 +150,54 @@ public class ReportServiceImpl implements ReportService { return dto; } - @Override - public List resultList(Long userId) throws SQLException { - - List reportList = reportRepository.findByUser_Id(userId); - - List 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 findReportSets(long lectureId) { + List reportSets = reportSetRepository.findByLectureId(lectureId); + return reportSets.stream() + .map(ReportSet::makeReportSetResponse) + .toList(); } @Override - public List studentResultList(Long lectureId) throws SQLException { + public List findReports(UUID reportSetId) { + List reports = reportRepository.findByReportSetId(reportSetId); - List reportList = reportRepository.findByLectureId(lectureId); + return reports.stream() + .map(Report::makeReportResponse) + .toList(); + } - List reportListResponseDtoList = new ArrayList<>(); + @Override + public List findReports(long lectureId, long userId) { + List 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 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 reports = registrations.stream() + .filter(Registration::isAccepted) + .map((Registration registration)-> registration.makeReport(reportSet, quizSet, lectureId)) + .toList(); + + reportRepository.saveAll(reports); + + return reportSet.getId(); } } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java index 0737045..481c0de 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java @@ -29,4 +29,6 @@ public interface UserService { boolean isEmailExist(String email); void changeForgottenPassword(Long id, String newPassword); + + boolean isTeacher(long id); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index c50e1c9..b4d20da 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -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; @@ -155,5 +156,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; + } } diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/controller/ChatController.java b/backend/src/main/java/com/edufocus/edufocus/ws/controller/ChatController.java index dbf5d8e..4e280b9 100644 --- a/backend/src/main/java/com/edufocus/edufocus/ws/controller/ChatController.java +++ b/backend/src/main/java/com/edufocus/edufocus/ws/controller/ChatController.java @@ -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); diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/entity/dto/QuizDto.java b/backend/src/main/java/com/edufocus/edufocus/ws/entity/dto/QuizDto.java index bd97f35..2d91954 100644 --- a/backend/src/main/java/com/edufocus/edufocus/ws/entity/dto/QuizDto.java +++ b/backend/src/main/java/com/edufocus/edufocus/ws/entity/dto/QuizDto.java @@ -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; } diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatService.java b/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatService.java deleted file mode 100644 index 5399bb9..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatService.java +++ /dev/null @@ -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 findChatUsers(long lectureId); - public boolean checkTeacher(ChatUserDto chatUser); - public void closeChatRoom(long chatRoomId); - public void deleteChatUserInfo(long userId); -} diff --git a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java deleted file mode 100644 index 29071cf..0000000 --- a/backend/src/main/java/com/edufocus/edufocus/ws/service/ChatServiceImpl.java +++ /dev/null @@ -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 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); - } -} From 918906de60b4b058c1b7f64e577455d52097a4af Mon Sep 17 00:00:00 2001 From: yulmam <70622601+yulmam@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:47:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=B5=9C=EC=8B=A0=EC=88=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/edufocus/board/controller/BoardController.java | 2 +- .../com/edufocus/edufocus/board/service/BoardServiceImpl.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java index 309acb6..87e5410 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/controller/BoardController.java @@ -38,7 +38,7 @@ public class BoardController { List 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); } diff --git a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java index 3fc7250..a357de2 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/service/BoardServiceImpl.java @@ -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 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 boards = boardRepository.findByLectureIdAndCategory(lectureId, category, pageable).getContent();