forge
Explore
Log in

Don't you dare go Hollow

Params structs for the d8dad92 list doors

Browse files at this commit

62f10ea7df748cc00a5e98532b352f03610c5632Ahmet Kaan GümüşParent: 57527df
  • fix
    • params structs for the d8dad92 list doors
Show full message
🐛 fix(clippy): params structs for the d8dad92 list doors

-d warnings gate red on main: too_many_arguments on the new filter list
functions (db/service appointment list_for_requester 8/7, db/service exam
list_windowed 9/7), type_complexity on the courses filter resolve,
extra_unused_lifetimes on pomodoro whole_log. RequesterListParams and
WindowedListParams params structs (SettingsParams precedent), the courses
tuple factored into ResolvedCourseFilter, every caller and test call site
migrated; no suppressions.
src/db/appointment.rsmodified+25 -6
@@ -132,6 +132,22 @@ where
132132 Ok(appointment)
133133 }
134134
135+/// The optional filters and the page of [`list_for_requester`], in one
136+/// struct — the fields outgrew a readable argument list. The default is
137+/// the unfiltered, unpaged read.
138+#[derive(Default)]
139+pub struct RequesterListParams<'a> {
140+ pub status: Option<AppointmentStatus>,
141+ /// The meeting's effective start bounds, `[after, before)`.
142+ pub starts_after: Option<Timestamp>,
143+ pub starts_before: Option<Timestamp>,
144+ /// The booked slot's teacher.
145+ pub teacher: Option<&'a UserId>,
146+ /// `None` = the full list.
147+ pub limit: Option<i64>,
148+ pub offset: i64,
149+}
150+
135151 /// The caller's own bookings, newest first. The optional filters narrow the
136152 /// read: `status` matches the stored state, `starts_after`/`starts_before`
137153 /// bound the meeting's effective start — a standing proposal, the slot's
@@ -145,13 +161,16 @@ where
145161 pub async fn list_for_requester(
146162 db: &Database,
147163 requester: &UserId,
148- status: Option<AppointmentStatus>,
149- starts_after: Option<Timestamp>,
150- starts_before: Option<Timestamp>,
151- teacher: Option<&UserId>,
152- limit: Option<i64>,
153- offset: i64,
164+ params: RequesterListParams<'_>,
154165 ) -> Result<(Vec<Appointment>, i64), AppError> {
166+ let RequesterListParams {
167+ status,
168+ starts_after,
169+ starts_before,
170+ teacher,
171+ limit,
172+ offset,
173+ } = params;
155174 // Spell the appointment columns against the join alias, so the derived
156175 // table's row keeps the exact names [`Appointment`] decodes and the
157176 // slot's duplicate column names never leak in. The plain shape aliases
src/db/exam.rsmodified+29 -13
@@ -206,6 +206,26 @@ pub async fn read(db: &Database, id: &ExamId) -> Result<Option<Exam>, AppError>
206206 .await?)
207207 }
208208
209+/// The schedule window and the page of [`list_windowed`], in one struct —
210+/// the fields outgrew a readable argument list. The four optional bounds
211+/// are [`crate::web::page::WindowParams`]'s schedule window, validated
212+/// upstream. The default is the windowless, unpaged read: all four bounds
213+/// absent keeps `id DESC` (newest first); any bound set drops window-less
214+/// exams (no `mode` → both schedule columns null, so every predicate is
215+/// `NULL`-rejecting) and flips the order to ascending by schedule —
216+/// `starts_at`, falling back to `ends_at`, ties by id — the order
217+/// `WindowParams::apply` used to produce in Rust.
218+#[derive(Default)]
219+pub struct WindowedListParams {
220+ pub starts_after: Option<i64>,
221+ pub ends_after: Option<i64>,
222+ pub starts_before: Option<i64>,
223+ pub ends_before: Option<i64>,
224+ /// `None` = the full list.
225+ pub limit: Option<i64>,
226+ pub offset: i64,
227+}
228+
209229 /// The exams list behind `GET /exams`, paged by the database — visibility,
210230 /// the draft rule, the schedule window, the `LIMIT/OFFSET` and the `total`
211231 /// count all share one `WHERE` per branch, so a filtered page never decodes
@@ -216,24 +236,20 @@ pub async fn read(db: &Database, id: &ExamId) -> Result<Option<Exam>, AppError>
216236 /// exam), with `NOT draft OR owner ∈ managed`, today's rule unchanged — a
217237 /// draft shows only to someone who manages its owner instance. Both `None` is
218238 /// the manager+ whole-table read.
219-///
220-/// The four optional bounds are [`crate::web::page::WindowParams`]'s schedule
221-/// window, validated upstream. All four absent keeps `id DESC` (newest
222-/// first); any bound set drops window-less exams (no `mode` → both schedule
223-/// columns null, so every predicate is `NULL`-rejecting) and flips the order
224-/// to ascending by schedule — `starts_at`, falling back to `ends_at`, ties by
225-/// id — the order `WindowParams::apply` used to produce in Rust.
226239 pub async fn list_windowed(
227240 db: &Database,
228241 visible: Option<&[ClassCourseId]>,
229242 managed: Option<&[ClassCourseId]>,
230- starts_after: Option<i64>,
231- ends_after: Option<i64>,
232- starts_before: Option<i64>,
233- ends_before: Option<i64>,
234- limit: Option<i64>,
235- offset: i64,
243+ params: WindowedListParams,
236244 ) -> Result<(Vec<Exam>, i64), AppError> {
245+ let WindowedListParams {
246+ starts_after,
247+ ends_after,
248+ starts_before,
249+ ends_before,
250+ limit,
251+ offset,
252+ } = params;
237253 // Window predicates and binds move together: each bound appends its
238254 // predicate with the placeholder number its bind position lands on. The
239255 // two visibility binds of the non-manager branch claim $1 and $2, so the
src/db/pomodoro.rsmodified+1 -1
@@ -440,7 +440,7 @@ mod tests {
440440
441441 /// The whole unwindowed log — the read the old `list_for_user` gave —
442442 /// for tests that just want the sessions.
443- async fn whole_log<'a>(user: &UserId, db: &Database) -> Vec<PomodoroSession> {
443+ async fn whole_log(user: &UserId, db: &Database) -> Vec<PomodoroSession> {
444444 page_for_user(db, user, None, None, None, 0)
445445 .await
446446 .unwrap()
src/service/appointment.rsmodified+96 -61
@@ -32,6 +32,8 @@ use crate::domain::timestamp::Timestamp;
3232 use crate::domain::user::UserId;
3333 use crate::error::{AppError, ValidationError};
3434
35+pub use crate::db::appointment::RequesterListParams;
36+
3537 /// Request `slot`. Lands `pending`: publishing availability is not consent
3638 /// to a specific person and topic.
3739 ///
@@ -126,24 +128,9 @@ pub async fn read(db: &Database, id: &AppointmentId) -> Result<Option<Appointmen
126128 pub async fn list_for_requester(
127129 db: &Database,
128130 requester: &UserId,
129- status: Option<AppointmentStatus>,
130- starts_after: Option<Timestamp>,
131- starts_before: Option<Timestamp>,
132- teacher: Option<&UserId>,
133- limit: Option<i64>,
134- offset: i64,
131+ params: RequesterListParams<'_>,
135132 ) -> Result<(Vec<Appointment>, i64), AppError> {
136- appointment::list_for_requester(
137- db,
138- requester,
139- status,
140- starts_after,
141- starts_before,
142- teacher,
143- limit,
144- offset,
145- )
146- .await
133+ appointment::list_for_requester(db, requester, params).await
147134 }
148135
149136 /// Every booking aimed at `teacher`, newest first — the request inbox,
@@ -909,13 +896,17 @@ mod tests {
909896
910897 // Absent: all three, newest first — the shape today's callers see.
911898 let (rows, total) =
912- list_for_requester(&db, &veli, None, None, None, None, None, 0).await.unwrap();
899+ list_for_requester(&db, &veli, RequesterListParams::default()).await.unwrap();
913900 assert_eq!((rows.len(), total), (3, 3));
914901
915902 // status: only the approved one, and total is the filtered count.
916- let (rows, total) = list_for_requester(&db, &veli, Some(AppointmentStatus::Approved), None, None, None,
917- None,
918- 0,
903+ let (rows, total) = list_for_requester(
904+ &db,
905+ &veli,
906+ RequesterListParams {
907+ status: Some(AppointmentStatus::Approved),
908+ ..Default::default()
909+ },
919910 )
920911 .await
921912 .unwrap();
@@ -923,25 +914,41 @@ mod tests {
923914 assert_eq!(rows[0].get_id(), approved.get_id());
924915
925916 // No state matches: an empty page, not an error.
926- let (rows, total) = list_for_requester(&db, &veli, Some(AppointmentStatus::Rejected), None, None, None,
927- None,
928- 0,
917+ let (rows, total) = list_for_requester(
918+ &db,
919+ &veli,
920+ RequesterListParams {
921+ status: Some(AppointmentStatus::Rejected),
922+ ..Default::default()
923+ },
929924 )
930925 .await
931926 .unwrap();
932927 assert_eq!((rows.len(), total), (0, 0));
933928
934929 // teacher joins through the slot: only the bookings on ali's slots.
935- let (rows, total) =
936- list_for_requester(&db, &veli, None, None, None, Some(&ali), None, 0).await.unwrap();
930+ let (rows, total) = list_for_requester(
931+ &db,
932+ &veli,
933+ RequesterListParams {
934+ teacher: Some(&ali),
935+ ..Default::default()
936+ },
937+ )
938+ .await
939+ .unwrap();
937940 assert_eq!((rows.len(), total), (2, 2));
938941 assert!(rows.iter().all(|row| row.get_id() != approved.get_id()));
939942
940943 // starts_after judges the effective start: the pending meeting (at
941944 // now + 60_000) is out; the approved and cancelled ones stay.
942- let (rows, total) = list_for_requester(&db, &veli, None, Some(at(now + 150_000)), None, None,
943- None,
944- 0,
945+ let (rows, total) = list_for_requester(
946+ &db,
947+ &veli,
948+ RequesterListParams {
949+ starts_after: Some(at(now + 150_000)),
950+ ..Default::default()
951+ },
945952 )
946953 .await
947954 .unwrap();
@@ -949,11 +956,28 @@ mod tests {
949956 assert!(rows.iter().all(|row| row.get_id() != pending.get_id()));
950957
951958 // The window applies after the filter; total stays the filtered count.
952- let (page1, total) =
953- list_for_requester(&db, &veli, None, None, None, None, Some(1), 0).await.unwrap();
959+ let (page1, total) = list_for_requester(
960+ &db,
961+ &veli,
962+ RequesterListParams {
963+ limit: Some(1),
964+ ..Default::default()
965+ },
966+ )
967+ .await
968+ .unwrap();
954969 assert_eq!((page1.len(), total), (1, 3));
955- let (page2, total) =
956- list_for_requester(&db, &veli, None, None, None, None, Some(1), 1).await.unwrap();
970+ let (page2, total) = list_for_requester(
971+ &db,
972+ &veli,
973+ RequesterListParams {
974+ limit: Some(1),
975+ offset: 1,
976+ ..Default::default()
977+ },
978+ )
979+ .await
980+ .unwrap();
957981 assert_eq!((page2.len(), total), (1, 3));
958982 assert_ne!(page1[0].get_id(), page2[0].get_id());
959983
@@ -963,9 +987,13 @@ mod tests {
963987 propose(&db, pending.get_id(), at(now + 500_000), at(now + 560_000), &ali)
964988 .await
965989 .unwrap();
966- let (rows, total) = list_for_requester(&db, &veli, None, Some(at(now + 400_000)), None, None,
967- None,
968- 0,
990+ let (rows, total) = list_for_requester(
991+ &db,
992+ &veli,
993+ RequesterListParams {
994+ starts_after: Some(at(now + 400_000)),
995+ ..Default::default()
996+ },
969997 )
970998 .await
971999 .unwrap();
@@ -1005,18 +1033,30 @@ mod tests {
10051033 .await
10061034 .unwrap();
10071035 let (rows, total) =
1008- list_for_requester(&db, &veli, None, None, None, None, None, 0).await.unwrap();
1036+ list_for_requester(&db, &veli, RequesterListParams::default()).await.unwrap();
10091037 assert_eq!((rows.len(), total), (3, 3), "the windowless row still lists");
1010- let (rows, total) = list_for_requester(&db, &veli, None, Some(at(now)), None, None,
1011- None,
1012- 0,
1038+ let (rows, total) = list_for_requester(
1039+ &db,
1040+ &veli,
1041+ RequesterListParams {
1042+ starts_after: Some(at(now)),
1043+ ..Default::default()
1044+ },
10131045 )
10141046 .await
10151047 .unwrap();
10161048 assert_eq!((rows.len(), total), (2, 2), "the windowless row has no start to match");
10171049 assert!(rows.iter().all(|row| row.get_id() != cancelled.get_id()));
1018- let (rows, total) =
1019- list_for_requester(&db, &veli, None, None, None, Some(&ali), None, 0).await.unwrap();
1050+ let (rows, total) = list_for_requester(
1051+ &db,
1052+ &veli,
1053+ RequesterListParams {
1054+ teacher: Some(&ali),
1055+ ..Default::default()
1056+ },
1057+ )
1058+ .await
1059+ .unwrap();
10201060 assert_eq!((rows.len(), total), (1, 1), "a windowless row names no teacher");
10211061 assert_eq!(rows[0].get_id(), pending.get_id());
10221062 }
@@ -1051,19 +1091,17 @@ mod tests {
10511091
10521092 // Absent: both — the set is unchanged without the bound.
10531093 let (rows, total) =
1054- list_for_requester(&db, &veli, None, None, None, None, None, 0).await.unwrap();
1094+ list_for_requester(&db, &veli, RequesterListParams::default()).await.unwrap();
10551095 assert_eq!((rows.len(), total), (2, 2));
10561096
10571097 // before: only the early booking survives.
10581098 let (rows, total) = list_for_requester(
10591099 &db,
10601100 &veli,
1061- None,
1062- None,
1063- Some(at(now + 150_000)),
1064- None,
1065- None,
1066- 0,
1101+ RequesterListParams {
1102+ starts_before: Some(at(now + 150_000)),
1103+ ..Default::default()
1104+ },
10671105 )
10681106 .await
10691107 .unwrap();
@@ -1076,12 +1114,10 @@ mod tests {
10761114 let (rows, total) = list_for_requester(
10771115 &db,
10781116 &veli,
1079- None,
1080- None,
1081- Some(at(now + 200_000)),
1082- None,
1083- None,
1084- 0,
1117+ RequesterListParams {
1118+ starts_before: Some(at(now + 200_000)),
1119+ ..Default::default()
1120+ },
10851121 )
10861122 .await
10871123 .unwrap();
@@ -1100,12 +1136,11 @@ mod tests {
11001136 let (rows, total) = list_for_requester(
11011137 &db,
11021138 &veli,
1103- None,
1104- Some(at(now + 150_000)),
1105- Some(at(now + 260_000)),
1106- None,
1107- None,
1108- 0,
1139+ RequesterListParams {
1140+ starts_after: Some(at(now + 150_000)),
1141+ starts_before: Some(at(now + 260_000)),
1142+ ..Default::default()
1143+ },
11091144 )
11101145 .await
11111146 .unwrap();
src/service/exam.rsmodified+39 -41
@@ -24,6 +24,8 @@ use crate::domain::user::{User, UserId};
2424 use crate::error::{AppError, ValidationError};
2525 use crate::service::exam_attempt::require_open;
2626
27+pub use crate::db::exam::WindowedListParams;
28+
2729 /// Publish (or draft) an exam on one class×course instance, inside one term.
2830 ///
2931 /// Two refusals stand in front of the write. The instance's catalog course
@@ -122,25 +124,9 @@ pub async fn list_windowed(
122124 db: &Database,
123125 visible: Option<&[ClassCourseId]>,
124126 managed: Option<&[ClassCourseId]>,
125- starts_after: Option<i64>,
126- ends_after: Option<i64>,
127- starts_before: Option<i64>,
128- ends_before: Option<i64>,
129- limit: Option<i64>,
130- offset: i64,
127+ params: WindowedListParams,
131128 ) -> Result<(Vec<Exam>, i64), AppError> {
132- exam::list_windowed(
133- db,
134- visible,
135- managed,
136- starts_after,
137- ends_after,
138- starts_before,
139- ends_before,
140- limit,
141- offset,
142- )
143- .await
129+ exam::list_windowed(db, visible, managed, params).await
144130 }
145131
146132 /// One instance's exams, newest first — the read behind
@@ -903,7 +889,7 @@ mod tests {
903889 let other_draft = exam_shaped(&db, &b, sync(now + 3_600_000), true, "other-draft").await;
904890
905891 // Manager+: the whole table, newest first.
906- let (rows, total) = list_windowed(&db, None, None, None, None, None, None, None, 0)
892+ let (rows, total) = list_windowed(&db, None, None, WindowedListParams::default())
907893 .await
908894 .unwrap();
909895 assert_eq!(total, 5);
@@ -920,9 +906,17 @@ mod tests {
920906 // unaliased `exam` (the audience join only exists on the other
921907 // branch). This exact call 500'd with "missing FROM-clause entry for
922908 // table e" while the predicates were `e.`-qualified.
923- let (rows, total) = list_windowed(&db, None, None, None, Some(now), None, None, None, 0)
924- .await
925- .unwrap();
909+ let (rows, total) = list_windowed(
910+ &db,
911+ None,
912+ None,
913+ WindowedListParams {
914+ ends_after: Some(now),
915+ ..Default::default()
916+ },
917+ )
918+ .await
919+ .unwrap();
926920 assert_eq!(total, 3);
927921 let listed: Vec<_> = rows.iter().map(|exam| exam.get_id()).cloned().collect();
928922 assert_eq!(
@@ -932,10 +926,17 @@ mod tests {
932926 .map(|exam| exam.get_id().clone())
933927 .collect::<Vec<_>>()
934928 );
935- let (_, total) =
936- list_windowed(&db, None, None, None, None, Some(now + 45 * 60_000), None, None, 0)
937- .await
938- .unwrap();
929+ let (_, total) = list_windowed(
930+ &db,
931+ None,
932+ None,
933+ WindowedListParams {
934+ starts_before: Some(now + 45 * 60_000),
935+ ..Default::default()
936+ },
937+ )
938+ .await
939+ .unwrap();
939940 assert_eq!(total, 1, "starts_before keeps only the already-run exam");
940941
941942 // A viewer of A who manages nothing: A's published exams only — both
@@ -943,7 +944,7 @@ mod tests {
943944 let visible = vec![a.get_id().clone()];
944945 let nothing: Vec<ClassCourseId> = Vec::new();
945946 let (rows, total) =
946- list_windowed(&db, Some(&visible), Some(&nothing), None, None, None, None, None, 0)
947+ list_windowed(&db, Some(&visible), Some(&nothing), WindowedListParams::default())
947948 .await
948949 .unwrap();
949950 assert_eq!(total, 3);
@@ -952,7 +953,7 @@ mod tests {
952953 // A's teacher manages A: sees A's draft — and still not B's.
953954 let manages_a = vec![a.get_id().clone()];
954955 let (rows, total) =
955- list_windowed(&db, Some(&visible), Some(&manages_a), None, None, None, None, None, 0)
956+ list_windowed(&db, Some(&visible), Some(&manages_a), WindowedListParams::default())
956957 .await
957958 .unwrap();
958959 assert_eq!(total, 4);
@@ -967,12 +968,10 @@ mod tests {
967968 &db,
968969 Some(&visible),
969970 Some(&manages_a),
970- None,
971- Some(now),
972- None,
973- None,
974- None,
975- 0,
971+ WindowedListParams {
972+ ends_after: Some(now),
973+ ..Default::default()
974+ },
976975 )
977976 .await
978977 .unwrap();
@@ -985,12 +984,11 @@ mod tests {
985984 &db,
986985 Some(&visible),
987986 Some(&manages_a),
988- None,
989- Some(now),
990- None,
991- None,
992- Some(1),
993- 0,
987+ WindowedListParams {
988+ ends_after: Some(now),
989+ limit: Some(1),
990+ ..Default::default()
991+ },
994992 )
995993 .await
996994 .unwrap();
@@ -1000,7 +998,7 @@ mod tests {
1000998 // draft wall leaves them an empty page, not an error.
1001999 let sees_b = vec![b.get_id().clone()];
10021000 let (rows, total) =
1003- list_windowed(&db, Some(&sees_b), Some(&nothing), None, None, None, None, None, 0)
1001+ list_windowed(&db, Some(&sees_b), Some(&nothing), WindowedListParams::default())
10041002 .await
10051003 .unwrap();
10061004 assert!(rows.is_empty() && total == 0);
src/web/appointments.rsmodified+8 -6
@@ -819,12 +819,14 @@ async fn list_appointments(
819819 service::appointment::list_for_requester(
820820 &st.db,
821821 user.get_id(),
822- status,
823- starts_after,
824- starts_before,
825- narrow_to.as_ref(),
826- limit,
827- offset,
822+ service::appointment::RequesterListParams {
823+ status,
824+ starts_after,
825+ starts_before,
826+ teacher: narrow_to.as_ref(),
827+ limit,
828+ offset,
829+ },
828830 )
829831 .await?
830832 };
src/web/courses.rsmodified+23 -8
@@ -438,18 +438,31 @@ struct CourseListFilter {
438438 taught: Option<bool>,
439439 }
440440
441+/// The parsed [`CourseListFilter`] — one named field per query parameter,
442+/// ready for [`visible_courses_filtered`].
443+#[derive(Debug)]
444+struct ResolvedCourseFilter {
445+ kind: Option<CourseKind>,
446+ q: Option<String>,
447+ taught: Option<bool>,
448+}
449+
441450 impl CourseListFilter {
442451 /// `kind` parses through the write-path validator, so an unknown or empty
443452 /// spelling is the same 400 a create/PATCH gets; `taught` needs no parse —
444453 /// the query extractor itself 400s a `?taught=` that is not `true`/`false`,
445454 /// naming the field; `q` passes through raw — each arm trims, folds and
446455 /// blanks it identically.
447- fn resolve(self) -> Result<(Option<CourseKind>, Option<String>, Option<bool>), AppError> {
456+ fn resolve(self) -> Result<ResolvedCourseFilter, AppError> {
448457 let kind = match self.kind {
449458 Some(kind) => Some(CourseKind::try_new(&kind)?),
450459 None => None,
451460 };
452- Ok((kind, self.q, self.taught))
461+ Ok(ResolvedCourseFilter {
462+ kind,
463+ q: self.q,
464+ taught: self.taught,
465+ })
453466 }
454467 }
455468
@@ -483,11 +496,13 @@ async fn list_courses(
483496 Query(page): Query<PageParams>,
484497 ) -> Result<Json<Page<CourseResponse>>, AppError> {
485498 let (limit, offset) = page.resolve()?;
486- let (kind, q, taught) = filter.resolve()?;
499+ let filters = filter.resolve()?;
487500 // The filters ride inside the visible set — SQL for a manager, the
488501 // union's tail in Rust below one — so total is the filtered length
489502 // before the window is cut.
490- let courses = visible_courses_filtered(&user, &st.db, kind, q.as_deref(), taught).await?;
503+ let courses =
504+ visible_courses_filtered(&user, &st.db, filters.kind, filters.q.as_deref(), filters.taught)
505+ .await?;
491506 let total = courses.len() as i64;
492507 // Paged in the web layer: the visible set is a Rust union of two lists.
493508 let window = paginate(&courses, limit, offset);
@@ -1009,16 +1024,16 @@ mod tests {
10091024 "{kind:?}: {err:?}"
10101025 );
10111026 }
1012- let (kind, q, taught) = CourseListFilter {
1027+ let resolved = CourseListFilter {
10131028 kind: Some("club".to_string()),
10141029 q: Some(" ".to_string()),
10151030 taught: None,
10161031 }
10171032 .resolve()
10181033 .unwrap();
1019- assert_eq!(kind.as_ref().map(CourseKind::as_str), Some("club"));
1020- assert_eq!(q.as_deref(), Some(" "));
1021- assert_eq!(taught, None);
1034+ assert_eq!(resolved.kind.as_ref().map(CourseKind::as_str), Some("club"));
1035+ assert_eq!(resolved.q.as_deref(), Some(" "));
1036+ assert_eq!(resolved.taught, None);
10221037 }
10231038
10241039 /// Manager arm: kind and q narrow the catalog, total is the filtered
src/web/exams/mod.rsmodified+10 -24
@@ -255,22 +255,19 @@ async fn list_exams(
255255 ) -> Result<Json<Page<ExamResponse>>, AppError> {
256256 let (limit, offset) = page.resolve()?;
257257 window.validate()?;
258+ let params = service::exam::WindowedListParams {
259+ starts_after: window.starts_after,
260+ ends_after: window.ends_after,
261+ starts_before: window.starts_before,
262+ ends_before: window.ends_before,
263+ limit,
264+ offset,
265+ };
258266 // Visibility and the draft rule ride the same WHERE as the page and the
259267 // count: a manager+ reads the whole table, everyone else the exams of
260268 // their visible instances — a draft only where they manage the instance.
261269 let (exams, total) = if user.get_role().at_least(Role::Manager) {
262- service::exam::list_windowed(
263- &st.db,
264- None,
265- None,
266- window.starts_after,
267- window.ends_after,
268- window.starts_before,
269- window.ends_before,
270- limit,
271- offset,
272- )
273- .await?
270+ service::exam::list_windowed(&st.db, None, None, params).await?
274271 } else {
275272 let instances = visible_instances(&user, &st.db).await?;
276273 let visible: Vec<_> = instances.iter().map(|(i, _)| i.get_id().clone()).collect();
@@ -281,18 +278,7 @@ async fn list_exams(
281278 .filter(|(_, manages)| *manages)
282279 .map(|(instance, _)| instance.get_id().clone())
283280 .collect();
284- service::exam::list_windowed(
285- &st.db,
286- Some(&visible),
287- Some(&managed),
288- window.starts_after,
289- window.ends_after,
290- window.starts_before,
291- window.ends_before,
292- limit,
293- offset,
294- )
295- .await?
281+ service::exam::list_windowed(&st.db, Some(&visible), Some(&managed), params).await?
296282 };
297283 let items = exams.iter().map(ExamResponse::new).collect();
298284 Ok(Json(Page::new(items, total, limit, offset)))