Skip to content
Snippets Groups Projects
Commit 89ffab9f authored by evilimkova's avatar evilimkova Committed by Martin Gargalovič
Browse files

findCertificateByUserIdAndCourseId

parent 39378667
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
...@@ -67,11 +67,11 @@ public class CertificateController { ...@@ -67,11 +67,11 @@ public class CertificateController {
* @param userId ID of user to retrieve certificates for. * @param userId ID of user to retrieve certificates for.
* @param courseId ID of course to retrieve certificates for. * @param courseId ID of course to retrieve certificates for.
* @return List of CertificateDto objects with previously generated certificates * @return List of CertificateDto objects with previously generated certificates
* for specified User. * for specified User and Course.
*/ */
@GetMapping("/getId") @GetMapping("/findForUserAndCourse")
public String getId(@RequestParam String userId, @RequestParam String courseId) { public List<CertificateSimpleDto> findForUserAndCourse(@RequestParam Long userId, @RequestParam Long courseId) {
return "0"; return certificateFacade.findByUserIdAndCourseId(userId, courseId);
} }
/** /**
......
...@@ -42,6 +42,13 @@ public class CertificateFacade { ...@@ -42,6 +42,13 @@ public class CertificateFacade {
public List<CertificateSimpleDto> findByUserId(Long userId) { public List<CertificateSimpleDto> findByUserId(Long userId) {
return certificateMapper.mapToList(certificateService.findByUserId(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) //@Transactional(readOnly = true)
//public Page<CertificateDto> findAll(Pageable pageable) { //public Page<CertificateDto> findAll(Pageable pageable) {
//return certificateMapper.mapToPageDto(certificateService.findAll(pageable)); //return certificateMapper.mapToPageDto(certificateService.findAll(pageable));
......
...@@ -13,5 +13,9 @@ public interface CertificateRepository extends JpaRepository<Certificate, Long> ...@@ -13,5 +13,9 @@ public interface CertificateRepository extends JpaRepository<Certificate, Long>
@Query("SELECT c FROM Certificate c WHERE c.userId = ?1") @Query("SELECT c FROM Certificate c WHERE c.userId = ?1")
List<Certificate> findCertificateByUserId(Long userId); 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);
} }
...@@ -30,6 +30,11 @@ public class CertificateService { ...@@ -30,6 +30,11 @@ public class CertificateService {
return certificateRepository.findCertificateByUserId(userId); return certificateRepository.findCertificateByUserId(userId);
} }
@Transactional(readOnly = true)
public List<Certificate> findByUserIdAndCourseId(Long userId, Long courseId) {
return certificateRepository.findCertificateByUserIdAndCourseId(userId, courseId);
}
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Certificate save(Certificate certificate) { public Certificate save(Certificate certificate) {
return certificateRepository.save(certificate); return certificateRepository.save(certificate);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment