diff --git a/migrations/each_user/0007_contact-groups.sql b/migrations/each_user/0007_contact-groups.sql new file mode 100644 index 0000000..f695b85 --- /dev/null +++ b/migrations/each_user/0007_contact-groups.sql @@ -0,0 +1,4 @@ +create table if not exists groups ( + contact_id number not null references contacts(id), + name text not null +); diff --git a/src/web/contact.rs b/src/web/contact.rs index 8b1fb8d..889a5cb 100644 --- a/src/web/contact.rs +++ b/src/web/contact.rs @@ -28,6 +28,13 @@ pub struct Address { pub value: String, } +#[derive(serde::Serialize, Debug)] +pub struct Group { + pub contact_id: DbId, + pub name: String, +} + + pub fn router() -> Router { Router::new() .route("/contact/new", post(self::post::contact)) @@ -94,6 +101,13 @@ mod get { .fetch_all(pool) .await?; + let groups: Vec = sqlx::query_as!( + Group, + "select * from groups where contact_id = $1", + contact_id) + .fetch_all(pool) + .await?; + let text_body: Option = sqlx::query!("select text_body from contacts where id = $1", contact_id) .fetch_one(pool) @@ -153,6 +167,15 @@ mod get { } } } + + @if groups.len() > 0 { + label { "in groups" } + #groups { + @for group in groups { + .group { (group.name) } + } + } + } }