Skip to content

Commit

Permalink
ops: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rootCircle committed Dec 2, 2023
1 parent 0666af9 commit 652e746
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/controllers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod compile_code;
pub mod email;
pub mod login_signup;
pub mod compile_code;
21 changes: 7 additions & 14 deletions src/controllers/compile_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ pub struct CodeOutputResponse {
#[derive(Deserialize)]
pub struct CodeQuizRequest {
pub code: String,
pub testcases: Vec<Testcase>
pub testcases: Vec<Testcase>,
}

#[derive(Deserialize)]
pub struct Testcase {
pub input: String,
pub expected_output: String
pub expected_output: String,
}

#[derive(Serialize)]
pub struct QuizResponse {
pub output_match: Vec<Result<bool, String>>
pub output_match: Vec<Result<bool, String>>,
}

pub async fn compile_code(
Expand All @@ -36,15 +36,12 @@ pub async fn compile_code(
})
}

pub async fn take_quiz(
extract::Json(user): extract::Json<CodeQuizRequest>,
) -> Json<QuizResponse> {
pub async fn take_quiz(extract::Json(user): extract::Json<CodeQuizRequest>) -> Json<QuizResponse> {
Json(QuizResponse {
output_match: match_outputs(user.code, user.testcases),
})
}


fn runnable_code(code: String, input: &str) -> Result<String, String> {
let runnable = run_program(code, input, false);
match runnable {
Expand All @@ -60,13 +57,9 @@ fn match_outputs(code: String, testcases: Vec<Testcase>) -> Vec<Result<bool, Str
let code_instance = runnable_code(code.clone(), &testcase.input);

match code_instance {
Ok(actual_output) => {
output_vec.push(Ok(actual_output == testcase.expected_output))
}
Err(err) => {
output_vec.push(Err(err))
}
Ok(actual_output) => output_vec.push(Ok(actual_output == testcase.expected_output)),
Err(err) => output_vec.push(Err(err)),
}
}
output_vec
}
}
2 changes: 1 addition & 1 deletion src/controllers/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lettre::{
AsyncTransport, Message, Tokio1Executor,
};

use crate::{smtp_config::Config, controllers::login_signup::User};
use crate::{controllers::login_signup::User, smtp_config::Config};

pub struct Email {
user: User,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/login_signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::{
time::{Duration, SystemTime},
};

use dotenv::dotenv;
use super::email::Email;
use dotenv::dotenv;
use rand::{distributions::Alphanumeric, Rng};

use crate::{smtp_config, controllers::login_signup::headers::authorization::Bearer};
use crate::{controllers::login_signup::headers::authorization::Bearer, smtp_config};
use axum::{
extract::{self, Path, TypedHeader},
headers,
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ use controllers::login_signup::{auth_routes, UserData};
use shuttle_persist::PersistInstance;
use tower_http::cors::CorsLayer;

mod smtp_config;
mod controllers;
mod smtp_config;

async fn api_health() -> &'static str {
"Zen is High Dear!\nCompiler Version: v0.2.0".to_string()
.leak()
"Zen is High Dear!\nCompiler Version: v0.2.0"
.to_string()
.leak()
}

#[shuttle_runtime::main]
Expand All @@ -39,4 +40,3 @@ async fn axum(#[shuttle_persist::Persist] persist: PersistInstance) -> shuttle_a

Ok(router.into())
}

0 comments on commit 652e746

Please sign in to comment.