Skip to content

Commit

Permalink
add get-chapter-completion-requirement sql function
Browse files Browse the repository at this point in the history
  • Loading branch information
george-misan committed Jul 18, 2024
1 parent 555bc1a commit 54f6a40
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Add up migration script here
ALTER TABLE course_modules
ADD COLUMN is_completion_requirement_by_chapter BOOLEAN DEFAULT NULL;
ADD COLUMN is_completion_requirement_by_chapter BOOLEAN NOT NULL DEFAULT FALSE;
COMMENT ON COLUMN course_modules.is_completion_requirement_by_chapter IS 'Determine if a chapter needs to specify its completion_requirement or not';
CREATE TABLE chapter_completion_requirements (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion services/headless-lms/models/src/course_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CourseModulesSchema {
ects_credits: Option<f32>,
enable_registering_completion_to_uh_open_university: bool,
certification_enabled: bool,
is_completion_requirement_by_chapter: Option<bool>,
is_completion_requirement_by_chapter: bool,
}
/**
* Based on [CourseModulesSchema] but completion_policy parsed and addded (and some not needeed fields removed).
Expand All @@ -44,6 +44,7 @@ pub struct CourseModule {
pub ects_credits: Option<f32>,
pub enable_registering_completion_to_uh_open_university: bool,
pub certification_enabled: bool,
pub is_completion_requirement_by_chapter: bool,
}

impl CourseModule {
Expand All @@ -63,6 +64,7 @@ impl CourseModule {
ects_credits: None,
enable_registering_completion_to_uh_open_university: false,
certification_enabled: false,
is_completion_requirement_by_chapter: false,
}
}
pub fn set_timestamps(
Expand Down Expand Up @@ -143,6 +145,7 @@ impl From<CourseModulesSchema> for CourseModule {
enable_registering_completion_to_uh_open_university: schema
.enable_registering_completion_to_uh_open_university,
certification_enabled: schema.certification_enabled,
is_completion_requirement_by_chapter: schema.is_completion_requirement_by_chapter,
}
}
}
Expand Down Expand Up @@ -651,6 +654,25 @@ WHERE id = $3
Ok(())
}

pub async fn update_is_chapter_completion_requirements(
conn: &mut PgConnection,
id: Uuid,
is_chapter_completion_requirements: bool,
) -> ModelResult<()> {
sqlx::query!(
"
UPDATE course_modules
SET is_completion_requirement_by_chapter = $2
WHERE id = $1
",
id,
is_chapter_completion_requirements,
)
.execute(conn)
.await?;
Ok(())
}

pub async fn update(
conn: &mut PgConnection,
id: Uuid,
Expand Down

0 comments on commit 54f6a40

Please sign in to comment.