headless_lms_models/
course_language_groups.rs1use crate::prelude::*;
2
3#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
4pub struct CourseLanguageVersion {
5 pub id: Uuid,
6 pub created_at: DateTime<Utc>,
7 pub updated_at: DateTime<Utc>,
8 pub deleted_at: Option<DateTime<Utc>>,
9 pub slug: String,
10}
11
12pub async fn insert(
13 conn: &mut PgConnection,
14 pkey_policy: PKeyPolicy<Uuid>,
15 slug: &str,
16) -> ModelResult<Uuid> {
17 let res = sqlx::query!(
18 "
19INSERT INTO course_language_groups (id, slug)
20VALUES ($1, $2)
21RETURNING id
22 ",
23 pkey_policy.into_uuid(),
24 slug,
25 )
26 .fetch_one(conn)
27 .await?;
28 Ok(res.id)
29}
30
31pub async fn get_slug_by_id(
33 conn: &mut PgConnection,
34 course_language_group_id: Uuid,
35) -> ModelResult<Option<String>> {
36 let row = sqlx::query_scalar!(
37 "
38SELECT slug
39FROM course_language_groups
40WHERE id = $1
41 AND deleted_at IS NULL",
42 course_language_group_id
43 )
44 .fetch_optional(conn)
45 .await?;
46 Ok(row)
47}