Skip to content

Commit faf62dd

Browse files
committed
Merge branch 'master' into migrate
2 parents 51bfe13 + 7e582e8 commit faf62dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2014
-1076
lines changed

atcoder-problems-backend/Cargo.lock

Lines changed: 701 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

atcoder-problems-backend/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ sql-client = { path = "./sql-client" }
2424
atcoder-client = { path = "./atcoder-client" }
2525

2626
# Web framework
27-
actix-web = "4.0.0-beta.18"
27+
actix-web = "4.0.0-rc.2"
28+
actix-service = "2.0.2"
2829
reqwest = { version = "0.11", features = ["json"] }
2930

3031
async-trait = "0.1"
3132

3233
anyhow = "1.0"
34+
futures-util = "0.3.19"
3335

3436
[dev-dependencies]
37+
httpmock = "0.6.6"
3538

3639
[workspace]
3740
members = ["sql-client", "atcoder-client"]
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
use std::env;
22

3+
use atcoder_problems_backend::server::middleware::github_auth::GithubClient;
34
use atcoder_problems_backend::server::run_server;
4-
use atcoder_problems_backend::server::GitHubAuthentication;
55
use atcoder_problems_backend::utils::init_log_config;
66

77
#[actix_web::main]
88
async fn main() {
9-
// std::env::set_var("RUST_LOG", "actix_web=info");
109
init_log_config().unwrap();
1110
let database_url = env::var("SQL_URL").expect("SQL_URL is not set.");
1211
let port = 8080;
1312

1413
let client_id = env::var("CLIENT_ID").unwrap_or_else(|_| String::new());
1514
let client_secret = env::var("CLIENT_SECRET").unwrap_or_else(|_| String::new());
1615

17-
let auth = GitHubAuthentication::new(&client_id, &client_secret);
1816
let pg_pool = sql_client::initialize_pool(&database_url)
1917
.await
2018
.expect("Failed to initialize the connection pool");
21-
run_server(pg_pool, auth, port)
19+
let github = GithubClient::new(
20+
&client_id,
21+
&client_secret,
22+
"https://github.com",
23+
"https://api.github.com",
24+
)
25+
.expect("Failed to create github client");
26+
run_server(pg_pool, github, port)
2227
.await
2328
.expect("Failed to run server");
2429
}

atcoder-problems-backend/src/server/auth.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use actix_web::{get, HttpResponse, Responder};
2+
3+
#[get("/healthcheck")]
4+
pub async fn get_healthcheck() -> impl Responder {
5+
HttpResponse::Ok().finish()
6+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use actix_web::{post, web, HttpResponse, Responder, Result};
2+
use serde::Deserialize;
3+
use sql_client::{
4+
internal::virtual_contest_manager::{VirtualContestItem, VirtualContestManager},
5+
PgPool,
6+
};
7+
8+
use crate::server::{error::ApiResult, middleware::github_auth::GithubToken};
9+
10+
#[derive(Deserialize)]
11+
pub struct UpdateItemsQuery {
12+
contest_id: String,
13+
problems: Vec<VirtualContestItem>,
14+
}
15+
16+
#[post("/internal-api/contest/item/update")]
17+
pub async fn update_items(
18+
token: web::ReqData<GithubToken>,
19+
pool: web::Data<PgPool>,
20+
query: web::Json<UpdateItemsQuery>,
21+
) -> Result<impl Responder> {
22+
let user_id = token.id.to_string();
23+
pool.update_items(&query.contest_id, &query.problems, &user_id)
24+
.await
25+
.map_internal_server_err()?;
26+
let response = HttpResponse::Ok().finish();
27+
Ok(response)
28+
}

0 commit comments

Comments
 (0)