feat: add about to users
This commit is contained in:
parent
41defc4a25
commit
c4fc23ec85
5 changed files with 32 additions and 0 deletions
2
migrations/2025-06-01-143713_add_about_to_users/down.sql
Normal file
2
migrations/2025-06-01-143713_add_about_to_users/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
ALTER TABLE users DROP COLUMN about;
|
2
migrations/2025-06-01-143713_add_about_to_users/up.sql
Normal file
2
migrations/2025-06-01-143713_add_about_to_users/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- Your SQL goes here
|
||||
ALTER TABLE users ADD COLUMN about VARCHAR(200) DEFAULT NULL;
|
|
@ -41,6 +41,7 @@ struct NewInfo {
|
|||
//password: Option<String>, will probably be handled through a reset password link
|
||||
email: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
|
@ -102,5 +103,9 @@ pub async fn update(
|
|||
me.set_pronouns(&data, pronouns.clone()).await?;
|
||||
}
|
||||
|
||||
if let Some(about) = &form.json.about {
|
||||
me.set_about(&data, about.clone()).await?;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
|
|
@ -146,6 +146,8 @@ diesel::table! {
|
|||
avatar -> Nullable<Varchar>,
|
||||
#[max_length = 32]
|
||||
pronouns -> Nullable<Varchar>,
|
||||
#[max_length = 200]
|
||||
about -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -953,6 +953,7 @@ pub struct User {
|
|||
display_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
@ -1004,6 +1005,7 @@ pub struct Me {
|
|||
display_name: Option<String>,
|
||||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
email: String,
|
||||
pub email_verified: bool,
|
||||
}
|
||||
|
@ -1198,6 +1200,25 @@ impl Me {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_about(&mut self, data: &Data, new_about: String) -> Result<(), Error> {
|
||||
let mut conn = data.pool.get().await?;
|
||||
|
||||
use users::dsl;
|
||||
update(users::table)
|
||||
.filter(dsl::uuid.eq(self.uuid))
|
||||
.set((
|
||||
dsl::about.eq(new_about.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