-
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.
Response200 struct implemented + Errors improved
- Loading branch information
Zac Ecob
committed
Aug 1, 2024
1 parent
4fa8c46
commit d2403c4
Showing
6 changed files
with
93 additions
and
18 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
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod organisation; | |
pub mod storage; | ||
pub mod transaction; | ||
pub mod user; | ||
pub mod response; |
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,31 @@ | ||
use axum::response::{IntoResponse, Response}; | ||
use aide::OperationOutput; | ||
use aide:: gen; | ||
use aide::openapi::Operation; | ||
use axum::http::StatusCode; | ||
|
||
|
||
pub struct Response200<const MSG: &'static str> {} | ||
|
||
/// Implementation for converting errors into responses. Manages error code and message returned. | ||
impl<const MSG: &'static str> IntoResponse for Response200<MSG> { | ||
fn into_response(self) -> Response { | ||
(StatusCode::OK, MSG).into_response() | ||
} | ||
} | ||
|
||
impl<const MSG: &'static str> OperationOutput for Response200<MSG> { | ||
type Inner = Self; | ||
|
||
fn inferred_responses( | ||
ctx: &mut gen::GenContext, | ||
operation: &mut Operation, | ||
) -> Vec<(Option<u16>, aide::openapi::Response)> { | ||
Vec::from([ | ||
(Some(200), aide::openapi::Response { | ||
description: MSG.to_string(), | ||
..Default::default() | ||
}) | ||
]) | ||
} | ||
} |
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,34 @@ | ||
struct Response200<const MSG: &'static str> {} | ||
|
||
/* | ||
impl OperationOutput for CreateRes { | ||
.... | ||
} | ||
impl IntoResponse for CreateRes { | ||
.... | ||
} | ||
*/ | ||
|
||
//Use const-generics?? I might be cooking | ||
|
||
impl OrganisationHandler { | ||
pub async fn create( | ||
State(state): State<AppState>, | ||
_user: SuperUser, | ||
mut transaction: DBTransaction<'_>, | ||
Json(data): Json<NewOrganisation>, | ||
) -> Result<impl IntoApiResponse, ChaosError> { | ||
Organisation::create( | ||
data.admin, | ||
data.name, | ||
state.snowflake_generator, | ||
&mut transaction.tx, | ||
) | ||
.await?; | ||
|
||
transaction.tx.commit().await?; | ||
Ok((StatusCode::OK, Response200::<"Succesfully created organisation!"> {}) | ||
} | ||
} |