Remove image_url from users
parent: tbd commit: 979c015
Showing 6 changed files with 79 insertions and 79 deletions
giterated-daemon/.sqlx/query-176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710.json
@@ -0,0 +1,50 @@ | ||
1 | { | |
2 | "db_name": "PostgreSQL", | |
3 | "query": "INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *", | |
4 | "describe": { | |
5 | "columns": [ | |
6 | { | |
7 | "ordinal": 0, | |
8 | "name": "username", | |
9 | "type_info": "Text" | |
10 | }, | |
11 | { | |
12 | "ordinal": 1, | |
13 | "name": "email", | |
14 | "type_info": "Text" | |
15 | }, | |
16 | { | |
17 | "ordinal": 2, | |
18 | "name": "password", | |
19 | "type_info": "Text" | |
20 | }, | |
21 | { | |
22 | "ordinal": 3, | |
23 | "name": "public_key", | |
24 | "type_info": "Text" | |
25 | }, | |
26 | { | |
27 | "ordinal": 4, | |
28 | "name": "enc_private_key", | |
29 | "type_info": "Text" | |
30 | } | |
31 | ], | |
32 | "parameters": { | |
33 | "Left": [ | |
34 | "Text", | |
35 | "Text", | |
36 | "Text", | |
37 | "Text", | |
38 | "Text" | |
39 | ] | |
40 | }, | |
41 | "nullable": [ | |
42 | false, | |
43 | true, | |
44 | false, | |
45 | false, | |
46 | false | |
47 | ] | |
48 | }, | |
49 | "hash": "176a2c067fd9c8d4beb9a98ed803009c3200441c70cb8299b13b6dbe2b73c710" | |
50 | } |
giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json
@@ -10,26 +10,21 @@ | ||
10 | 10 | }, |
11 | 11 | { |
12 | 12 | "ordinal": 1, |
13 | "name": "image_url", | |
14 | "type_info": "Text" | |
15 | }, | |
16 | { | |
17 | "ordinal": 2, | |
18 | 13 | "name": "email", |
19 | 14 | "type_info": "Text" |
20 | 15 | }, |
21 | 16 | { |
22 | "ordinal": 3, | |
17 | "ordinal": 2, | |
23 | 18 | "name": "password", |
24 | 19 | "type_info": "Text" |
25 | 20 | }, |
26 | 21 | { |
27 | "ordinal": 4, | |
22 | "ordinal": 3, | |
28 | 23 | "name": "public_key", |
29 | 24 | "type_info": "Text" |
30 | 25 | }, |
31 | 26 | { |
32 | "ordinal": 5, | |
27 | "ordinal": 4, | |
33 | 28 | "name": "enc_private_key", |
34 | 29 | "type_info": "Text" |
35 | 30 | } |
@@ -41,7 +36,6 @@ | ||
41 | 36 | }, |
42 | 37 | "nullable": [ |
43 | 38 | false, |
44 | false, | |
45 | 39 | true, |
46 | 40 | false, |
47 | 41 | false, |
giterated-daemon/migrations/20230905060634_modify_users.sql
@@ -0,0 +1 @@ | ||
1 | ALTER TABLE users DROP COLUMN image_url; | |
1 | \ No newline at end of file |
giterated-daemon/src/backend/user.rs
@@ -19,7 +19,7 @@ use giterated_models::{ | ||
19 | 19 | }, |
20 | 20 | model::{ |
21 | 21 | instance::Instance, |
22 | settings::{Setting, UserBio, UserDisplayName}, | |
22 | settings::{Setting, UserBio, UserDisplayImage, UserDisplayName}, | |
23 | 23 | user::User, |
24 | 24 | }, |
25 | 25 | }; |
@@ -83,18 +83,21 @@ impl UserBackend for UserAuth { | ||
83 | 83 | &mut self, |
84 | 84 | request: UserDisplayImageRequest, |
85 | 85 | ) -> Result<UserDisplayImageResponse, anyhow::Error> { |
86 | let db_row = sqlx::query_as!( | |
87 | UserRow, | |
88 | r#"SELECT * FROM users WHERE username = $1"#, | |
89 | request.user.username | |
90 | ) | |
91 | .fetch_one(&self.pg_pool.clone()) | |
92 | .await | |
93 | .unwrap(); | |
86 | let settings = self.settings(&request.user).await?; | |
94 | 87 | |
95 | Ok(UserDisplayImageResponse { | |
96 | image_url: db_row.image_url, | |
97 | }) | |
88 | let image = settings | |
89 | .iter() | |
90 | .find(|setting| &setting.0 == UserDisplayImage::name()); | |
91 | ||
92 | if let Some((_, image)) = image { | |
93 | let image: UserDisplayImage = serde_json::from_value(image.clone()).unwrap(); | |
94 | ||
95 | Ok(UserDisplayImageResponse { | |
96 | image_url: Some(image.0), | |
97 | }) | |
98 | } else { | |
99 | Ok(UserDisplayImageResponse { image_url: None }) | |
100 | } | |
98 | 101 | } |
99 | 102 | |
100 | 103 | async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error> { |
@@ -214,7 +217,7 @@ impl AuthBackend for UserAuth { | ||
214 | 217 | |
215 | 218 | let user = match sqlx::query_as!( |
216 | 219 | UserRow, |
217 | r#"INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *"#, | |
220 | r#"INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *"#, | |
218 | 221 | request.username, |
219 | 222 | "example.com", |
220 | 223 | password_hash, |
@@ -260,7 +263,6 @@ impl AuthBackend for UserAuth { | ||
260 | 263 | #[derive(Debug, sqlx::FromRow)] |
261 | 264 | struct UserRow { |
262 | 265 | pub username: String, |
263 | pub image_url: Option<String>, | |
264 | 266 | pub email: Option<String>, |
265 | 267 | pub password: String, |
266 | 268 | pub public_key: String, |
giterated-models/src/model/settings.rs
@@ -21,3 +21,12 @@ impl Setting for UserDisplayName { | ||
21 | 21 | "Display Name" |
22 | 22 | } |
23 | 23 | } |
24 | ||
25 | #[derive(Debug, Serialize, Deserialize)] | |
26 | pub struct UserDisplayImage(pub String); | |
27 | ||
28 | impl Setting for UserDisplayImage { | |
29 | fn name() -> &'static str { | |
30 | "Profile Image" | |
31 | } | |
32 | } |