diff options
Diffstat (limited to 'src/routers/account.rs')
| -rw-r--r-- | src/routers/account.rs | 49 |
1 files changed, 6 insertions, 43 deletions
diff --git a/src/routers/account.rs b/src/routers/account.rs index 4aaa56a..bb1cde5 100644 --- a/src/routers/account.rs +++ b/src/routers/account.rs | |||
| @@ -13,24 +13,12 @@ use crate::{ | |||
| 13 | ApiResult, AppState, ClientError, GlobalResponses, JwtClaims, ServerError, SuccessResponse, | 13 | ApiResult, AppState, ClientError, GlobalResponses, JwtClaims, ServerError, SuccessResponse, |
| 14 | create_jwt, create_password, | 14 | create_jwt, create_password, |
| 15 | extract::{ApiJson, Auth}, | 15 | extract::{ApiJson, Auth}, |
| 16 | models::Account, | ||
| 16 | tags::ACCOUNT, | 17 | tags::ACCOUNT, |
| 17 | validate_password, | 18 | validate_password, |
| 18 | }; | 19 | }; |
| 19 | 20 | ||
| 20 | #[derive(Serialize, ToSchema)] | 21 | #[derive(Serialize, ToSchema)] |
| 21 | #[schema(description = "Account information")] | ||
| 22 | struct Account { | ||
| 23 | #[schema(examples(1))] | ||
| 24 | id: i64, | ||
| 25 | #[schema(examples("john_doe", "ivanov_ivan"))] | ||
| 26 | username: String, | ||
| 27 | #[schema(examples("John", "Иван"))] | ||
| 28 | first_name: String, | ||
| 29 | #[schema(examples("Doe", "Иванов"))] | ||
| 30 | last_name: String, | ||
| 31 | } | ||
| 32 | |||
| 33 | #[derive(Serialize, ToSchema)] | ||
| 34 | #[schema(description = "Authorization token information")] | 22 | #[schema(description = "Authorization token information")] |
| 35 | struct Token { | 23 | struct Token { |
| 36 | token: String, | 24 | token: String, |
| @@ -120,12 +108,7 @@ struct DeleteUserRequest { | |||
| 120 | security(("auth" = [])), | 108 | security(("auth" = [])), |
| 121 | )] | 109 | )] |
| 122 | async fn me(Auth(user): Auth) -> ApiResult<Account> { | 110 | async fn me(Auth(user): Auth) -> ApiResult<Account> { |
| 123 | return Ok(SuccessResponse::ok(Account { | 111 | return Ok(SuccessResponse::ok(user.into())); |
| 124 | id: user.id, | ||
| 125 | username: user.username, | ||
| 126 | first_name: user.first_name, | ||
| 127 | last_name: user.last_name, | ||
| 128 | })); | ||
| 129 | } | 112 | } |
| 130 | 113 | ||
| 131 | #[utoipa::path( | 114 | #[utoipa::path( |
| @@ -170,12 +153,7 @@ async fn register( | |||
| 170 | .insert(&state.db) | 153 | .insert(&state.db) |
| 171 | .await?; | 154 | .await?; |
| 172 | 155 | ||
| 173 | Ok(SuccessResponse::ok(Account { | 156 | Ok(SuccessResponse::ok(user.into())) |
| 174 | id: user.id, | ||
| 175 | username: user.username, | ||
| 176 | first_name: user.first_name, | ||
| 177 | last_name: user.last_name, | ||
| 178 | })) | ||
| 179 | } | 157 | } |
| 180 | 158 | ||
| 181 | #[utoipa::path( | 159 | #[utoipa::path( |
| @@ -250,12 +228,7 @@ async fn change_password( | |||
| 250 | active_user.password_issue_date = Set(Utc::now().naive_utc()); | 228 | active_user.password_issue_date = Set(Utc::now().naive_utc()); |
| 251 | 229 | ||
| 252 | let user = active_user.update(&state.db).await?; | 230 | let user = active_user.update(&state.db).await?; |
| 253 | Ok(SuccessResponse::ok(Account { | 231 | Ok(SuccessResponse::ok(user.into())) |
| 254 | id: user.id, | ||
| 255 | username: user.username, | ||
| 256 | first_name: user.first_name, | ||
| 257 | last_name: user.last_name, | ||
| 258 | })) | ||
| 259 | } | 232 | } |
| 260 | 233 | ||
| 261 | #[utoipa::path( | 234 | #[utoipa::path( |
| @@ -295,12 +268,7 @@ async fn change_username( | |||
| 295 | active_user.username = Set(req.new_username); | 268 | active_user.username = Set(req.new_username); |
| 296 | 269 | ||
| 297 | let user = active_user.update(&state.db).await?; | 270 | let user = active_user.update(&state.db).await?; |
| 298 | Ok(SuccessResponse::ok(Account { | 271 | Ok(SuccessResponse::ok(user.into())) |
| 299 | id: user.id, | ||
| 300 | username: user.username, | ||
| 301 | first_name: user.first_name, | ||
| 302 | last_name: user.last_name, | ||
| 303 | })) | ||
| 304 | } | 272 | } |
| 305 | 273 | ||
| 306 | #[utoipa::path( | 274 | #[utoipa::path( |
| @@ -368,12 +336,7 @@ async fn delete( | |||
| 368 | 336 | ||
| 369 | user.clone().delete(&state.db).await?; | 337 | user.clone().delete(&state.db).await?; |
| 370 | 338 | ||
| 371 | Ok(SuccessResponse::ok(Account { | 339 | Ok(SuccessResponse::ok(user.into())) |
| 372 | id: user.id, | ||
| 373 | username: user.username, | ||
| 374 | first_name: user.first_name, | ||
| 375 | last_name: user.last_name, | ||
| 376 | })) | ||
| 377 | } | 340 | } |
| 378 | 341 | ||
| 379 | pub fn router() -> OpenApiRouter<AppState> { | 342 | pub fn router() -> OpenApiRouter<AppState> { |
