feat: support query public packages without org_id (all orgs)

Make org_id optional in find_public_course_packages API.
When omitted, return all active packages across all orgs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 10:01:31 +08:00
parent eca14626ec
commit b8f87c4d40
2 changed files with 39 additions and 2 deletions
+4 -2
View File
@@ -231,11 +231,13 @@ pub async fn find_public_course_packages(
Query(params): Query<HashMap<String, String>>,
) -> Json<HtyResponse<(Vec<CoursePackage>, i64, i64)>> {
let result = (|| -> anyhow::Result<(Vec<CoursePackage>, i64, i64)> {
let org_id = params.get("org_id").ok_or_else(|| anyhow!("org_id is required"))?;
let page = get_some_from_query_params::<i64>("page", &params).unwrap_or(1);
let page_size = get_some_from_query_params::<i64>("page_size", &params).unwrap_or(20);
let keyword = get_some_from_query_params::<String>("keyword", &params);
CoursePackage::find_all_active_by_org_with_page(org_id, &keyword, page, page_size, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())
match params.get("org_id") {
Some(org_id) => CoursePackage::find_all_active_by_org_with_page(org_id, &keyword, page, page_size, extract_conn(fetch_db_conn(&db_pool)?).deref_mut()),
None => CoursePackage::find_all_active_with_page(&keyword, page, page_size, extract_conn(fetch_db_conn(&db_pool)?).deref_mut()),
}
})();
match result {
Ok(ok) => wrap_json_ok_resp(ok),