headless_lms_models/
certificate_fonts.rs

1use crate::prelude::*;
2
3#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
4#[cfg_attr(feature = "ts_rs", derive(TS))]
5pub struct CertificateFont {
6    pub id: Uuid,
7    pub created_at: DateTime<Utc>,
8    pub updated_at: DateTime<Utc>,
9    pub deleted_at: Option<DateTime<Utc>>,
10    pub file_path: String,
11    pub file_upload_id: Uuid,
12    pub display_name: String,
13}
14
15#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
16#[cfg_attr(feature = "ts_rs", derive(TS))]
17pub struct NewCertificateFont {
18    pub file_path: String,
19    pub file_upload_id: Uuid,
20    pub display_name: String,
21}
22
23pub async fn insert(
24    conn: &mut PgConnection,
25    certificate_font: &NewCertificateFont,
26) -> ModelResult<CertificateFont> {
27    let res = sqlx::query_as!(
28        CertificateFont,
29        "
30INSERT INTO certificate_fonts (
31    file_path,
32    file_upload_id,
33    display_name
34  )
35VALUES ($1, $2, $3)
36RETURNING *
37",
38        certificate_font.file_path,
39        certificate_font.file_upload_id,
40        certificate_font.display_name
41    )
42    .fetch_one(conn)
43    .await?;
44    Ok(res)
45}
46
47pub async fn get_all(conn: &mut PgConnection) -> ModelResult<Vec<CertificateFont>> {
48    let res = sqlx::query_as!(
49        CertificateFont,
50        "
51SELECT *
52FROM certificate_fonts
53WHERE deleted_at IS NULL
54"
55    )
56    .fetch_all(conn)
57    .await?;
58    Ok(res)
59}