Skip to content

Commit

Permalink
Merge pull request #114 from AnataAria/vinh
Browse files Browse the repository at this point in the history
vinh/add mark score for instructor method api
  • Loading branch information
PoserDungeon2003 authored Nov 7, 2023
2 parents 92cd69e + f7fd82f commit fc1c91c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.group1.drawingcouseselling.model.dto.ExamDetailInfoDto;
import com.group1.drawingcouseselling.model.dto.ExamDto;
import com.group1.drawingcouseselling.model.dto.ExamMarkDto;
import com.group1.drawingcouseselling.service.ExamService;
import com.group1.drawingcouseselling.service.JwtService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

Expand Down Expand Up @@ -39,4 +37,12 @@ public ResponseEntity<Page<ExamDto>> getExamsSubmittedListOnPaging(@RequestHeade
public ResponseEntity<ExamDetailInfoDto> getExamDetailInformation(BigDecimal examID){
return ResponseEntity.ok(examService.getExamInfoDetail(examID));
}

@PostMapping("/exam/mark")
public ResponseEntity<ExamDto> markExam(@RequestHeader("Authorization") String authorization,
@RequestBody ExamMarkDto examMark
){
String instructorEmail = jwtService.extractUserEmail(authorization.substring(7));
return ResponseEntity.ok(examService.assignScoreSubmit(instructorEmail,examMark));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ public class Exam {
@PreUpdate
private void updateScoreStatus(){
if(score != null){
courseContentCompletion.setDone(switch (score) {
case 'A', 'B', 'C' -> true;
default -> false;
});
switch (score) {
case 'A', 'B', 'C':
courseContentCompletion.setDone(true);
submitStatus = EExamStatus.PASSED;
break;
default:
submitStatus = EExamStatus.FAILED;
courseContentCompletion.setDone(false);
break;
}

}else {
courseContentCompletion.setDone(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import com.group1.drawingcouseselling.model.dto.ExamMarkDto;
import com.group1.drawingcouseselling.model.entity.Course;
import com.group1.drawingcouseselling.model.entity.CourseContent;
import com.group1.drawingcouseselling.model.entity.CourseContentCompletion;
import com.group1.drawingcouseselling.model.entity.Customer;
import com.group1.drawingcouseselling.model.enums.EExamStatus;
import com.group1.drawingcouseselling.repository.CourseContentCompletionRepository;
import com.group1.drawingcouseselling.repository.CourseContentRepository;
import com.group1.drawingcouseselling.repository.ExamRepository;
import com.group1.drawingcouseselling.service.CustomerService;
import com.group1.drawingcouseselling.service.ExamService;
import com.group1.drawingcouseselling.service.InstructorService;
import com.group1.drawingcouseselling.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -30,6 +31,7 @@ public class ExamServiceImpl implements ExamService {
private final ExamRepository examRepository;
private final CustomerService customerService;
private final InstructorService instructorService;
private final CourseContentCompletionRepository courseContentCompletionRepository;
@Override
public ExamDto getExamInformation(BigDecimal courseContentID, String customerEmail){
var customer = customerService.searchCustomerByEmail(customerEmail).orElseThrow(() -> new UserNotFoundException(""));
Expand Down Expand Up @@ -86,6 +88,24 @@ public ExamDetailInfoDto getExamInfoDetail(BigDecimal examID){
public ExamDto assignScoreSubmit(String instructorEmail, ExamMarkDto examMark){
var instructor = instructorService.findInstructorByInstructorEmail(instructorEmail);
if(instructor == null) throw new UserNotFoundException("");
return null;
var exam = examRepository.findById(examMark.examID()).orElseThrow(() ->
new EntityNotFoundException("This exam isn't existed"));
exam.setScore(examMark.score());
exam.setInstructorComment(examMark.comment());
var result = examRepository.save(exam);
var a = result.getCourseContentCompletion();
if(result.getSubmitStatus() == EExamStatus.PASSED){
a.setDone(true);
}else{
a.setDone(false);
}
courseContentCompletionRepository.save(a);
return ExamDto.builder()
.id(result.getId())
.examStatus(result.getSubmitStatus())
.comment(result.getInstructorComment())
.score(result.getScore())
.artLink(result.getArtLinked())
.build();
}
}

0 comments on commit fc1c91c

Please sign in to comment.