feat: add pronouns to users
This commit is contained in:
parent
2f7fac8db5
commit
ee8211a321
5 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
ALTER TABLE users DROP COLUMN pronouns;
|
|
@ -0,0 +1,2 @@
|
|||
-- Your SQL goes here
|
||||
ALTER TABLE users ADD COLUMN pronouns VARCHAR(32) DEFAULT NULL;
|
|
@ -40,6 +40,7 @@ struct NewInfo {
|
|||
display_name: Option<String>,
|
||||
//password: Option<String>, will probably be handled through a reset password link
|
||||
email: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
|
@ -97,5 +98,9 @@ pub async fn update(
|
|||
me.set_email(&data, email.clone()).await?;
|
||||
}
|
||||
|
||||
if let Some(pronouns) = &form.json.pronouns {
|
||||
me.set_pronouns(&data, pronouns.clone()).await?;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
|
|
@ -144,6 +144,8 @@ diesel::table! {
|
|||
deleted_at -> Nullable<Int8>,
|
||||
#[max_length = 100]
|
||||
avatar -> Nullable<Varchar>,
|
||||
#[max_length = 32]
|
||||
pronouns -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -865,6 +865,7 @@ pub struct User {
|
|||
username: String,
|
||||
display_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
@ -915,6 +916,7 @@ pub struct Me {
|
|||
username: String,
|
||||
display_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
email: String,
|
||||
pub email_verified: bool,
|
||||
}
|
||||
|
@ -1090,6 +1092,25 @@ impl Me {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_pronouns(&mut self, data: &Data, new_pronouns: String) -> Result<(), Error> {
|
||||
let mut conn = data.pool.get().await?;
|
||||
|
||||
use users::dsl;
|
||||
update(users::table)
|
||||
.filter(dsl::uuid.eq(self.uuid))
|
||||
.set((
|
||||
dsl::pronouns.eq(new_pronouns.as_str()),
|
||||
))
|
||||
.execute(&mut conn)
|
||||
.await?;
|
||||
|
||||
if data.get_cache_key(self.uuid.to_string()).await.is_ok() {
|
||||
data.del_cache_key(self.uuid.to_string()).await?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue