-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from AnataAria/vinh
vinh/add get exam infomation
- Loading branch information
Showing
5 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...gcouseselling/src/main/java/com/group1/drawingcouseselling/controller/ExamController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...drawingcouseselling/src/main/java/com/group1/drawingcouseselling/service/ExamService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
32 changes: 32 additions & 0 deletions
32
...useselling/src/main/java/com/group1/drawingcouseselling/service/impl/ExamServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.