-
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.
feat:added methods for delte and update role;added handler for role a…
…nd added some routes into main regarding role
- Loading branch information
Alex_Miao_WSL
committed
Jul 16, 2024
1 parent
4726958
commit 11e8f01
Showing
4 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod auth; | ||
pub mod organisation; | ||
pub mod role; |
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,45 @@ | ||
use crate::models; | ||
use crate::models::app::AppState; | ||
use crate::models::auth::SuperUser; | ||
use crate::models::auth::{AuthUser, OrganisationAdmin}; | ||
use crate::models::error::ChaosError; | ||
use crate::models::role::{Role, RoleUpdate}; | ||
use crate::models::transaction::DBTransaction; | ||
use crate::service; | ||
use axum::extract::{Json, Path, State}; | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
|
||
pub struct RoleHandler; | ||
|
||
impl RoleHandler { | ||
pub async fn get( | ||
State(state): State<AppState>, | ||
Path(id): Path<i32>, | ||
_user: AuthUser, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let role = Role::get(id, &state.db).await?; | ||
Ok((StatusCode::OK, Json(role))) | ||
} | ||
|
||
pub async fn delete( | ||
State(state): State<AppState>, | ||
Path(id): Path<i32>, | ||
_admin: OrganisationAdmin, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Role::delete(id, &state.db).await?; | ||
Ok((StatusCode::OK, "Successfully deleted role")) | ||
} | ||
|
||
pub async fn update( | ||
State(state): State<AppState>, | ||
Path(id): Path<i32>, | ||
_admin: OrganisationAdmin, | ||
mut transaction: DBTransaction<'_>, | ||
Json(data): Json<RoleUpdate>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Role::update(id, data, &mut transaction.tx,).await?; | ||
transaction.tx.commit().await?; | ||
Ok((StatusCode::OK, "Successfully updated role")) | ||
} | ||
} |
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