1 | package com.example.task.repository;
|
---|
2 |
|
---|
3 | import com.example.task.entity.projection.NonRepeatingClassEvent;
|
---|
4 | import com.example.task.entity.projection.ExamEvent;
|
---|
5 | import com.example.task.entity.projection.RepeatingClassEvent;
|
---|
6 | import com.example.task.entity.subject.SubjectEntity;
|
---|
7 | import com.example.task.entity.subject.SubjectId;
|
---|
8 | import org.springframework.data.jpa.repository.JpaRepository;
|
---|
9 | import org.springframework.data.jpa.repository.Query;
|
---|
10 | import org.springframework.data.repository.query.Param;
|
---|
11 | import org.springframework.stereotype.Repository;
|
---|
12 |
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Repository
|
---|
16 | public interface SubjectRepository extends JpaRepository<SubjectEntity, SubjectId> {
|
---|
17 |
|
---|
18 | @Query(value = "SELECT sat.subject_name AS subjectName, " +
|
---|
19 | "ce.event_name AS eventName, " +
|
---|
20 | "ce.event_type AS eventType, " +
|
---|
21 | "nre.event_date AS eventDate, " +
|
---|
22 | "ce.event_start_time AS eventStartTime, " +
|
---|
23 | "ce.event_end_time AS eventEndTime, " +
|
---|
24 | "ce.calendar_event_id AS eventId " +
|
---|
25 | "FROM project.non_repeating_event AS nre " +
|
---|
26 | "JOIN project.calendar_event AS ce ON nre.calendar_event_id = ce.calendar_event_id " +
|
---|
27 | "JOIN project.subject_event AS sbe ON ce.calendar_event_id = sbe.calendar_event_id " +
|
---|
28 | "JOIN project.subject_at_term AS sat ON sat.term_subject_id = sbe.term_subject_id " +
|
---|
29 | "AND sat.term_type = sbe.term_type " +
|
---|
30 | "AND sat.starting_year = sbe.starting_year " +
|
---|
31 | "AND sat.finishing_year = sbe.finishing_year " +
|
---|
32 | "AND sat.student_id = sbe.student_id " +
|
---|
33 | "WHERE nre.event_date >= CURRENT_DATE " +
|
---|
34 | "AND ce.event_type = 'Exam' " +
|
---|
35 | "AND sbe.student_id = :studentId " +
|
---|
36 | "ORDER BY nre.event_date, ce.event_start_time", nativeQuery = true)
|
---|
37 | List<ExamEvent> exams(@Param("studentId") Integer studentId);
|
---|
38 |
|
---|
39 | @Query(value = "SELECT sat.subject_name AS subjectName, " +
|
---|
40 | "ce.event_name AS eventName, " +
|
---|
41 | "ce.event_type AS eventType, " +
|
---|
42 | "nre.event_date AS eventDate, " +
|
---|
43 | "ce.event_start_time AS eventStartTime, " +
|
---|
44 | "ce.event_end_time AS eventEndTime, " +
|
---|
45 | "ce.calendar_event_id AS eventId " +
|
---|
46 | "FROM project.non_repeating_event AS nre " +
|
---|
47 | "JOIN project.calendar_event AS ce ON nre.calendar_event_id = ce.calendar_event_id " +
|
---|
48 | "JOIN project.subject_event AS sbe ON ce.calendar_event_id = sbe.calendar_event_id " +
|
---|
49 | "JOIN project.subject_at_term AS sat ON sat.term_subject_id = sbe.term_subject_id " +
|
---|
50 | "AND sat.term_type = sbe.term_type " +
|
---|
51 | "AND sat.starting_year = sbe.starting_year " +
|
---|
52 | "AND sat.finishing_year = sbe.finishing_year " +
|
---|
53 | "AND sat.student_id = sbe.student_id " +
|
---|
54 | "WHERE nre.event_date >= CURRENT_DATE " +
|
---|
55 | "AND ce.event_type = 'Class' " +
|
---|
56 | "AND sbe.student_id = :studentId " +
|
---|
57 | "ORDER BY nre.event_date, ce.event_start_time", nativeQuery = true)
|
---|
58 | List<NonRepeatingClassEvent> nonRepeatingClasses(@Param("studentId") Integer studentId);
|
---|
59 |
|
---|
60 | @Query(value = "SELECT sat.subject_name AS subjectName, " +
|
---|
61 | "ce.event_name AS eventName, " +
|
---|
62 | "ce.event_type AS eventType, " +
|
---|
63 | "nre.starting_date AS eventStartingDate, " +
|
---|
64 | "nre.ending_date AS eventEndingDate, " +
|
---|
65 | "nre.event_week_day AS eventDay, " +
|
---|
66 | "ce.event_start_time AS eventStartTime, " +
|
---|
67 | "ce.event_end_time AS eventEndTime, " +
|
---|
68 | "ce.calendar_event_id AS eventId " +
|
---|
69 | "FROM project.repeating_event AS nre " +
|
---|
70 | "JOIN project.calendar_event AS ce ON nre.calendar_event_id = ce.calendar_event_id " +
|
---|
71 | "JOIN project.subject_event AS sbe ON ce.calendar_event_id = sbe.calendar_event_id " +
|
---|
72 | "JOIN project.subject_at_term AS sat ON sat.term_subject_id = sbe.term_subject_id " +
|
---|
73 | "AND sat.term_type = sbe.term_type " +
|
---|
74 | "AND sat.starting_year = sbe.starting_year " +
|
---|
75 | "AND sat.finishing_year = sbe.finishing_year " +
|
---|
76 | "AND sat.student_id = sbe.student_id " +
|
---|
77 | "WHERE nre.starting_date >= CURRENT_DATE " +
|
---|
78 | "AND ce.event_type = 'Class' " +
|
---|
79 | "AND sbe.student_id = :studentId " +
|
---|
80 | "ORDER BY nre.starting_date, ce.event_start_time", nativeQuery = true)
|
---|
81 | List<RepeatingClassEvent> repeatingClasses(@Param("studentId") Integer studentId);
|
---|
82 |
|
---|
83 |
|
---|
84 | }
|
---|