headless_lms_models/
chapter_lock_action_logs.rs1use crate::prelude::*;
2use crate::user_chapter_locking_statuses::ChapterLockingStatus;
3use utoipa::ToSchema;
4
5#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, sqlx::FromRow, ToSchema)]
6pub struct ChapterLockActionLog {
7 pub id: Uuid,
8 pub actor_user_id: Option<Uuid>,
9 pub target_user_id: Uuid,
10 pub course_id: Uuid,
11 pub chapter_id: Uuid,
12 pub status: ChapterLockingStatus,
13 pub created_at: DateTime<Utc>,
14 pub updated_at: DateTime<Utc>,
15 pub deleted_at: Option<DateTime<Utc>>,
16}
17
18pub async fn insert(
19 conn: &mut PgConnection,
20 actor_user_id: Option<Uuid>,
21 target_user_id: Uuid,
22 course_id: Uuid,
23 chapter_id: Uuid,
24 status: ChapterLockingStatus,
25) -> ModelResult<ChapterLockActionLog> {
26 let row = sqlx::query_as!(
27 ChapterLockActionLog,
28 r#"
29INSERT INTO chapter_lock_action_logs (
30 actor_user_id,
31 target_user_id,
32 course_id,
33 chapter_id,
34 status
35)
36VALUES ($1, $2, $3, $4, $5)
37RETURNING id,
38 actor_user_id,
39 target_user_id,
40 course_id,
41 chapter_id,
42 status as "status: ChapterLockingStatus",
43 created_at,
44 updated_at,
45 deleted_at
46 "#,
47 actor_user_id,
48 target_user_id,
49 course_id,
50 chapter_id,
51 status as ChapterLockingStatus,
52 )
53 .fetch_one(conn)
54 .await?;
55 Ok(row)
56}