Skip to content

Commit

Permalink
ran cargo format
Browse files Browse the repository at this point in the history
  • Loading branch information
KavikaPalletenne committed Nov 12, 2024
1 parent 6293a54 commit c1d0acd
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 396 deletions.
32 changes: 15 additions & 17 deletions backend/server/src/handler/answer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde_json::json;
use crate::models::answer::{Answer, NewAnswer};
use crate::models::app::AppState;
use crate::models::auth::{AnswerOwner, ApplicationOwner, AuthUser};
use crate::models::error::ChaosError;
use crate::models::transaction::DBTransaction;
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde_json::json;

pub struct AnswerHandler;

Expand All @@ -24,8 +24,9 @@ impl AnswerHandler {
data.question_id,
data.answer_data,
state.snowflake_generator,
&mut transaction.tx
).await?;
&mut transaction.tx,
)
.await?;

transaction.tx.commit().await?;

Expand All @@ -37,8 +38,8 @@ impl AnswerHandler {
_owner: ApplicationOwner,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let answers = Answer::get_all_common_by_application(application_id, &mut transaction.tx)
.await?;
let answers =
Answer::get_all_common_by_application(application_id, &mut transaction.tx).await?;

transaction.tx.commit().await?;

Expand All @@ -50,8 +51,9 @@ impl AnswerHandler {
_owner: ApplicationOwner,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let answers = Answer::get_all_by_application_and_role(application_id, role_id, &mut transaction.tx)
.await?;
let answers =
Answer::get_all_by_application_and_role(application_id, role_id, &mut transaction.tx)
.await?;

transaction.tx.commit().await?;

Expand All @@ -64,11 +66,7 @@ impl AnswerHandler {
mut transaction: DBTransaction<'_>,
Json(data): Json<NewAnswer>,
) -> Result<impl IntoResponse, ChaosError> {
Answer::update(
answer_id,
data.answer_data,
&mut transaction.tx
).await?;
Answer::update(answer_id, data.answer_data, &mut transaction.tx).await?;

transaction.tx.commit().await?;

Expand All @@ -78,12 +76,12 @@ impl AnswerHandler {
pub async fn delete(
Path(answer_id): Path<i64>,
_owner: AnswerOwner,
mut transaction: DBTransaction<'_>
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
Answer::delete(answer_id, &mut transaction.tx).await?;

transaction.tx.commit().await?;

Ok((StatusCode::OK, "Successfully deleted answer"))
}
}
}
4 changes: 2 additions & 2 deletions backend/server/src/handler/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::models::app::AppState;
use crate::models::application::{Application, ApplicationStatus};
use crate::models::auth::{AuthUser, ApplicationAdmin};
use crate::models::auth::{ApplicationAdmin, AuthUser};
use crate::models::error::ChaosError;
use crate::models::transaction::DBTransaction;
use axum::extract::{Json, Path, State};
Expand Down Expand Up @@ -48,4 +48,4 @@ impl ApplicationHandler {
transaction.tx.commit().await?;
Ok((StatusCode::OK, Json(applications)))
}
}
}
9 changes: 8 additions & 1 deletion backend/server/src/handler/campaign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ impl CampaignHandler {
mut transaction: DBTransaction<'_>,
Json(data): Json<NewApplication>,
) -> Result<impl IntoResponse, ChaosError> {
Application::create(id, user.user_id, data, state.snowflake_generator, &mut transaction.tx).await?;
Application::create(
id,
user.user_id,
data,
state.snowflake_generator,
&mut transaction.tx,
)
.await?;
transaction.tx.commit().await?;
Ok((StatusCode::OK, "Successfully created application"))
}
Expand Down
8 changes: 4 additions & 4 deletions backend/server/src/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod answer;
pub mod application;
pub mod auth;
pub mod user;
pub mod campaign;
pub mod organisation;
pub mod question;
pub mod rating;
pub mod role;
pub mod application;
pub mod question;
pub mod answer;
pub mod user;
44 changes: 24 additions & 20 deletions backend/server/src/handler/question.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use axum::extract::{Json, Path, State};
use axum::response::IntoResponse;
use axum::http::StatusCode;
use serde_json::json;
use crate::models::app::AppState;
use crate::models::auth::{AuthUser, CampaignAdmin, QuestionAdmin};
use crate::models::error::ChaosError;
use crate::models::question::{NewQuestion, Question};
use crate::models::transaction::DBTransaction;
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde_json::json;

pub struct QuestionHandler;

Expand All @@ -28,7 +28,8 @@ impl QuestionHandler {
data.question_data,
state.snowflake_generator,
&mut transaction.tx,
).await?;
)
.await?;

transaction.tx.commit().await?;

Expand All @@ -40,9 +41,9 @@ impl QuestionHandler {
_user: AuthUser,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let questions = Question::get_all_by_campaign_and_role(
campaign_id, role_id, &mut transaction.tx
).await?;
let questions =
Question::get_all_by_campaign_and_role(campaign_id, role_id, &mut transaction.tx)
.await?;

transaction.tx.commit().await?;

Expand All @@ -54,9 +55,8 @@ impl QuestionHandler {
_user: AuthUser,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
let questions = Question::get_all_common_by_campaign(
campaign_id, &mut transaction.tx,
).await?;
let questions =
Question::get_all_common_by_campaign(campaign_id, &mut transaction.tx).await?;

transaction.tx.commit().await?;

Expand All @@ -71,10 +71,17 @@ impl QuestionHandler {
Json(data): Json<NewQuestion>,
) -> Result<impl IntoResponse, ChaosError> {
Question::update(
question_id, data.title, data.description, data.common,
data.roles, data.required, data.question_data,
&mut transaction.tx, state.snowflake_generator,
).await?;
question_id,
data.title,
data.description,
data.common,
data.roles,
data.required,
data.question_data,
&mut transaction.tx,
state.snowflake_generator,
)
.await?;

transaction.tx.commit().await?;

Expand All @@ -86,13 +93,10 @@ impl QuestionHandler {
_admin: QuestionAdmin,
mut transaction: DBTransaction<'_>,
) -> Result<impl IntoResponse, ChaosError> {
Question::delete(
question_id,
&mut transaction.tx,
).await?;
Question::delete(question_id, &mut transaction.tx).await?;

transaction.tx.commit().await?;

Ok((StatusCode::OK, "Successfully deleted question"))
}
}
}
2 changes: 1 addition & 1 deletion backend/server/src/handler/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::models::application::Application;
use crate::models::auth::{AuthUser, RoleAdmin};
use crate::models::error::ChaosError;
use crate::models::role::{Role, RoleUpdate};
use axum::extract::{Json, Path, State};
use crate::models::transaction::DBTransaction;
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;

Expand Down
18 changes: 8 additions & 10 deletions backend/server/src/handler/user.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::models::app::AppState;
use crate::models::auth::AuthUser;
use crate::models::error::ChaosError;
use crate::models::user::{User, UserDegree, UserGender, UserName, UserPronouns, UserZid};
use axum::extract::{Json, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use crate::models::user::{User, UserDegree, UserGender, UserName, UserPronouns, UserZid};

pub struct UserHandler;

Expand All @@ -16,14 +16,14 @@ impl UserHandler {
let user = User::get(user.user_id, &state.db).await?;
Ok((StatusCode::OK, Json(user)))
}

pub async fn update_name(
State(state): State<AppState>,
user: AuthUser,
Json(request_body): Json<UserName>,
) -> Result<impl IntoResponse, ChaosError> {
User::update_name(user.user_id, request_body.name, &state.db).await?;

Ok((StatusCode::OK, "Updated username"))
}

Expand All @@ -46,17 +46,17 @@ impl UserHandler {

Ok((StatusCode::OK, "Updated gender"))
}

pub async fn update_zid(
State(state): State<AppState>,
user: AuthUser,
Json(request_body): Json<UserZid>,
) -> Result<impl IntoResponse, ChaosError> {
User::update_zid(user.user_id, request_body.zid, &state.db).await?;

Ok((StatusCode::OK, "Updated zid"))
}

pub async fn update_degree(
State(state): State<AppState>,
user: AuthUser,
Expand All @@ -66,12 +66,10 @@ impl UserHandler {
user.user_id,
request_body.degree_name,
request_body.degree_starting_year,
&state.db
&state.db,
)
.await?;

Ok((StatusCode::OK, "Updated user degree"))
}
}


Loading

0 comments on commit c1d0acd

Please sign in to comment.