Skip to content

Commit

Permalink
vinh/fix error code for exam get infomation
Browse files Browse the repository at this point in the history
  • Loading branch information
AnataAria committed Nov 6, 2023
1 parent 85d0c36 commit 90beaad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.group1.drawingcouseselling.exception;

import com.group1.drawingcouseselling.model.dto.ErrorMessage;
import lombok.Builder;
import lombok.Getter;
import org.springframework.http.HttpStatus;
@Getter
Expand All @@ -10,5 +11,9 @@ public class BaseException extends RuntimeException {
public BaseException(String message) {
super(message);
}
public BaseException(ErrorMessage errorMessage) {
super(errorMessage.getErrorList().toString());
this.errorMessage = errorMessage;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public EntityNotFoundException(String message) {
.currentTimeError(new Date(System.currentTimeMillis()))
.build();
}
public EntityNotFoundException(ErrorMessage errorMessage) {
super(errorMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.group1.drawingcouseselling.exception.EntityNotFoundException;
import com.group1.drawingcouseselling.exception.UserNotFoundException;
import com.group1.drawingcouseselling.model.dto.ErrorMessage;
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.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand All @@ -19,8 +23,11 @@ public class ExamServiceImpl implements ExamService {
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"));

.orElseThrow(() -> new EntityNotFoundException(ErrorMessage.builder()
.errorList(List.of("Exam not submitted"))
.status(HttpStatus.valueOf(420))
.currentTimeError(new Date(System.currentTimeMillis()))
.build()));
return ExamDto.builder()
.score(customerExam.getScore())
.id(customerExam.getId())
Expand Down

0 comments on commit 90beaad

Please sign in to comment.