Commit 84483017 authored by Ololw's avatar Ololw
Browse files

Logique métier Scénario 2

parent c67ab62e
......@@ -10,6 +10,6 @@ import org.springframework.stereotype.Repository;
*/
@SuppressWarnings("unused")
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
public interface CourseRepository extends JpaRepository<Course, Long>, CourseRepositoryCustom {
}
package com.mycompany.myapp.repository;
import java.util.List;
import com.mycompany.myapp.domain.Course;
public interface CourseRepositoryCustom
{
public List<Course> getLateCourses();
public List<Course> getWaitingCourses();
public List<Course> getInProgressCourses();
public List<Course> getDoneCourses();
}
package com.mycompany.myapp.repository;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
//import org.joda.time.Instant;
import java.time.Instant;
import com.mycompany.myapp.domain.Course;
public class CourseRepositoryImpl implements CourseRepositoryCustom
{
@PersistenceContext
EntityManager entityManager;
public List<Course> getLateCourses()
{
Instant current = Instant.now();
Instant dateLimite = current.minus(1, ChronoUnit.DAYS);
Query query = entityManager.createNativeQuery(
"SELECT * FROM mytransport.course " + "WHERE mytransport.course.taxi_id IS NULL "
+ "AND mytransport.course.debut_espere < ?" + "AND mytransport.course.debut_espere > ? ",
Course.class);
query.setParameter(1, current);
query.setParameter(2, dateLimite);
return query.getResultList();
}
public List<Course> getWaitingCourses()
{
Instant current = Instant.now();
Query query = entityManager.createNativeQuery("SELECT * FROM mytransport.course "
+ "WHERE mytransport.course.taxi_id IS NULL " + "AND mytransport.course.debut_espere >= ?",
Course.class);
query.setParameter(1, current);
return query.getResultList();
}
public List<Course> getInProgressCourses()
{
Query query = entityManager.createNativeQuery("SELECT * FROM mytransport.course "
+ "WHERE mytransport.course.taxi_id IS NOT NULL " + "AND mytransport.course.fin IS NULL",
Course.class);
return query.getResultList();
}
public List<Course> getDoneCourses()
{
Instant current = Instant.now();
Instant dateLimite = current.minus(1, ChronoUnit.DAYS);
Query query = entityManager.createNativeQuery("SELECT * FROM mytransport.course "
+ "WHERE mytransport.course.fin IS NOT NULL "
+ "AND mytransport.course.fin > ?",
Course.class);
query.setParameter(1, dateLimite);
return query.getResultList();
}
}
......@@ -144,5 +144,64 @@ public class CourseResource {
.stream(courseSearchRepository.search(queryStringQuery(query)).spliterator(), false)
.collect(Collectors.toList());
}
/**
* GET /coursesLate : get all late courses.
*
* @return the ResponseEntity with status 200 (OK) and the list of courses in body
*/
@GetMapping("/coursesLate")
@Timed
public List<Course> getAllLateCourses() {
log.debug("REST request to get all Late Courses");
return courseRepository.getLateCourses();
}
/**
* GET /coursesWaiting : get all waiting courses.
*
* @return the ResponseEntity with status 200 (OK) and the list of courses in body
*/
@GetMapping("/coursesWaiting")
@Timed
public List<Course> getAllWaitingCourses() {
log.debug("REST request to get all Waiting Courses");
return courseRepository.getWaitingCourses();
}
/**
* GET /coursesInProgress : get all in progress courses.
*
* @return the ResponseEntity with status 200 (OK) and the list of courses in body
*/
@GetMapping("/coursesInProgress")
@Timed
public List<Course> getAllInProgressCourses() {
log.debug("REST request to get all in progress Courses");
return courseRepository.getInProgressCourses();
}
/**
* GET /coursesDone : get all done courses for the last day.
*
* @return the ResponseEntity with status 200 (OK) and the list of courses in body
*/
@GetMapping("/coursesDone")
@Timed
public List<Course> getAllDoneCourses() {
log.debug("REST request to get all in progress Courses");
return courseRepository.getDoneCourses();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment