Skip to content
Snippets Groups Projects
Commit 18948411 authored by evilimkova's avatar evilimkova
Browse files

findCertificateByUserIdAndCourseId

parent aec8cf7c
No related branches found
No related tags found
4 merge requests!31M2,!29M2 exercise,!27Draft: M2 user,!19M2 certificate
Pipeline #
......@@ -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);
}
/**
......
......@@ -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));
......
......@@ -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);
}
......@@ -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);
......
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