Skip to content

Commit

Permalink
feat: implemented pronouns in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dhj03 committed Sep 20, 2023
1 parent c031541 commit 09111ca
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions backend/migrations/2023-09-20-052638_user_pronouns/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE users
DROP COLUMN pronouns;
2 changes: 2 additions & 0 deletions backend/migrations/2023-09-20-052638_user_pronouns/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE users
ADD COLUMN pronouns TEXT DEFAULT '' NOT NULL;
38 changes: 32 additions & 6 deletions backend/seed_data/src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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,
},
];
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion backend/server/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::JsonErr;
use crate::{
database::{
models::{NewUser, User},
schema::{UserGender},
schema::UserGender,
Database,
},
state::ApiState,
Expand Down Expand Up @@ -281,6 +281,7 @@ pub struct SignUpBody {
degree_name: String,
degree_starting_year: u32,
gender: UserGender,
pronouns: String,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -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,
};

Expand Down
2 changes: 2 additions & 0 deletions backend/server/src/database/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions backend/server/src/database/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ table! {
degree_name -> Text,
degree_starting_year -> Int4,
gender -> UserGenderMapping,
pronouns -> Text,
superuser -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
Expand Down

0 comments on commit 09111ca

Please sign in to comment.