From 09111caaa556a6eb1d5d9717a107031fe6722aa3 Mon Sep 17 00:00:00 2001 From: William Zhang Date: Wed, 20 Sep 2023 16:03:56 +1000 Subject: [PATCH] feat: implemented pronouns in backend --- .../2023-09-20-052638_user_pronouns/down.sql | 2 + .../2023-09-20-052638_user_pronouns/up.sql | 2 + backend/seed_data/src/seed.rs | 38 ++++++++++++++++--- backend/server/src/auth.rs | 4 +- backend/server/src/database/models.rs | 2 + backend/server/src/database/schema.rs | 1 + 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 backend/migrations/2023-09-20-052638_user_pronouns/down.sql create mode 100644 backend/migrations/2023-09-20-052638_user_pronouns/up.sql diff --git a/backend/migrations/2023-09-20-052638_user_pronouns/down.sql b/backend/migrations/2023-09-20-052638_user_pronouns/down.sql new file mode 100644 index 00000000..6cc4cb64 --- /dev/null +++ b/backend/migrations/2023-09-20-052638_user_pronouns/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE users +DROP COLUMN pronouns; diff --git a/backend/migrations/2023-09-20-052638_user_pronouns/up.sql b/backend/migrations/2023-09-20-052638_user_pronouns/up.sql new file mode 100644 index 00000000..ef54ae9c --- /dev/null +++ b/backend/migrations/2023-09-20-052638_user_pronouns/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE users + ADD COLUMN pronouns TEXT DEFAULT '' NOT NULL; diff --git a/backend/seed_data/src/seed.rs b/backend/seed_data/src/seed.rs index c34e0ad9..f542faa2 100644 --- a/backend/seed_data/src/seed.rs +++ b/backend/seed_data/src/seed.rs @@ -25,6 +25,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2019, gender: UserGender::Unspecified, + pronouns: "they/them".to_string(), superuser: true, }, NewUser { @@ -34,6 +35,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2019, gender: UserGender::Unspecified, + pronouns: "".to_string(), superuser: false, }, NewUser { @@ -43,6 +45,7 @@ pub fn seed() { degree_name: "B. Eng (Software)".to_string(), degree_starting_year: 2019, gender: UserGender::Male, + pronouns: "he/him".to_string(), superuser: false, }, NewUser { @@ -52,6 +55,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2020, gender: UserGender::Female, + pronouns: "she/her".to_string(), superuser: false, }, NewUser { @@ -61,6 +65,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2019, gender: UserGender::Male, + pronouns: "he/him".to_string(), superuser: false, }, NewUser { @@ -70,6 +75,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2020, gender: UserGender::Male, + pronouns: "he/him".to_string(), superuser: false, }, NewUser { @@ -79,6 +85,7 @@ pub fn seed() { degree_name: "B. CompSci".to_string(), degree_starting_year: 2020, gender: UserGender::Male, + pronouns: "he/him".to_string(), superuser: false, }, ]; @@ -93,10 +100,22 @@ pub fn seed() { // create two organisations let csesoc_org_logo_id = "d6b7b23d-064b-40f2-9b73-9a4cd32ee9c6"; let degrees_org_logo_id = "adebf7f3-aa1e-4712-b5ca-051430bfaf8e"; - let csesoc_org_logo = try_decode_bytes(std::fs::read("./assets/csesoc_logo.png").unwrap()).expect("./assets/csesoc_logo.png missing!"); - let degrees_org_logo = try_decode_bytes(std::fs::read("./assets/180DC.png").unwrap()).expect("./assets/180DC.png missing!"); - save_image(csesoc_org_logo, backend::images::ImageLocation::ORGANISATIONS, csesoc_org_logo_id).expect("Failed saving CSESoc Logo"); - save_image(degrees_org_logo, backend::images::ImageLocation::ORGANISATIONS, degrees_org_logo_id).expect("Failed saving 180DC Logo"); + let csesoc_org_logo = try_decode_bytes(std::fs::read("./assets/csesoc_logo.png").unwrap()) + .expect("./assets/csesoc_logo.png missing!"); + let degrees_org_logo = try_decode_bytes(std::fs::read("./assets/180DC.png").unwrap()) + .expect("./assets/180DC.png missing!"); + save_image( + csesoc_org_logo, + backend::images::ImageLocation::ORGANISATIONS, + csesoc_org_logo_id, + ) + .expect("Failed saving CSESoc Logo"); + save_image( + degrees_org_logo, + backend::images::ImageLocation::ORGANISATIONS, + degrees_org_logo_id, + ) + .expect("Failed saving 180DC Logo"); let orgs = vec![ NewOrganisation { @@ -151,8 +170,15 @@ pub fn seed() { // create peer mentoring campaign for csesoc let peer_mentoring_logo_id = "523fde49-027a-4fc8-b296-aaefe9e215d6"; - let peer_mentoring_logo = try_decode_bytes(std::fs::read("./assets/csesoc_peer_mentoring.jpg").unwrap()).expect("./assets/csesoc_peer_mentoring.jpg missing!"); - save_image(peer_mentoring_logo, backend::images::ImageLocation::CAMPAIGNS, peer_mentoring_logo_id).expect("Failed saving Peer Mentoring Logo"); + let peer_mentoring_logo = + try_decode_bytes(std::fs::read("./assets/csesoc_peer_mentoring.jpg").unwrap()) + .expect("./assets/csesoc_peer_mentoring.jpg missing!"); + save_image( + peer_mentoring_logo, + backend::images::ImageLocation::CAMPAIGNS, + peer_mentoring_logo_id, + ) + .expect("Failed saving Peer Mentoring Logo"); let new_campaign = NewCampaign { name: "2022 Peer Mentor Recruitment".to_string(), diff --git a/backend/server/src/auth.rs b/backend/server/src/auth.rs index 1820b939..4f7e805e 100644 --- a/backend/server/src/auth.rs +++ b/backend/server/src/auth.rs @@ -2,7 +2,7 @@ use crate::error::JsonErr; use crate::{ database::{ models::{NewUser, User}, - schema::{UserGender}, + schema::UserGender, Database, }, state::ApiState, @@ -281,6 +281,7 @@ pub struct SignUpBody { degree_name: String, degree_starting_year: u32, gender: UserGender, + pronouns: String, } #[derive(Serialize)] @@ -350,6 +351,7 @@ pub async fn signup( degree_name: body.degree_name.to_string(), degree_starting_year: body.degree_starting_year as i32, gender: body.gender, + pronouns: body.pronouns.to_string(), superuser: User::get_number(conn) == 0, }; diff --git a/backend/server/src/database/models.rs b/backend/server/src/database/models.rs index ded34e94..d4236081 100644 --- a/backend/server/src/database/models.rs +++ b/backend/server/src/database/models.rs @@ -24,6 +24,7 @@ pub struct User { pub degree_name: String, pub degree_starting_year: i32, pub gender: UserGender, + pub pronouns: String, pub superuser: bool, pub created_at: NaiveDateTime, pub updated_at: NaiveDateTime, @@ -51,6 +52,7 @@ pub struct NewUser { pub degree_name: String, pub degree_starting_year: i32, pub gender: UserGender, + pub pronouns: String, pub superuser: bool, } diff --git a/backend/server/src/database/schema.rs b/backend/server/src/database/schema.rs index 783138d4..a5a526d4 100644 --- a/backend/server/src/database/schema.rs +++ b/backend/server/src/database/schema.rs @@ -161,6 +161,7 @@ table! { degree_name -> Text, degree_starting_year -> Int4, gender -> UserGenderMapping, + pronouns -> Text, superuser -> Bool, created_at -> Timestamp, updated_at -> Timestamp,