feat: add teacher_id filter to student daka query

Allow students to filter dakas by teacher_id when querying.
Both student_id and teacher_id can now coexist in the request.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-30 23:50:43 +08:00
parent 8afd3d9234
commit 0fa6d4a823
2 changed files with 13 additions and 5 deletions
+8 -2
View File
@@ -3456,13 +3456,19 @@ impl Daka {
id_org: &String,
page: i64,
page_size: i64,
id_teacher: Option<&String>,
conn: &mut PgConnection,
) -> anyhow::Result<(Vec<Daka>, i64, i64)> {
// 从students里面jsonb查询有这个`id_student`的dakas
// 可以参考Daka::find_active_dakas_by_all_teachers_with_pagination
use diesel::prelude::*;
let q_total = format!("select count(*) as result from daka where is_delete is not True AND org_id='{}' AND jsonb_path_exists(students, '$.val.users.vals[*].user_id ? (@ == \"{}\")')", id_org, id_student).to_string();
let teacher_filter = match id_teacher {
Some(tid) => format!(" AND teacher_id='{}'", tid),
None => "".to_string(),
};
let q_total = format!("select count(*) as result from daka where is_delete is not True AND org_id='{}' AND jsonb_path_exists(students, '$.val.users.vals[*].user_id ? (@ == \"{}\")'){}", id_org, id_student, teacher_filter).to_string();
debug!(
"find_active_dakas_by_student_id_with_pagination -> q_total: {:?}",
q_total
@@ -3473,7 +3479,7 @@ impl Daka {
.result;
let total_page = total_len.clone() / page_size;
let q = format!("select * from daka where is_delete is not True AND org_id='{}' AND jsonb_path_exists(students, '$.val.users.vals[*].user_id ? (@ == \"{}\")') ORDER BY updated_at DESC, created_at DESC LIMIT {} OFFSET ({} - 1) * {}", id_org, id_student, page_size.to_string(), page.to_string(), page_size.to_string()).to_string();
let q = format!("select * from daka where is_delete is not True AND org_id='{}' AND jsonb_path_exists(students, '$.val.users.vals[*].user_id ? (@ == \"{}\")'){} ORDER BY updated_at DESC, created_at DESC LIMIT {} OFFSET ({} - 1) * {}", id_org, id_student, teacher_filter, page_size.to_string(), page.to_string(), page_size.to_string()).to_string();
debug!(
"find_active_dakas_by_student_id_with_pagination -> q: {:?}",
q