1use std::fmt::Debug;
2
3use serde::{Deserialize, Serialize};
4use sqlx::PgPool;
5use uuid::Uuid;
6
7#[derive(sqlx::FromRow, Serialize, Deserialize, Clone)]
8pub struct Form {
9 pub id: Uuid,
10 pub qr_code_id: Uuid,
11 pub account_id: Uuid,
12}
13
14impl Debug for Form {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 f.debug_struct("Form")
17 .field("id", &self.id)
18 .field("qr_code_id", &self.qr_code_id)
19 .field("account_id", &self.account_id)
20 .finish()
21 }
22}
23
24pub struct NewForm {
25 pub id: Uuid,
26 pub qr_code_id: Uuid,
27 pub account_id: Uuid,
28}
29
30impl NewForm {
31 pub fn default() -> Self {
32 Self {
33 id: Uuid::new_v4(),
34 qr_code_id: Uuid::new_v4(),
35 account_id: Uuid::new_v4(),
36 }
37 }
38
39 pub async fn store(&self, pool: &PgPool) -> Result<(), anyhow::Error> {
40 sqlx::query!(
41 "INSERT INTO form (id, qr_code_id, account_id)
42 VALUES ($1, $2, $3)",
43 self.id,
44 self.qr_code_id,
45 self.account_id
46 )
47 .execute(pool)
48 .await?;
49
50 Ok(())
51 }
52}