Skip to content

Commit 6dbfffe

Browse files
committed
feat: problems.jsonをAPIで取得可能に
- reqwestにUA追加で起動時に取得するように変更した。
1 parent ab92c57 commit 6dbfffe

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

backend/src/api/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ use std::{error::Error, marker::Sync};
33

44
#[derive(Debug, Deserialize)]
55
pub struct Problem {
6-
pub id: String,
7-
pub contest_id: String,
8-
pub title: String,
6+
pub id: String,
7+
pub contest_id: String,
8+
pub title: String,
99
}
1010

11-
pub async fn fetch_problem() -> Result<Vec<Problem>, Box<dyn Error+Send+Sync>> {
12-
let url = "https://kenkoooo.com/atcoder/resources/problems.json";
13-
let text = reqwest::get(url).await?.text().await?;
14-
let problem: Vec<Problem> = serde_json::from_str(&text)?;
11+
pub async fn fetch_problem() -> Result<Vec<Problem>, Box<dyn Error + Send + Sync>> {
12+
let url = "https://kenkoooo.com/atcoder/resources/problems.json";
1513

16-
Ok(problem)
14+
// reqwest::Clientを作成し、User-Agentヘッダーを追加
15+
let client = reqwest::Client::builder()
16+
.user_agent("atcoder-random-picker/0.1") // 任意の名前やバージョンを指定
17+
.build()?;
18+
19+
let text = client.get(url).send().await?.text().await?;
20+
let problem: Vec<Problem> = serde_json::from_str(&text)?;
21+
22+
Ok(problem)
1723
}

0 commit comments

Comments
 (0)