Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kavos113 committed Jan 10, 2025
1 parent b8aaa7a commit 82216f3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use axum::{
use super::Repository;

mod authentication;
mod users;
mod submissions;
mod users;

pub fn make_router(app_state: Repository) -> Router {
let authentication_router = Router::new()
Expand All @@ -27,8 +27,8 @@ pub fn make_router(app_state: Repository) -> Router {
.route("/me/password", put(users::put_me_password))
.route("/:userId", get(users::get_user));

let submissions_router = Router::new()
.route("/:submissionId", get(submissions::get_submission));
let submissions_router =
Router::new().route("/:submissionId", get(submissions::get_submission));

Router::new()
.nest("/", authentication_router)
Expand Down
11 changes: 7 additions & 4 deletions src/handler/submissions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use axum::{extract::{Path, State}, response::IntoResponse, Json};
use axum::{
extract::{Path, State},
response::IntoResponse,
Json,
};
use axum_extra::{headers::Cookie, TypedHeader};
use reqwest::StatusCode;
use serde::Serialize;
Expand Down Expand Up @@ -39,7 +43,6 @@ pub async fn get_submission(
TypedHeader(cookie): TypedHeader<Cookie>,
Path(path): Path<i64>,
) -> anyhow::Result<impl IntoResponse, StatusCode> {

let submission = state
.get_submission_by_id(path)
.await
Expand All @@ -62,7 +65,7 @@ pub async fn get_submission(
.ok_or(StatusCode::NOT_FOUND)?;

if display_id != problem.author_id {
return Err(StatusCode::NOT_FOUND)
return Err(StatusCode::NOT_FOUND);
}
}

Expand Down Expand Up @@ -97,4 +100,4 @@ pub async fn get_submission(
};

Ok(Json(response))
}
}
4 changes: 2 additions & 2 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use sqlx::mysql::{MySqlConnectOptions, MySqlPoolOptions};
use super::Repository;

mod jwt;
mod normal_problems;
mod submissions;
mod user_password;
pub mod users;
mod users_session;
mod submissions;
mod normal_problems;

impl Repository {
pub async fn connect() -> anyhow::Result<Self> {
Expand Down
16 changes: 10 additions & 6 deletions src/repository/normal_problems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ pub struct NormalProblems {
}

impl Repository {
pub async fn get_normal_problem_by_id(&self, id: i32) -> anyhow::Result<Option<NormalProblems>> {
let problem = sqlx::query_as::<_, NormalProblems>("SELECT * FROM normal_problems WHERE id = ?")
.bind(id)
.fetch_optional(&self.pool)
.await?;
pub async fn get_normal_problem_by_id(
&self,
id: i32,
) -> anyhow::Result<Option<NormalProblems>> {
let problem =
sqlx::query_as::<_, NormalProblems>("SELECT * FROM normal_problems WHERE id = ?")
.bind(id)
.fetch_optional(&self.pool)
.await?;

Ok(problem)
}
}
}
18 changes: 11 additions & 7 deletions src/repository/submissions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sqlx::{FromRow, types::chrono};
use sqlx::{types::chrono, FromRow};

use super::Repository;

Expand Down Expand Up @@ -38,12 +38,16 @@ impl Repository {
Ok(submission)
}

pub async fn get_testcases_by_submission_id(&self, submission_id: i32) -> anyhow::Result<Vec<Testcase>> {
let testcases = sqlx::query_as::<_, Testcase>("SELECT * FROM testcases WHERE submission_id = ?")
.bind(submission_id)
.fetch_all(&self.pool)
.await?;
pub async fn get_testcases_by_submission_id(
&self,
submission_id: i32,
) -> anyhow::Result<Vec<Testcase>> {
let testcases =
sqlx::query_as::<_, Testcase>("SELECT * FROM testcases WHERE submission_id = ?")
.bind(submission_id)
.fetch_all(&self.pool)
.await?;

Ok(testcases)
}
}
}

0 comments on commit 82216f3

Please sign in to comment.