From f933b40fe2c383be0b762cd16aff16348f4d5bd5 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 20 Sep 2021 16:06:16 -0400 Subject: [PATCH] Add "interest" booleans to signups form Co-Authored-By: Max Brunsfeld --- ...0210920192001_add_interests_to_signups.sql | 4 ++++ server/src/db.rs | 22 ++++++++++++++++--- server/src/home.rs | 17 ++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 server/migrations/20210920192001_add_interests_to_signups.sql diff --git a/server/migrations/20210920192001_add_interests_to_signups.sql b/server/migrations/20210920192001_add_interests_to_signups.sql new file mode 100644 index 0000000000000000000000000000000000000000..2457abfc757a3d3c6171d9639e2c280981689ead --- /dev/null +++ b/server/migrations/20210920192001_add_interests_to_signups.sql @@ -0,0 +1,4 @@ +ALTER TABLE "signups" + ADD "wants_releases" BOOLEAN, + ADD "wants_updates" BOOLEAN, + ADD "wants_community" BOOLEAN; \ No newline at end of file diff --git a/server/src/db.rs b/server/src/db.rs index 14ad85b68af2e06148c02d12dc74790fa2b5b0c9..210b3643d1b3d3fe9ecc7bb29a26a93560747195 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -47,17 +47,30 @@ impl Db { github_login: &str, email_address: &str, about: &str, + wants_releases: bool, + wants_updates: bool, + wants_community: bool, ) -> Result { test_support!(self, { let query = " - INSERT INTO signups (github_login, email_address, about) - VALUES ($1, $2, $3) + INSERT INTO signups ( + github_login, + email_address, + about, + wants_releases, + wants_updates, + wants_community + ) + VALUES ($1, $2, $3, $4, $5, $6) RETURNING id "; sqlx::query_scalar(query) .bind(github_login) .bind(email_address) .bind(about) + .bind(wants_releases) + .bind(wants_updates) + .bind(wants_community) .fetch_one(&self.pool) .await .map(SignupId) @@ -501,6 +514,9 @@ pub struct Signup { pub github_login: String, pub email_address: String, pub about: String, + pub wants_releases: Option, + pub wants_updates: Option, + pub wants_community: Option, } id_type!(ChannelId); @@ -731,4 +747,4 @@ pub mod tests { assert_eq!(msg1_id, msg3_id); assert_eq!(msg2_id, msg4_id); } -} +} \ No newline at end of file diff --git a/server/src/home.rs b/server/src/home.rs index 25adde3a0f2fed3d7b11c107e23dcbfdf1d67bac..10336f2fb77613b6ee9b1ef4b8a73c582daa84c5 100644 --- a/server/src/home.rs +++ b/server/src/home.rs @@ -61,6 +61,12 @@ async fn post_signup(mut request: Request) -> tide::Result { github_login: String, email_address: String, about: String, + #[serde(default)] + wants_releases: bool, + #[serde(default)] + wants_updates: bool, + #[serde(default)] + wants_community: bool, } let mut form: Form = request.body_form().await?; @@ -75,7 +81,14 @@ async fn post_signup(mut request: Request) -> tide::Result { // Save signup in the database request .db() - .create_signup(&form.github_login, &form.email_address, &form.about) + .create_signup( + &form.github_login, + &form.email_address, + &form.about, + form.wants_releases, + form.wants_updates, + form.wants_community, + ) .await?; let layout_data = request.layout_data().await?; @@ -101,4 +114,4 @@ async fn get_release_asset(request: Request) -> tide::Result { .content_type(mime::BYTE_STREAM) .body(body) .build()) -} +} \ No newline at end of file