From eacf3b070077eb33f3ed9b91659c8cd03a0a7377 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 8 Aug 2023 11:11:29 +0200 Subject: [PATCH] Add new field --- .../migrations/2023-05-24-102711_create_users/up.sql | 1 + geneit_backend/src/controllers/members_controller.rs | 3 +++ geneit_backend/src/models.rs | 1 + geneit_backend/src/schema.rs | 1 + geneit_backend/src/services/members_service.rs | 1 + 5 files changed, 7 insertions(+) diff --git a/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql b/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql index f116e8e..7c39e92 100644 --- a/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql +++ b/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql @@ -61,6 +61,7 @@ CREATE TABLE members ( birth_year smallint NULL, birth_month smallint NULL, birth_day smallint NULL, + dead BOOLEAN NOT NULL DEFAULT FALSE, death_year smallint NULL, death_month smallint NULL, death_day smallint NULL, diff --git a/geneit_backend/src/controllers/members_controller.rs b/geneit_backend/src/controllers/members_controller.rs index 516419c..2b7bb68 100644 --- a/geneit_backend/src/controllers/members_controller.rs +++ b/geneit_backend/src/controllers/members_controller.rs @@ -45,6 +45,8 @@ pub struct MemberRequest { father: Option, #[serde(flatten, with = "prefix_birth")] birth: Option, + #[serde(default)] + dead: bool, #[serde(flatten, with = "prefix_death")] death: Option, note: Option, @@ -221,6 +223,7 @@ impl MemberRequest { member.birth_month = self.birth.as_ref().map(|m| m.month).unwrap_or_default(); member.birth_day = self.birth.as_ref().map(|m| m.day).unwrap_or_default(); + member.dead = self.dead; member.death_year = self.death.as_ref().map(|m| m.year).unwrap_or_default(); member.death_month = self.death.as_ref().map(|m| m.month).unwrap_or_default(); member.death_day = self.death.as_ref().map(|m| m.day).unwrap_or_default(); diff --git a/geneit_backend/src/models.rs b/geneit_backend/src/models.rs index ce27d26..15fb71d 100644 --- a/geneit_backend/src/models.rs +++ b/geneit_backend/src/models.rs @@ -242,6 +242,7 @@ pub struct Member { pub birth_year: Option, pub birth_month: Option, pub birth_day: Option, + pub dead: bool, pub death_year: Option, pub death_month: Option, pub death_day: Option, diff --git a/geneit_backend/src/schema.rs b/geneit_backend/src/schema.rs index 3bb9698..bda2564 100644 --- a/geneit_backend/src/schema.rs +++ b/geneit_backend/src/schema.rs @@ -50,6 +50,7 @@ diesel::table! { birth_year -> Nullable, birth_month -> Nullable, birth_day -> Nullable, + dead -> Bool, death_year -> Nullable, death_month -> Nullable, death_day -> Nullable, diff --git a/geneit_backend/src/services/members_service.rs b/geneit_backend/src/services/members_service.rs index cb1f547..30257fa 100644 --- a/geneit_backend/src/services/members_service.rs +++ b/geneit_backend/src/services/members_service.rs @@ -75,6 +75,7 @@ pub async fn update(member: &mut Member) -> anyhow::Result<()> { members::dsl::birth_year.eq(member.birth_year), members::dsl::birth_month.eq(member.birth_month), members::dsl::birth_day.eq(member.birth_day), + members::dsl::dead.eq(member.dead), members::dsl::death_year.eq(member.death_year), members::dsl::death_month.eq(member.death_month), members::dsl::death_day.eq(member.death_day),