Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add path for backend_api_schema and judge_api_server #66

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions judge-control-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ reqwest = "0.12.5"
anyhow = "1.0"
thiserror = "1.0.63"
ssh2 = "0.9.4"
backend_api_schema = { path = "backend-api-schema" }
judge_api_server = { path = "judge-api-server" }
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1
*
*
* Generated by: https://openapi-generator.tech
*/



#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
Expand All @@ -30,7 +28,6 @@ pub struct ApiKey {
pub key: String,
}


impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
Expand All @@ -47,7 +44,6 @@ impl Default for Configuration {
oauth_access_token: None,
bearer_access_token: None,
api_key: None,

}
}
}
16 changes: 9 additions & 7 deletions judge-control-app/backend-api-schema/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Error<T> {
ResponseError(ResponseContent<T>),
}

impl <T> fmt::Display for Error<T> {
impl<T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Expand All @@ -28,7 +28,7 @@ impl <T> fmt::Display for Error<T> {
}
}

impl <T: fmt::Debug> error::Error for Error<T> {
impl<T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Expand All @@ -39,19 +39,19 @@ impl <T: fmt::Debug> error::Error for Error<T> {
}
}

impl <T> From<reqwest::Error> for Error<T> {
impl<T> From<reqwest::Error> for Error<T> {
fn from(e: reqwest::Error) -> Self {
Error::Reqwest(e)
}
}

impl <T> From<serde_json::Error> for Error<T> {
impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}

impl <T> From<std::io::Error> for Error<T> {
impl<T> From<std::io::Error> for Error<T> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
Expand All @@ -78,8 +78,10 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String
value,
));
}
},
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
}
serde_json::Value::String(s) => {
params.push((format!("{}[{}]", prefix, key), s.clone()))
}
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
}
}
Expand Down
30 changes: 18 additions & 12 deletions judge-control-app/backend-api-schema/src/apis/submit_result_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1
*
*
* Generated by: https://openapi-generator.tech
*/


use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


/// struct for typed errors of method [`submit_result`]
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -22,18 +20,22 @@ pub enum SubmitResultError {
UnknownValue(serde_json::Value),
}


/// ジャッジ結果
pub async fn submit_result(configuration: &configuration::Configuration, submit_result: models::SubmitResult) -> Result<(), Error<SubmitResultError>> {
pub async fn submit_result(
configuration: &configuration::Configuration,
submit_result: models::SubmitResult,
) -> Result<(), Error<SubmitResultError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!("{}/submit-result", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&submit_result);

Expand All @@ -46,9 +48,13 @@ pub async fn submit_result(configuration: &configuration::Configuration, submit_
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<SubmitResultError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
let local_var_entity: Option<SubmitResultError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

4 changes: 2 additions & 2 deletions judge-control-app/backend-api-schema/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]

extern crate serde_repr;
extern crate reqwest;
extern crate serde;
extern crate serde_json;
extern crate serde_repr;
extern crate url;
extern crate reqwest;

pub mod apis;
pub mod models;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -31,7 +31,6 @@ pub enum JudgeStatus {
Ce,
#[serde(rename = "IE")]
Ie,

}

impl std::fmt::Display for JudgeStatus {
Expand All @@ -54,4 +53,3 @@ impl Default for JudgeStatus {
Self::Ac
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand All @@ -26,12 +26,15 @@ pub struct SubmitResult {

impl SubmitResult {
/// テストケースのジャッジ結果
pub fn new(judge_id: uuid::Uuid, test_results: Vec<models::TestResult>, total_result: models::TestResult) -> SubmitResult {
pub fn new(
judge_id: uuid::Uuid,
test_results: Vec<models::TestResult>,
total_result: models::TestResult,
) -> SubmitResult {
SubmitResult {
judge_id,
test_results,
total_result: Box::new(total_result),
}
}
}

10 changes: 7 additions & 3 deletions judge-control-app/backend-api-schema/src/models/test_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1
*
*
* Generated by: https://openapi-generator.tech
*/

Expand Down Expand Up @@ -32,7 +32,12 @@ pub struct TestResult {

impl TestResult {
/// テストケースの結果
pub fn new(status: models::JudgeStatus, score: f64, exec_time: f64, memory_size: f64) -> TestResult {
pub fn new(
status: models::JudgeStatus,
score: f64,
exec_time: f64,
memory_size: f64,
) -> TestResult {
TestResult {
status,
text: None,
Expand All @@ -42,4 +47,3 @@ impl TestResult {
}
}
}

13 changes: 6 additions & 7 deletions judge-control-app/judge-api-server/src/apis/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use crate::{models, types::*};
#[allow(clippy::large_enum_variant)]
pub enum JudgeResponse {
/// OK
Status200_OK
Status200_OK,
}


/// Judge
#[async_trait]
#[allow(clippy::ptr_arg)]
Expand All @@ -24,10 +23,10 @@ pub trait Judge {
///
/// Judge - POST /v1/judge
async fn judge(
&self,
method: Method,
host: Host,
cookies: CookieJar,
body: models::Judge,
&self,
method: Method,
host: Host,
cookies: CookieJar,
body: models::Judge,
) -> Result<JudgeResponse, String>;
}
1 change: 0 additions & 1 deletion judge-control-app/judge-api-server/src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod judge;

Loading