summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/routes/warning.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/routes/warning.rs b/src/routes/warning.rs
index f33b339..384218a 100644
--- a/src/routes/warning.rs
+++ b/src/routes/warning.rs
@@ -12,7 +12,7 @@ use crate::{
use axum::{
extract::{Path, Query},
http::StatusCode,
- routing::{get, post, put},
+ routing::{get, post},
Json, Router,
};
@@ -20,7 +20,10 @@ use axum::{
pub fn create_route() -> Router {
Router::new()
.route("/", get(list_warnings).post(create_warning))
- .route("/:id", put(edit_warning).delete(delete_warning))
+ .route(
+ "/:id",
+ get(get_warning).put(edit_warning).delete(delete_warning),
+ )
.route("/filter", post(filter_warnings))
}
@@ -47,6 +50,23 @@ async fn list_warnings(
Ok(Json(WarningPagination { count, results }))
}
+/// Get a warning with id = `model_id`
+async fn get_warning(
+ Path(warning_id): Path<i32>,
+ claims: Claims,
+) -> Result<Json<Warning>, AppError> {
+ let user = User::find_by_id(claims.user_id).await?;
+
+ if !(user.is_staff.unwrap()) {
+ return Err(AppError::Unauthorized);
+ }
+
+ match Warning::find_by_id(warning_id).await {
+ Ok(warning) => Ok(Json(warning.into())),
+ Err(_) => Err(AppError::NotFound("Warning not found".to_string())),
+ }
+}
+
/// Create a warning. Checks Authorization token
async fn create_warning(
Json(payload): Json<WarningCreate>,