Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vinh/add get exam infomation #111

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.