headless_lms_server/programs/seed/seed_courses/
seed_material_reference_course.rs1use crate::programs::seed::builder::chapter::ChapterBuilder;
2use crate::programs::seed::builder::context::SeedContext;
3use crate::programs::seed::builder::course::{CourseBuilder, CourseInstanceConfig};
4use crate::programs::seed::builder::module::ModuleBuilder;
5use crate::programs::seed::builder::page::PageBuilder;
6use crate::programs::seed::seed_courses::CommonCourseData;
7use anyhow::Result;
8use headless_lms_models::roles::UserRole;
9use headless_lms_utils::{attributes, document_schema_processor::GutenbergBlock};
10use tracing::info;
11use uuid::Uuid;
12
13pub async fn seed_material_reference_course(
14 course_id: Uuid,
15 course_name: &str,
16 course_slug: &str,
17 common_course_data: CommonCourseData,
18) -> Result<Uuid> {
19 let CommonCourseData {
20 db_pool,
21 organization_id: org,
22 teacher_user_id,
23 student_user_id: _student,
24 langs_user_id: _langs_user_id,
25 example_normal_user_ids: _users,
26 jwt_key: _jwt_key,
27 base_url: _base_url,
28 } = common_course_data;
29
30 let mut conn = db_pool.acquire().await?;
31 let cx = SeedContext {
32 teacher: teacher_user_id,
33 org,
34 base_course_ns: course_id,
35 };
36
37 info!("inserting material reference course {}", course_name);
38
39 let course = CourseBuilder::new(course_name, course_slug)
40 .desc("Minimal course for testing material references.")
41 .course_id(course_id)
42 .instance(CourseInstanceConfig {
43 name: None,
44 description: None,
45 support_email: None,
46 teacher_in_charge_name: "admin".to_string(),
47 teacher_in_charge_email: "admin@example.com".to_string(),
48 opening_time: None,
49 closing_time: None,
50 instance_id: Some(cx.v5(b"material-ref-instance-001")),
51 })
52 .role(teacher_user_id, UserRole::Teacher)
53 .module(
54 ModuleBuilder::new().order(0).chapter(
55 ChapterBuilder::new(1, "Chapter 1")
56 .fixed_ids(
57 cx.v5(b"material-ref-chapter-001"),
58 cx.v5(b"material-ref-front-page-001"),
59 )
60 .page(
61 PageBuilder::new("/chapter-1/page-1", "Page One")
62 .block(
63 GutenbergBlock::block_with_name_and_attributes(
64 "core/heading",
65 attributes! {
66 "content": "Page One",
67 "level": 1,
68 },
69 )
70 .with_id(cx.v5(b"material-ref-heading-001")),
71 )
72 .block(
73 GutenbergBlock::paragraph("The abacus is one of the oldest known calculating tools, with origins tracing back to ancient Mesopotamia and China. Often consisting of a wooden frame with rows of beads, it has been used for centuries as a reliable aid in performing arithmetic operations. Its simplicity and effectiveness made it a cornerstone of commerce and education across many civilizations.")
74 .with_id(cx.v5(b"material-ref-abacus-001")),
75 )
76 .block(
77 GutenbergBlock::paragraph("Throughout history, the abacus has taken on various forms, from the Roman hand abacus to the Chinese suanpan and the Japanese soroban. Each design introduced unique innovations, optimizing calculation methods for their respective regions. Despite the rise of digital calculators, the abacus continues to be used in some educational settings to teach arithmetic concepts and mental math techniques.")
78 .with_id(cx.v5(b"material-ref-abacus-002")),
79 )
80 .block(
81 GutenbergBlock::paragraph("Modern interest in the abacus has grown as educators recognize its value in developing number sense and concentration in children. Competitions in mental abacus calculation demonstrate just how powerful this tool can be when mastered. While it may seem outdated, the abacus remains a symbol of timeless ingenuity and practical problem-solving.")
82 .with_id(cx.v5(b"material-ref-abacus-003")),
83 )
84 .block(
85 GutenbergBlock::paragraph("In recent years, digital adaptations of the abacus have also emerged, blending traditional methods with modern interfaces. These tools not only preserve the historical legacy of the abacus but also make it more accessible to new generations of learners. Whether used physically or virtually, the abacus continues to bridge the gap between tactile learning and abstract thinking.")
86 .with_id(cx.v5(b"material-ref-abacus-004")),
87 ),
88 ),
89 ),
90 );
91
92 let (course, _default_instance, _last_module) = course.seed(&mut conn, &cx).await?;
93
94 Ok(course.id)
95}