feat(course-package): add org_visible to course_group and course_package_item table
Migrations:
- htyws: add org_id, org_visible columns to course_group
- htykc: create course_package_item table
Backend:
- CourseGroup: add org_visible, org_id fields; find_org_visible_by_org_id query
- CoursePackageItem: new model with sync/list API
- SUPERVISOR role check for package item management
- New endpoint: GET /api/v1/ws/find_org_visible_course_groups
- New endpoints: POST /api/v1/clazz/course-package/item/sync,
GET /api/v1/clazz/course-package/item/list/{package_id}
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
DROP INDEX IF EXISTS idx_course_group_org_visible;
|
||||
DROP INDEX IF EXISTS idx_course_group_org_id;
|
||||
|
||||
ALTER TABLE course_group
|
||||
DROP COLUMN IF EXISTS org_visible;
|
||||
|
||||
ALTER TABLE course_group
|
||||
DROP COLUMN IF EXISTS org_id;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE course_group
|
||||
ADD COLUMN IF NOT EXISTS org_id varchar;
|
||||
|
||||
ALTER TABLE course_group
|
||||
ADD COLUMN IF NOT EXISTS org_visible boolean DEFAULT false;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_course_group_org_id ON course_group (org_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_course_group_org_visible ON course_group (org_visible);
|
||||
@@ -546,6 +546,8 @@ pub struct ReqCourseGroup {
|
||||
pub updated_at: Option<NaiveDateTime>,
|
||||
pub updated_by: Option<String>,
|
||||
pub teachers: Option<MultiVals<TeacherIdAndName>>,
|
||||
pub org_id: Option<String>,
|
||||
pub org_visible: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
@@ -5239,6 +5241,8 @@ pub struct CourseGroup {
|
||||
pub updated_at: Option<NaiveDateTime>,
|
||||
pub updated_by: Option<String>,
|
||||
pub teachers: Option<MultiVals<TeacherIdAndName>>,
|
||||
pub org_id: Option<String>,
|
||||
pub org_visible: Option<bool>,
|
||||
}
|
||||
|
||||
impl CourseGroup {
|
||||
@@ -5270,6 +5274,23 @@ impl CourseGroup {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_org_visible_by_org_id(
|
||||
in_org_id: &str,
|
||||
conn: &mut PgConnection,
|
||||
) -> anyhow::Result<Vec<CourseGroup>> {
|
||||
let q = course_group::table
|
||||
.filter(course_group::org_id.eq(in_org_id))
|
||||
.filter(course_group::org_visible.eq(true))
|
||||
.order((course_group::updated_at.desc(), course_group::created_at.desc()));
|
||||
match q.load::<CourseGroup>(conn) {
|
||||
Ok(list) => Ok(list),
|
||||
Err(e) => Err(anyhow!(HtyErr {
|
||||
code: HtyErrCode::DbErr,
|
||||
reason: Some(e.to_string()),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create(
|
||||
in_section_group: &CourseGroup,
|
||||
conn: &mut PgConnection,
|
||||
@@ -5332,6 +5353,8 @@ impl CourseGroup {
|
||||
updated_at: self.updated_at.clone(),
|
||||
updated_by: self.updated_by.clone(),
|
||||
teachers: self.teachers.clone(),
|
||||
org_id: self.org_id.clone(),
|
||||
org_visible: self.org_visible.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5350,6 +5373,8 @@ impl CourseGroup {
|
||||
updated_at: Some(current_local_datetime()),
|
||||
updated_by: c_in_req.updated_by,
|
||||
teachers: c_in_req.teachers,
|
||||
org_id: c_in_req.org_id,
|
||||
org_visible: c_in_req.org_visible,
|
||||
})
|
||||
} else {
|
||||
Ok(CourseGroup {
|
||||
@@ -5363,6 +5388,8 @@ impl CourseGroup {
|
||||
updated_at: Some(current_local_datetime()),
|
||||
updated_by: c_in_req.updated_by,
|
||||
teachers: c_in_req.teachers,
|
||||
org_id: c_in_req.org_id,
|
||||
org_visible: c_in_req.org_visible,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ diesel::table! {
|
||||
updated_at -> Nullable<Timestamp>,
|
||||
updated_by -> Nullable<Varchar>,
|
||||
teachers -> Nullable<Jsonb>,
|
||||
org_id -> Nullable<Varchar>,
|
||||
org_visible -> Nullable<Bool>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user