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:
+22
-3
@@ -614,11 +614,30 @@ pub fn raw_find_course_group_by_ids(
|
|||||||
.clone()
|
.clone()
|
||||||
.vals
|
.vals
|
||||||
.ok_or_else(|| anyhow!("vals is required"))?;
|
.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![];
|
let mut res = vec![];
|
||||||
for id in c_ids {
|
for id in c_ids {
|
||||||
let item =
|
let item = CourseGroup::find_by_id(&id, conn)?;
|
||||||
CourseGroup::find_by_id(&id, extract_conn(fetch_db_conn(&db_pool)?).deref_mut())?;
|
let mut req = item.to_req();
|
||||||
let 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)
|
res.push(req)
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|||||||
@@ -557,6 +557,7 @@ pub struct ReqCourseGroup {
|
|||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub group_name: Option<String>,
|
pub group_name: Option<String>,
|
||||||
pub course_section_ids: Option<MultiVals<String>>,
|
pub course_section_ids: Option<MultiVals<String>>,
|
||||||
|
pub course_sections: Option<Vec<ReqCourseSection>>,
|
||||||
pub created_at: Option<NaiveDateTime>,
|
pub created_at: Option<NaiveDateTime>,
|
||||||
pub created_by: Option<String>,
|
pub created_by: Option<String>,
|
||||||
pub updated_at: Option<NaiveDateTime>,
|
pub updated_at: Option<NaiveDateTime>,
|
||||||
@@ -5422,6 +5423,7 @@ impl CourseGroup {
|
|||||||
id: Some(self.id.clone()),
|
id: Some(self.id.clone()),
|
||||||
group_name: Some(self.group_name.clone()),
|
group_name: Some(self.group_name.clone()),
|
||||||
course_section_ids: self.course_section_ids.clone(),
|
course_section_ids: self.course_section_ids.clone(),
|
||||||
|
course_sections: None,
|
||||||
created_at: self.created_at.clone(),
|
created_at: self.created_at.clone(),
|
||||||
created_by: self.created_by.clone(),
|
created_by: self.created_by.clone(),
|
||||||
updated_at: self.updated_at.clone(),
|
updated_at: self.updated_at.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user