From 6a571020c26e5865790149ad240c8ddc1673607c Mon Sep 17 00:00:00 2001 From: twil3akine Date: Wed, 20 Aug 2025 23:08:36 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20fonts=E3=81=AE=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=88=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fontのインポートをしていなかったので、入っていないPCで見ると適応されてなかったのを修正 --- frontend/src/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/style.css b/frontend/src/style.css index 9aa544c..369fafe 100644 --- a/frontend/src/style.css +++ b/frontend/src/style.css @@ -1,3 +1,4 @@ +@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100..900&family=Ubuntu+Sans+Mono:ital,wght@0,400..700;1,400..700&display=swap'); @import "tailwindcss"; @theme { From 17b0a64a1cfe74001db41491d51bafe9a8afc7ee Mon Sep 17 00:00:00 2001 From: twil3akine Date: Wed, 27 Aug 2025 20:55:05 +0900 Subject: [PATCH 2/5] =?UTF-8?q?update:=20Pick=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - loading ? loader+pick : pick -> loading ? loader : pick - setTimeout = 2200 -> 1050 --- frontend/src/App.svelte | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index a8abe8c..4c68770 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -39,15 +39,18 @@ } const json: Problem = await res.json(); - result = json; + + setTimeout(() => { + result = json; + loading = false; + }, 1050); } catch (err) { - errorMessage = (err as Error).message; - result = null; + setTimeout(() => { + errorMessage = (err as Error).message; + result = null; + loading = false; + }, 1050); } - - setTimeout(() => { - loading = false; - }, 2200); } @@ -70,13 +73,14 @@
-
From 38231814a8cbc35d5cacc71ee9b7bc72dd34efc2 Mon Sep 17 00:00:00 2001 From: twil3akine Date: Wed, 27 Aug 2025 21:51:56 +0900 Subject: [PATCH 3/5] =?UTF-8?q?update:=20404=20response=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 指定Diff範囲内の問題がなかったとき、404 Res with JSONを返すように変更 --- backend/src/utils/routing.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/src/utils/routing.rs b/backend/src/utils/routing.rs index f364bda..e2172cd 100644 --- a/backend/src/utils/routing.rs +++ b/backend/src/utils/routing.rs @@ -1,11 +1,12 @@ use hyper::{Body, Request, Response, StatusCode, header}; +use core::prelude::v1::derive; use std::option::Option::None; use std::result::Result::Ok; +use std::string::ToString; use std::{collections::HashMap}; use std::convert::{From, Infallible}; use std::sync::Arc; use chrono::{DateTime, Local}; -use rand; use rand::seq::IteratorRandom; use serde::Serialize; @@ -25,6 +26,11 @@ struct ProblemResponse { difficulty: Option, } +#[derive(Serialize)] +struct ErrorResponse { + message: String, +} + async fn get_parameter(req: &Request) -> HashMap { let query = req.uri().query().unwrap_or(""); url::form_urlencoded::parse(query.as_bytes()) @@ -99,8 +105,14 @@ pub async fn router(req: Request, state: Arc) -> Result { - let mut not_found = Response::new(Body::from("No problem found in given range.")); + let error_body = serde_json::to_string(&ErrorResponse { + message: "指定Diff範囲に該当する問題がありませんでした".to_string(), + }).unwrap(); + + let mut not_found = Response::new(Body::from(error_body)); *not_found.status_mut() = StatusCode::NOT_FOUND; + not_found.headers_mut().insert(header::CONTENT_TYPE, "application/json".parse().unwrap()); + Ok(with_cors_headers(not_found)) } } From deaad8087d5205897596e5ee6b65a56c3de781fa Mon Sep 17 00:00:00 2001 From: twil3akine Date: Wed, 27 Aug 2025 21:53:05 +0900 Subject: [PATCH 4/5] =?UTF-8?q?update:=20errorMessage=E3=81=AE=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E6=96=B9=E6=B3=95=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pickの結果をMessageコンポーネントを使用して、成功、失敗どちらも同じような見た目に変更 --- frontend/src/App.svelte | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 4c68770..9f4289b 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -34,6 +34,11 @@ `${API_URL}/?under=${under_diff}&over=${over_diff}` ); + if (res.status === 404) { + const data = await res.json(); + throw new Error(data.message ?? "指定範囲内に該当する問題がありませんでした"); + } + if (!res.ok) { throw new Error(`HTTPエラー: ${res.status}`); } @@ -66,10 +71,6 @@

最低Diffが負の値になっています

{/if} - {#if errorMessage} -

{errorMessage}

- {/if} -
@@ -112,6 +113,20 @@
+ {:else if errorMessage} +
+ +
+ + +

+ {errorMessage} +

+
+
+
{/if} \ No newline at end of file From bb3df3eb603bfdbfdd48392bc4d3fc283f34c6f0 Mon Sep 17 00:00:00 2001 From: twil3akine Date: Wed, 27 Aug 2025 22:07:54 +0900 Subject: [PATCH 5/5] update: test --- backend/tests/routing_test.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/tests/routing_test.rs b/backend/tests/routing_test.rs index 71b66df..c9249e3 100644 --- a/backend/tests/routing_test.rs +++ b/backend/tests/routing_test.rs @@ -14,13 +14,11 @@ fn build_test_state() -> Arc { ProblemModel { difficulty: Some(1000.0) }, ); - let problems = vec![ - Problem { - id: "abc001_a".to_string(), - contest_id: "abc001".to_string(), - name: "A - Test Problem".to_string(), - } - ]; + let problems = vec![Problem { + id: "abc001_a".to_string(), + contest_id: "abc001".to_string(), + name: "A - Test Problem".to_string(), + }]; Arc::new(AppState { problems, @@ -56,7 +54,14 @@ async fn test_not_found_path() { async fn test_not_found_problem() { let (status, body) = build_and_send(Method::GET, "/?under=0&over=500").await; assert_eq!(status, StatusCode::NOT_FOUND); - assert_eq!(body, "No problem found in given range."); + + #[derive(serde::Deserialize)] + struct ErrorResponse { + message: String, + } + + let err: ErrorResponse = serde_json::from_str(&body).unwrap(); + assert_eq!(err.message, "指定Diff範囲に該当する問題がありませんでした"); } #[tokio::test] @@ -70,7 +75,7 @@ async fn test_under_greater_than_over() { async fn test_random_range() { let (status, body) = build_and_send(Method::GET, "/?under=500&over=1500").await; assert_eq!(status, StatusCode::OK); - + #[derive(serde::Deserialize)] struct ProblemResponse { id: String,