-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added get_username for all users logged in * updted user crud * efficient user get fucntion * finished user but no testing * finished user crud * docker working file * set users `created_at` and `updated_at` to not null * set optional fields to `Option` in `User` struct * fix `query_as` with custom enums * finished user crud * changed User CRUD to use handler struct * move `User` DB logic to `models::User` file * add pronouns and gender to `User` * remove TODO comment * fixed errors and warnings with adding new user fields --------- Co-authored-by: Alex_Miao_WSL <yuan_sen.miao@student.unsw.edu.au> Co-authored-by: Kavika <kbpalletenne@gmail.com>
- Loading branch information
1 parent
f140dd6
commit 45c8324
Showing
8 changed files
with
255 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod auth; | ||
pub mod user; | ||
pub mod campaign; | ||
pub mod organisation; | ||
pub mod role; | ||
pub mod application; | ||
pub mod application; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::models::app::AppState; | ||
use crate::models::auth::AuthUser; | ||
use crate::models::error::ChaosError; | ||
use axum::extract::{Json, State}; | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
use crate::models::user::{User, UserDegree, UserGender, UserName, UserPronouns, UserZid}; | ||
|
||
pub struct UserHandler; | ||
|
||
impl UserHandler { | ||
pub async fn get( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let user = User::get(user.user_id, &state.db).await?; | ||
Ok((StatusCode::OK, Json(user))) | ||
} | ||
|
||
pub async fn update_name( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
Json(request_body): Json<UserName>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
User::update_name(user.user_id, request_body.name, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Updated username")) | ||
} | ||
|
||
pub async fn update_pronouns( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
Json(request_body): Json<UserPronouns>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
User::update_pronouns(user.user_id, request_body.pronouns, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Updated pronouns")) | ||
} | ||
|
||
pub async fn update_gender( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
Json(request_body): Json<UserGender>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
User::update_gender(user.user_id, request_body.gender, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Updated gender")) | ||
} | ||
|
||
pub async fn update_zid( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
Json(request_body): Json<UserZid>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
User::update_zid(user.user_id, request_body.zid, &state.db).await?; | ||
|
||
Ok((StatusCode::OK, "Updated zid")) | ||
} | ||
|
||
pub async fn update_degree( | ||
State(state): State<AppState>, | ||
user: AuthUser, | ||
Json(request_body): Json<UserDegree>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
User::update_degree( | ||
user.user_id, | ||
request_body.degree_name, | ||
request_body.degree_starting_year, | ||
&state.db | ||
) | ||
.await?; | ||
|
||
Ok((StatusCode::OK, "Updated user degree")) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.