-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get系は権限不要でinsertとupdateはEquipmentManager以上、deleteはAdministratorという分割で一旦実装
- Loading branch information
1 parent
976778b
commit 68d8d80
Showing
4 changed files
with
165 additions
and
106 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,22 +1,30 @@ | ||
use crate::certification::{get_role, Role}; | ||
use crate::{ | ||
error_handling::{result_to_handler_with_log, ReturnData}, | ||
error_handling::{result_to_handler, result_to_handler_with_log, QrError, ReturnData}, | ||
Container, | ||
}; | ||
use axum::extract::Json; | ||
use axum::{extract::Json, headers::authorization::Bearer}; | ||
use sqlx::{pool::Pool, postgres::Postgres}; | ||
use std::sync::Arc; | ||
use tracing::*; | ||
|
||
pub async fn insert_container( | ||
bearer: Bearer, | ||
Json(container): Json<Container>, | ||
conn: Arc<Pool<Postgres>>, | ||
) -> ReturnData<()> { | ||
info!("Try insert container: {container:?}"); | ||
let res = crate::database::insert_container::insert_container(&*conn, container.clone()).await; | ||
result_to_handler_with_log( | ||
|_| Some(format!("Success insert container[{}]", &container.id)), | ||
|e| Some(format!("{e} [{}]", &container.id)), | ||
&res, | ||
) | ||
.await | ||
let role = get_role(&*conn, bearer.token()).await; | ||
if Ok(Role::EquipmentManager) == role && Ok(Role::Administrator) == role { | ||
info!("Try insert container: {container:?}"); | ||
let res = | ||
crate::database::insert_container::insert_container(&*conn, container.clone()).await; | ||
result_to_handler_with_log( | ||
|_| Some(format!("Success insert container[{}]", &container.id)), | ||
|e| Some(format!("{e} [{}]", &container.id)), | ||
&res, | ||
) | ||
.await | ||
} else { | ||
result_to_handler(&Err(QrError::Authorized)).await | ||
} | ||
} |
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.