-
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 model file for application; added create method. fix: changed schema for application_role, fixed id type for role. * attempt to implement get for application; added additional fields for role response struct * added additional field to Application response type * feat: added get methods for application in model * fix pool usage in model/role, added set_status methods to application, patched API routes for get_all routes * added handlers for application; implemented Auth for ApplicationAdmin * added routes for applications in main; implement more handlers; moved some application handler methods to other more appropriate handlers * change `*Admin` `FromRequest` implementations to use HashMap of path variables * make 'Pending' the default Application status * return user info with `ApplicationDetails` --------- Co-authored-by: Alex_Miao_WSL <[email protected]> Co-authored-by: Kavika <[email protected]>
- Loading branch information
1 parent
ba6fb2b
commit f140dd6
Showing
13 changed files
with
615 additions
and
29 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::models::app::AppState; | ||
use crate::models::application::{Application, ApplicationStatus}; | ||
use crate::models::auth::{AuthUser, ApplicationAdmin}; | ||
use crate::models::error::ChaosError; | ||
use crate::models::transaction::DBTransaction; | ||
use axum::extract::{Json, Path, State}; | ||
use axum::http::StatusCode; | ||
use axum::response::IntoResponse; | ||
|
||
pub struct ApplicationHandler; | ||
|
||
impl ApplicationHandler { | ||
pub async fn get( | ||
Path(application_id): Path<i64>, | ||
_admin: ApplicationAdmin, | ||
mut transaction: DBTransaction<'_>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let application = Application::get(application_id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
Ok((StatusCode::OK, Json(application))) | ||
} | ||
|
||
pub async fn set_status( | ||
State(state): State<AppState>, | ||
Path(application_id): Path<i64>, | ||
_admin: ApplicationAdmin, | ||
Json(data): Json<ApplicationStatus>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Application::set_status(application_id, data, &state.db).await?; | ||
Ok((StatusCode::OK, "Status successfully updated")) | ||
} | ||
|
||
pub async fn set_private_status( | ||
State(state): State<AppState>, | ||
Path(application_id): Path<i64>, | ||
_admin: ApplicationAdmin, | ||
Json(data): Json<ApplicationStatus>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
Application::set_private_status(application_id, data, &state.db).await?; | ||
Ok((StatusCode::OK, "Private Status successfully updated")) | ||
} | ||
|
||
pub async fn get_from_curr_user( | ||
user: AuthUser, | ||
mut transaction: DBTransaction<'_>, | ||
) -> Result<impl IntoResponse, ChaosError> { | ||
let applications = Application::get_from_user_id(user.user_id, &mut transaction.tx).await?; | ||
transaction.tx.commit().await?; | ||
Ok((StatusCode::OK, Json(applications))) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod auth; | |
pub mod campaign; | ||
pub mod organisation; | ||
pub mod role; | ||
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
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.