diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateController.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateController.java index c31cd05af51aa9fad8d7faa4e36370a48886bbd2..1fedbb67cb67adbdd0e88061ab3646322e1ede6c 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateController.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateController.java @@ -67,11 +67,11 @@ public class CertificateController { * @param userId ID of user to retrieve certificates for. * @param courseId ID of course to retrieve certificates for. * @return List of CertificateDto objects with previously generated certificates - * for specified User. + * for specified User and Course. */ - @GetMapping("/getId") - public String getId(@RequestParam String userId, @RequestParam String courseId) { - return "0"; + @GetMapping("/findForUserAndCourse") + public List<CertificateSimpleDto> findForUserAndCourse(@RequestParam Long userId, @RequestParam Long courseId) { + return certificateFacade.findByUserIdAndCourseId(userId, courseId); } /** diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateFacade.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateFacade.java index fe2084ccad5057c0f169f0f2d3fd696130402a94..0403330a62028d465085dab48288d0ccca96155b 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateFacade.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateFacade.java @@ -42,6 +42,13 @@ public class CertificateFacade { public List<CertificateSimpleDto> findByUserId(Long userId) { return certificateMapper.mapToList(certificateService.findByUserId(userId)); } + + @Cacheable(cacheNames = "certificates", key = "#userId") + @Transactional(readOnly = true) + public List<CertificateSimpleDto> findByUserIdAndCourseId(Long userId, Long courseId) { + return certificateMapper.mapToList(certificateService.findByUserIdAndCourseId(userId, courseId)); + } + //@Transactional(readOnly = true) //public Page<CertificateDto> findAll(Pageable pageable) { //return certificateMapper.mapToPageDto(certificateService.findAll(pageable)); diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateRepository.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateRepository.java index 14c6fbd7a4bcd4c02f9954e9fa581d5eac1e43e3..832d2d22d002b82e3a93287f4382cfa66273b56d 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateRepository.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateRepository.java @@ -13,5 +13,9 @@ public interface CertificateRepository extends JpaRepository<Certificate, Long> @Query("SELECT c FROM Certificate c WHERE c.userId = ?1") List<Certificate> findCertificateByUserId(Long userId); + + @Query("SELECT c FROM Certificate c WHERE c.userId = ?1 and c.courseId = ?2") + List<Certificate> findCertificateByUserIdAndCourseId(Long userId, Long courseId); + } diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java index baf8828b808be912bd6fb688ce93b28d761ffe51..4725dcdaf87ef480e5f922650815ca5577ac9ff8 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java @@ -30,6 +30,11 @@ public class CertificateService { return certificateRepository.findCertificateByUserId(userId); } + @Transactional(readOnly = true) + public List<Certificate> findByUserIdAndCourseId(Long userId, Long courseId) { + return certificateRepository.findCertificateByUserIdAndCourseId(userId, courseId); + } + @Transactional(readOnly = true) public Certificate save(Certificate certificate) { return certificateRepository.save(certificate);