feat: qna

This commit is contained in:
박정민 2024-08-09 10:23:10 +09:00
commit 3442e9b91e
11 changed files with 59 additions and 17 deletions

View File

@ -34,15 +34,17 @@ public class Board {
@Column(nullable = false)
private String category;
@Column(nullable = false)
@Column(columnDefinition = "TEXT", nullable = false)
private String content;
@Column(nullable = true)
private int viewCount;
@Column(columnDefinition = "TIMESTAMP")
@CreatedDate
LocalDateTime createdAt;
@Column(columnDefinition = "TIMESTAMP")
@LastModifiedDate
LocalDateTime modifiedAt;

View File

@ -9,6 +9,8 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import java.time.LocalDateTime;
@ -22,13 +24,16 @@ public class Comment {
@Id
@GeneratedValue
private long id;
@Column
@Column(columnDefinition = "TEXT", nullable = false)
private String content;
@Column
@Column(columnDefinition = "TIMESTAMP")
@CreatedDate
private LocalDateTime createdAt;
@Column
@Column(columnDefinition = "TIMESTAMP")
@LastModifiedDate
private LocalDateTime modifiedAt;
@ManyToOne

View File

@ -27,10 +27,10 @@ public class Lecture {
@Column
private String title;
@Lob
@Column(columnDefinition = "text")
private String description;
@Lob
@Column(columnDefinition = "text")
private String plan;
@Column

View File

@ -36,7 +36,7 @@ public class RegistrationController {
}
@PutMapping("/{registrationId}")
public ResponseEntity<?> acceptRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
public ResponseEntity<?> acceptRegistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
if (!registrationService.acceptRegistration(userId, registrationId)) {
@ -47,7 +47,7 @@ public class RegistrationController {
}
@DeleteMapping("/{registrationId}")
public ResponseEntity<?> deleteRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
public ResponseEntity<?> deleteRegistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
if (!registrationService.deleteRegistration(userId, registrationId)) {

View File

@ -63,7 +63,10 @@ public class ReportController {
return new ResponseEntity<>(detailReport, HttpStatus.OK);
}
<<<<<<< HEAD
=======
>>>>>>> 935331e7e93d9c25ec6f32ba6155ed19b5fd60f9
@GetMapping("/teacher/reportSet/{lectureId}")
public ResponseEntity<List<ReportSetResponse>> searchReportSets(@PathVariable("lectureId") long lectureId) {
List<ReportSetResponse> reportSetResponses = reportService.findReportSets(lectureId);
@ -84,4 +87,13 @@ public class ReportController {
return new ResponseEntity<>(reportResponses, HttpStatus.OK);
}
@DeleteMapping("/teacher/report/{reportSetId}")
public ResponseEntity<?> deleteReportSet(@PathVariable("reportSetId") UUID reportSetId, HttpServletRequest request){
String token = request.getHeader("Authorization");
long userId = Long.parseLong(jwtUtil.getUserId(token));
reportService.deleteReportSet(reportSetId, userId);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -18,6 +18,6 @@ public class QuizDto {
private String image;
private String answer;
private String userAnswer;
private boolean isCollect;
private boolean isCorrect;
private List<ChoiceDto> choices;
}

View File

@ -1,14 +1,14 @@
package com.edufocus.edufocus.report.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.*;
import java.time.LocalDateTime;
import java.util.UUID;
@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ReportSetResponse {

View File

@ -3,9 +3,11 @@ 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 com.fasterxml.jackson.annotation.JsonAutoDetect;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;
import java.util.Date;
@ -17,6 +19,8 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class Report {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -26,6 +30,7 @@ public class Report {
private int correctCount;
@Column(columnDefinition = "TIMESTAMP")
@CreatedDate
private LocalDateTime testAt;

View File

@ -3,11 +3,13 @@ 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 com.fasterxml.jackson.annotation.JsonAutoDetect;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;
@ -21,6 +23,8 @@ import java.util.UUID;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class ReportSet {
@Id
@GeneratedValue(generator = "UUID")
@ -30,6 +34,7 @@ public class ReportSet {
)
private UUID id;
@Column(columnDefinition = "TIMESTAMP")
@CreatedDate
private LocalDateTime createAt;
@ -51,4 +56,8 @@ public class ReportSet {
.testAt(createAt)
.build();
}
public long findUserId(){
return lecture.getUser().getId();
}
}

View File

@ -20,4 +20,6 @@ public interface ReportService {
List<ReportResponse> findReports(long lectureId, long userid);
UUID initReportSet(long lectureId, long quizSetId);
void deleteReportSet(UUID reportSetId, long userId);
}

View File

@ -54,17 +54,17 @@ public class ReportServiceImpl implements ReportService {
for (int idx = 0; idx < answerInputList.size(); idx++) {
Quiz quiz = quizList.get(idx);
String inputAnswer = answerInputList.get(idx);
boolean isCollect;
boolean isCorrect;
Answer answer;
if (quiz.getAnswer().equals(inputAnswer)) {
correctCount++;
isCollect = true;
isCorrect = true;
} else {
isCollect = false;
isCorrect = false;
}
answer = Answer.builder()
.userAnswer(inputAnswer)
.isCorrect(isCollect)
.isCorrect(isCorrect)
.report(report)
.quiz(quiz)
.build();
@ -106,7 +106,7 @@ public class ReportServiceImpl implements ReportService {
.question(quiz.getQuestion())
.answer(quiz.getAnswer())
.userAnswer(answer.getUserAnswer())
.isCollect(answer.isCorrect())
.isCorrect(answer.isCorrect())
.choices(choiceDtos)
.build();
@ -172,4 +172,11 @@ public class ReportServiceImpl implements ReportService {
return reportSet.getId();
}
@Override
public void deleteReportSet(UUID reportSetId, long userId) {
ReportSet reportSet = reportSetRepository.findById(reportSetId).orElseThrow(NoSuchElementException::new);
if(reportSet.findUserId() == userId)
reportSetRepository.delete(reportSet);
}
}