headless_lms_server/programs/seed/seed_organizations/
credit_registration.rs1use std::sync::Arc;
5
6use headless_lms_base::config::ApplicationConfiguration;
7use headless_lms_models::{PKeyPolicy, organizations};
8use sqlx::{Pool, Postgres};
9use tracing::info;
10use uuid::Uuid;
11
12use crate::{
13 domain::models_requests::JwtKey,
14 programs::seed::{
15 seed_courses::{CommonCourseData, seed_credit_registration},
16 seed_file_storage::SeedFileStorageResult,
17 seed_users::SeedUsersResult,
18 },
19};
20
21pub const CREDIT_REGISTRATION_ORGANIZATION_ID: Uuid =
22 Uuid::from_u128(0xc5ed17ea_0000_4a5e_9e6e_c0de00000000);
23
24pub async fn seed_organization_credit_registration(
25 db_pool: Pool<Postgres>,
26 app_config: &ApplicationConfiguration,
27 seed_users_result: SeedUsersResult,
28 base_url: String,
29 jwt_key: Arc<JwtKey>,
30 _seed_file_storage_result: SeedFileStorageResult,
32) -> anyhow::Result<Uuid> {
33 info!("inserting organization credit-registration");
34 let mut conn = db_pool.acquire().await?;
35 let organization_id = organizations::insert(
36 &mut conn,
37 PKeyPolicy::Fixed(CREDIT_REGISTRATION_ORGANIZATION_ID),
38 "Credit registration fixtures",
39 "credit-registration",
40 Some("Courses the credit registration system tests own. Not meant for humans to study."),
41 false,
42 )
43 .await?;
44 drop(conn);
45
46 seed_credit_registration(
47 app_config,
48 CommonCourseData {
49 db_pool,
50 organization_id,
51 teacher_user_id: seed_users_result.teacher_user_id,
52 student_user_id: seed_users_result.student_1_user_id,
53 langs_user_id: seed_users_result.langs_user_id,
54 example_normal_user_ids: Arc::new(seed_users_result.example_normal_user_ids.to_vec()),
55 jwt_key,
56 base_url,
57 },
58 )
59 .await?;
60 Ok(organization_id)
61}