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 Field {
9 pub id: Uuid,
10 pub form_id: Uuid,
11 pub field_type: String,
12}
13
14impl Debug for Field {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 f.debug_struct("Field")
17 .field("id", &self.id)
18 .field("form_id", &self.form_id)
19 .field("field_type", &self.field_type)
20 .finish()
21 }
22}
23
24pub struct NewField {
25 pub id: Uuid,
26 pub form_id: Uuid,
27 pub field_type: String,
28}
29
30impl NewField {
31 pub fn default() -> Self {
32 Self {
33 id: Uuid::new_v4(),
34 form_id: Uuid::new_v4(),
35 field_type: String::from(""),
36 }
37 }
38
39 pub async fn store(&self, pool: &PgPool) -> Result<(), anyhow::Error> {
40 sqlx::query!(
41 "INSERT INTO form_input (id, form_id, type)
42 VALUES ($1, $2, $3)",
43 self.id,
44 self.form_id,
45 self.field_type,
46 )
47 .execute(pool)
48 .await?;
49
50 Ok(())
51 }
52}