Skip to content

Commit

Permalink
Merge pull request #111 from AnataAria/vinh
Browse files Browse the repository at this point in the history
vinh/add get exam infomation
  • Loading branch information
PoserDungeon2003 authored Nov 6, 2023
2 parents 055e9ea + 85d0c36 commit 7f23a5f
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.group1.drawingcouseselling.controller;

import com.group1.drawingcouseselling.model.dto.ExamDto;
import com.group1.drawingcouseselling.service.ExamService;
import com.group1.drawingcouseselling.service.JwtService;
import lombok.RequiredArgsConstructor;
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.RestController;

import java.math.BigDecimal;

@RestController
@RequiredArgsConstructor
public class ExamController {
private final ExamService examService;
private final JwtService jwtService;
@GetMapping("/exam")
public ResponseEntity<ExamDto> getExamSubmitted(@RequestHeader("Authorization") String authorization,
BigDecimal courseContentID)
{
String email = jwtService.extractUserEmail(authorization.substring(7));
return ResponseEntity.ok(examService.getExamInformation(courseContentID, email));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import com.group1.drawingcouseselling.model.entity.Exam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Optional;

@Repository
public interface ExamRepository extends JpaRepository<Exam, BigDecimal> {
@Query("SELECT e FROM exam e INNER JOIN course_content_completion ccc ON e.courseContentCompletion.id = ccc.id" +
" INNER JOIN course_content cc ON cc.id = ccc.courseContent.id WHERE ccc.customer.id = :customerID AND cc.id = :courseContentID")
public Optional<Exam> getExamByCustomerIdAndCourseContentId(@Param(value = "customerID") BigDecimal customerID,@Param(value = "courseContentID") BigDecimal courseContentID);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.group1.drawingcouseselling.service;

import com.group1.drawingcouseselling.model.dto.ExamDto;

import java.math.BigDecimal;

public interface ExamService {
public ExamDto getExamInformation(BigDecimal courseContentID, String customerEmail);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.group1.drawingcouseselling.service.impl;

import com.group1.drawingcouseselling.exception.EntityNotFoundException;
import com.group1.drawingcouseselling.exception.UserNotFoundException;
import com.group1.drawingcouseselling.model.dto.ExamDto;
import com.group1.drawingcouseselling.repository.ExamRepository;
import com.group1.drawingcouseselling.service.CustomerService;
import com.group1.drawingcouseselling.service.ExamService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
@RequiredArgsConstructor
public class ExamServiceImpl implements ExamService {
private final ExamRepository examRepository;
private final CustomerService customerService;
public ExamDto getExamInformation(BigDecimal courseContentID, String customerEmail){
var customer = customerService.searchCustomerByEmail(customerEmail).orElseThrow(() -> new UserNotFoundException(""));
var customerExam = examRepository.getExamByCustomerIdAndCourseContentId(customer.getId(), courseContentID)
.orElseThrow(() -> new EntityNotFoundException("Exam not submited"));

return ExamDto.builder()
.score(customerExam.getScore())
.id(customerExam.getId())
.examStatus(customerExam.getSubmitStatus())
.artLink(customerExam.getArtLinked())
.comment(customerExam.getInstructorComment())
.build();
}
}
137 changes: 137 additions & 0 deletions frontend/my-app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f23a5f

Please sign in to comment.