headless_lms_server/programs/seed/seed_courses/
seed_glossary.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 crate::programs::seed::seed_helpers::paragraph;
8use anyhow::Result;
9use chrono::Utc;
10use headless_lms_models::roles::UserRole;
11use headless_lms_utils::{attributes, document_schema_processor::GutenbergBlock};
12use tracing::info;
13use uuid::Uuid;
14
15use super::super::seed_users::SeedUsersResult;
16
17pub async fn seed_glossary_course(
18 course_id: Uuid,
19 course_name: &str,
20 course_slug: &str,
21 common_course_data: CommonCourseData,
22 seed_users_result: SeedUsersResult,
23) -> Result<Uuid> {
24 let CommonCourseData {
25 db_pool,
26 organization_id: org,
27 teacher_user_id,
28 student_user_id: _student,
29 langs_user_id: _langs_user_id,
30 example_normal_user_ids: _users,
31 jwt_key: _jwt_key,
32 base_url: _base_url,
33 } = common_course_data;
34
35 let mut conn = db_pool.acquire().await?;
36 let cx = SeedContext {
37 teacher: teacher_user_id,
38 org,
39 base_course_ns: course_id,
40 };
41
42 info!("Inserting glossary course {}", course_name);
43
44 let course = CourseBuilder::new(course_name, course_slug)
45 .desc("Sample course for glossary.")
46 .course_id(course_id)
47 .instance(CourseInstanceConfig {
48 name: None,
49 description: None,
50 support_email: None,
51 teacher_in_charge_name: "admin".to_string(),
52 teacher_in_charge_email: "admin@example.com".to_string(),
53 opening_time: None,
54 closing_time: None,
55 instance_id: Some(cx.v5(b"instance:default")),
56 })
57 .role(seed_users_result.teacher_user_id, UserRole::Teacher)
58 .top_level_page(
59 "/glossary",
60 "Glossary",
61 1,
62 false,
63 Some(vec![GutenbergBlock {
64 name: "moocfi/glossary".to_string(),
65 is_valid: true,
66 client_id: cx.v5(b"glossary-page-block"),
67 attributes: attributes! {},
68 inner_blocks: vec![],
69 }]),
70 )
71 .module(
72 ModuleBuilder::new()
73 .order(0)
74 .register_to_open_university(false)
75 .automatic_completion(Some(1), Some(1), false)
76 .chapter(
77 ChapterBuilder::new(1, "Introduction")
78 .opens(Utc::now())
79 .fixed_ids(cx.v5(b"chapter:1"), cx.v5(b"chapter:1:instance"))
80 .page(
81 PageBuilder::new("/chapter-1/page-1", "Page One").block(paragraph(
82 "This course uses many TLAs. Why? Because why use one word when three letters will do? It's like a secret code, but everyone knows it. You'll encounter CS, HDD, KB, and many more. When shopping for a new computer, you might hear someone say that an SSD makes everything faster, but don't worry if you're not sure what that means yet. By the end of this course, you'll be fluent in the language of three-letter abbreviations.",
83 cx.v5(b"page:1:1:block:intro"),
84 )),
85 ),
86 ),
87 )
88 .glossary_entry(
89 "TLA",
90 "Three Letter Acronym - because developers love abbreviations more than they love coffee.",
91 )
92 .glossary_entry(
93 "CS",
94 "Computer science. Computer science is an essential part of being successful in your life. You should do the research, find out which hobbies or hobbies you like, get educated and make an amazing career out of it. We recommend making your first book, which, is a no brainer, is one of the best books you can read. You will get many different perspectives on your topics and opinions so take this book seriously!",
95 )
96 .glossary_entry(
97 "HDD",
98 "Hard disk drive. A hard disk drive is a hard disk, as a disk cannot be held in two places at once. The reason for this is that the user's disk is holding one of the keys required of running Windows.",
99 )
100 .glossary_entry("KB", "Keyboard.");
101
102 let (course, _default_instance, _last_module) = course.seed(&mut conn, &cx).await?;
103
104 Ok(course.id)
105}