diff --git a/giterated-daemon/.sqlx/query-176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710.json b/giterated-daemon/.sqlx/query-176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710.json new file mode 100644 index 0000000..3cfc144 --- /dev/null +++ b/giterated-daemon/.sqlx/query-176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710.json @@ -0,0 +1,50 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "email", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "password", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "public_key", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "enc_private_key", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + false, + true, + false, + false, + false + ] + }, + "hash": "176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710" +} diff --git a/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json b/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json deleted file mode 100644 index 0f3e629..0000000 --- a/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "username", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "image_url", - "type_info": "Text" - }, - { - "ordinal": 2, - "name": "email", - "type_info": "Text" - }, - { - "ordinal": 3, - "name": "password", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "public_key", - "type_info": "Text" - }, - { - "ordinal": 5, - "name": "enc_private_key", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "Text", - "Text" - ] - }, - "nullable": [ - false, - false, - true, - false, - false, - false - ] - }, - "hash": "2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf" -} diff --git a/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json b/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json index ce3dbde..61a807d 100644 --- a/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json +++ b/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json @@ -10,26 +10,21 @@ }, { "ordinal": 1, - "name": "image_url", - "type_info": "Text" - }, - { - "ordinal": 2, "name": "email", "type_info": "Text" }, { - "ordinal": 3, + "ordinal": 2, "name": "password", "type_info": "Text" }, { - "ordinal": 4, + "ordinal": 3, "name": "public_key", "type_info": "Text" }, { - "ordinal": 5, + "ordinal": 4, "name": "enc_private_key", "type_info": "Text" } @@ -41,7 +36,6 @@ }, "nullable": [ false, - false, true, false, false, diff --git a/giterated-daemon/migrations/20230905060634_modify_users.sql b/giterated-daemon/migrations/20230905060634_modify_users.sql new file mode 100644 index 0000000..49c6aa0 --- /dev/null +++ b/giterated-daemon/migrations/20230905060634_modify_users.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN image_url; \ No newline at end of file diff --git a/giterated-daemon/src/backend/user.rs b/giterated-daemon/src/backend/user.rs index 9662666..8457f13 100644 --- a/giterated-daemon/src/backend/user.rs +++ b/giterated-daemon/src/backend/user.rs @@ -19,7 +19,7 @@ use giterated_models::{ }, model::{ instance::Instance, - settings::{Setting, UserBio, UserDisplayName}, + settings::{Setting, UserBio, UserDisplayImage, UserDisplayName}, user::User, }, }; @@ -83,18 +83,21 @@ impl UserBackend for UserAuth { &mut self, request: UserDisplayImageRequest, ) -> Result { - let db_row = sqlx::query_as!( - UserRow, - r#"SELECT * FROM users WHERE username = $1"#, - request.user.username - ) - .fetch_one(&self.pg_pool.clone()) - .await - .unwrap(); + let settings = self.settings(&request.user).await?; - Ok(UserDisplayImageResponse { - image_url: db_row.image_url, - }) + let image = settings + .iter() + .find(|setting| &setting.0 == UserDisplayImage::name()); + + if let Some((_, image)) = image { + let image: UserDisplayImage = serde_json::from_value(image.clone()).unwrap(); + + Ok(UserDisplayImageResponse { + image_url: Some(image.0), + }) + } else { + Ok(UserDisplayImageResponse { image_url: None }) + } } async fn bio(&mut self, request: UserBioRequest) -> Result { @@ -214,7 +217,7 @@ impl AuthBackend for UserAuth { let user = match sqlx::query_as!( UserRow, - r#"INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *"#, + r#"INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *"#, request.username, "example.com", password_hash, @@ -260,7 +263,6 @@ impl AuthBackend for UserAuth { #[derive(Debug, sqlx::FromRow)] struct UserRow { pub username: String, - pub image_url: Option, pub email: Option, pub password: String, pub public_key: String, diff --git a/giterated-models/src/model/settings.rs b/giterated-models/src/model/settings.rs index 701c091..6ca4075 100644 --- a/giterated-models/src/model/settings.rs +++ b/giterated-models/src/model/settings.rs @@ -21,3 +21,12 @@ impl Setting for UserDisplayName { "Display Name" } } + +#[derive(Debug, Serialize, Deserialize)] +pub struct UserDisplayImage(pub String); + +impl Setting for UserDisplayImage { + fn name() -> &'static str { + "Profile Image" + } +}