fix: include resolved course_sections in course group API response

ReqCourseGroup now includes a course_sections field populated with
full section objects when returned by find_course_group_by_ids,
fixing unpublished package detail display in the frontend.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 19:04:56 +08:00
parent f534230af7
commit 723787a8ea
2 changed files with 24 additions and 3 deletions
+22 -3
View File
@@ -614,11 +614,30 @@ pub fn raw_find_course_group_by_ids(
.clone()
.vals
.ok_or_else(|| anyhow!("vals is required"))?;
let mut conn_holder = extract_conn(fetch_db_conn(&db_pool)?);
let conn = conn_holder.deref_mut();
let mut res = vec![];
for id in c_ids {
let item =
CourseGroup::find_by_id(&id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
let req = item.to_req();
let item = CourseGroup::find_by_id(&id, conn)?;
let mut req = item.to_req();
// Resolve course_section_ids into full course_sections objects
if let Some(ref section_ids) = item.course_section_ids {
if let Some(ref ids) = section_ids.vals {
let mut sections = Vec::new();
for sid in ids {
match CourseSection::find_by_id(sid, conn) {
Ok(section) => sections.push(section.to_req()),
Err(e) => error!(
"raw_find_course_group_by_ids -> failed to find course_section {}: {}",
sid, e
),
}
}
if !sections.is_empty() {
req.course_sections = Some(sections);
}
}
}
res.push(req)
}
Ok(res)
+2
View File
@@ -557,6 +557,7 @@ pub struct ReqCourseGroup {
pub id: Option<String>,
pub group_name: Option<String>,
pub course_section_ids: Option<MultiVals<String>>,
pub course_sections: Option<Vec<ReqCourseSection>>,
pub created_at: Option<NaiveDateTime>,
pub created_by: Option<String>,
pub updated_at: Option<NaiveDateTime>,
@@ -5422,6 +5423,7 @@ impl CourseGroup {
id: Some(self.id.clone()),
group_name: Some(self.group_name.clone()),
course_section_ids: self.course_section_ids.clone(),
course_sections: None,
created_at: self.created_at.clone(),
created_by: self.created_by.clone(),
updated_at: self.updated_at.clone(),