This commit is contained in:
parent
e3e77cbae3
commit
1f05189ec6
2 changed files with 27 additions and 0 deletions
4
migrations/each_user/0007_contact-groups.sql
Normal file
4
migrations/each_user/0007_contact-groups.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
create table if not exists groups (
|
||||||
|
contact_id number not null references contacts(id),
|
||||||
|
name text not null
|
||||||
|
);
|
||||||
|
|
@ -28,6 +28,13 @@ pub struct Address {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, Debug)]
|
||||||
|
pub struct Group {
|
||||||
|
pub contact_id: DbId,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn router() -> Router<AppState> {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/contact/new", post(self::post::contact))
|
.route("/contact/new", post(self::post::contact))
|
||||||
|
|
@ -94,6 +101,13 @@ mod get {
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let groups: Vec<Group> = sqlx::query_as!(
|
||||||
|
Group,
|
||||||
|
"select * from groups where contact_id = $1",
|
||||||
|
contact_id)
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let text_body: Option<String> =
|
let text_body: Option<String> =
|
||||||
sqlx::query!("select text_body from contacts where id = $1", contact_id)
|
sqlx::query!("select text_body from contacts where id = $1", contact_id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
|
|
@ -153,6 +167,15 @@ mod get {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if groups.len() > 0 {
|
||||||
|
label { "in groups" }
|
||||||
|
#groups {
|
||||||
|
@for group in groups {
|
||||||
|
.group { (group.name) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue