Skip to content

Commit

Permalink
Merge pull request #1408 from nebocco/feature/remove_api
Browse files Browse the repository at this point in the history
Remove Deprecated API
  • Loading branch information
kenkoooo authored Oct 15, 2023
2 parents 5c99f31 + c3320fe commit 4bd8ed9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 97 deletions.
20 changes: 3 additions & 17 deletions atcoder-problems-backend/src/server/ranking/rated_point_sum.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
use super::{
RankingRequest, RankingRequestFormat, RankingResponseFormat, RankingSelector, UserRankRequest,
RankingRequest, RankingRequestFormat, RankingResponse, RankingSelector, UserRankRequest,
UserRankResponse, UserRankSelector,
};

use actix_web::{error, web, Result};
use async_trait::async_trait;
use serde::Serialize;
use sql_client::{rated_point_sum::RatedPointSumClient, PgPool};

#[deprecated(
note = "this special Response type is deprecated and will be replaced with super::RankingResponse"
)]
#[derive(Debug, Serialize)]
pub(crate) struct RPSRankingResponse {
user_id: String,
count: i64,
point_sum: i64,
}

impl RankingResponseFormat for RPSRankingResponse {}

pub(crate) struct RatedPointSumRanking;

#[async_trait(?Send)]
impl RankingSelector for RatedPointSumRanking {
type Request = RankingRequest;
type Response = RPSRankingResponse;
type Response = RankingResponse;
async fn fetch(pool: web::Data<PgPool>, query: Self::Request) -> Result<Vec<Self::Response>> {
let ranking = pool
.load_rated_point_sum_in_range(query.range())
.await
.map_err(error::ErrorInternalServerError)?;
Ok(ranking
.into_iter()
.map(|entry| RPSRankingResponse {
.map(|entry| RankingResponse {
user_id: entry.user_id,
count: entry.point_sum,
point_sum: entry.point_sum,
})
.collect())
}
Expand Down
4 changes: 1 addition & 3 deletions atcoder-problems-backend/src/server/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::server::{
user_info::get_user_info,
user_submissions::get_user_submission_count,
user_submissions::{
get_recent_submissions, get_user_submissions, get_user_submissions_from_time,
get_users_time_submissions,
get_recent_submissions, get_user_submissions_from_time, get_users_time_submissions,
},
};

Expand Down Expand Up @@ -43,7 +42,6 @@ pub fn config_services(cfg: &mut web::ServiceConfig) {
.service(endpoint::internal_api::progress_reset::delete_progress_reset_item)
.service(
web::scope("/atcoder-api")
.service(web::resource("/results").route(web::get().to(get_user_submissions)))
.service(
web::scope("/v2")
.service(web::resource("/user_info").route(web::get().to(get_user_info))),
Expand Down
18 changes: 0 additions & 18 deletions atcoder-problems-backend/src/server/user_submissions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::server::MakeCors;
use actix_web::http::header::CACHE_CONTROL;
use actix_web::{error, web, HttpRequest, HttpResponse, Result};
use serde::{Deserialize, Serialize};
use sql_client::submission_client::{SubmissionClient, SubmissionRequest};
Expand All @@ -14,23 +13,6 @@ pub(crate) struct GetUserSubmissionQuery {
to_second: Option<i64>,
}

pub(crate) async fn get_user_submissions(
_request: HttpRequest,
pool: web::Data<PgPool>,
query: web::Query<GetUserSubmissionQuery>,
) -> Result<HttpResponse> {
let user_id = &query.user;
let submissions = pool
.get_submissions(SubmissionRequest::UserAll { user_id })
.await
.map_err(error::ErrorInternalServerError)?;
let response = HttpResponse::Ok()
.make_cors()
.insert_header((CACHE_CONTROL, "max-age=300"))
.json(&submissions);
Ok(response)
}

pub(crate) async fn get_user_submissions_from_time(
_request: HttpRequest,
pool: web::Data<PgPool>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async fn test_rated_point_sum_ranking() {
assert_eq!(
response,
json!([
{"user_id":"u2","point_sum":2,"count":2},
{"user_id":"u1","point_sum":1,"count":1},
{"user_id":"u3","point_sum":1,"count":1}
{"user_id":"u2","count":2},
{"user_id":"u1","count":1},
{"user_id":"u3","count":1}
])
);

Expand All @@ -48,8 +48,8 @@ async fn test_rated_point_sum_ranking() {
assert_eq!(
response,
json!([
{"user_id":"u1","point_sum":1,"count":1},
{"user_id":"u3","point_sum":1,"count":1}
{"user_id":"u1","count":1},
{"user_id":"u3","count":1}
])
);

Expand All @@ -61,7 +61,7 @@ async fn test_rated_point_sum_ranking() {
assert_eq!(
response,
json!([
{"user_id":"u2","point_sum":2,"count":2}
{"user_id":"u2","count":2}
])
);

Expand Down
34 changes: 2 additions & 32 deletions atcoder-problems-backend/tests/test_server_e2e_submissions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use actix_web::{http::StatusCode, test, App};
use atcoder_problems_backend::server::config_services;
use serde_json::Value;
use sql_client::models::Submission;
use sql_client::PgPool;
Expand Down Expand Up @@ -36,35 +35,6 @@ async fn prepare_data_set(conn: &PgPool) {
.unwrap();
}

#[actix_web::test]
async fn test_user_submissions() {
let pg_pool = utils::initialize_and_connect_to_test_sql().await;
prepare_data_set(&pg_pool).await;

let app = test::init_service(
App::new()
.app_data(actix_web::web::Data::new(pg_pool))
.configure(config_services),
)
.await;

let request = test::TestRequest::get()
.uri("/atcoder-api/results?user=u1")
.to_request();
let submissions: Vec<Submission> = test::call_and_read_body_json(&app, request).await;

assert_eq!(submissions.len(), 5);
assert!(submissions.iter().all(|s| s.user_id == "u1"));

let response = test::TestRequest::get()
.uri("/atcoder-api/results?user=u2")
.to_request();
let submissions: Vec<Submission> = test::call_and_read_body_json(&app, response).await;

assert_eq!(submissions.len(), 5);
assert!(submissions.iter().all(|s| s.user_id == "u2"));
}

#[actix_web::test]
async fn test_user_submissions_fromtime() {
let pg_pool = utils::initialize_and_connect_to_test_sql().await;
Expand Down Expand Up @@ -186,7 +156,7 @@ async fn test_invalid_path() {
assert_eq!(response.status(), StatusCode::NOT_FOUND);

let response = test::TestRequest::get()
.uri("/atcoder-api/results")
.uri("/atcoder-api/v3/user/submissions")
.send_request(&app)
.await;

Expand Down Expand Up @@ -256,7 +226,7 @@ async fn test_cors() {
);

let response = test::TestRequest::get()
.uri("/atcoder-api/results?user=u1")
.uri("/atcoder-api/v3/user/submissions?user=u1&from_second=0")
.send_request(&app)
.await;

Expand Down
28 changes: 7 additions & 21 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ https://kenkoooo.com/atcoder/atcoder-api/v3/ac_ranking?from=0&to=10
https://kenkoooo.com/atcoder/atcoder-api/v3/user/ac_rank?user=kenkoooo
```

Deprecated ~~https://kenkoooo.com/atcoder/resources/ac.json~~ This old API will be removed soon. You can see more detail about the plan ([#989](https://github.com/kenkoooo/AtCoderProblems/issues/989)).

### Rated Point Sum

#### Example


```
https://kenkoooo.com/atcoder/atcoder-api/v3/rated_point_sum_ranking?from=0&to=10
https://kenkoooo.com/atcoder/atcoder-api/v3/user/rated_point_sum_rank?user=kenkoooo
```

Deprecated ~~https://kenkoooo.com/atcoder/resources/sums.json~~ This old API will be removed soon. You can see more detail about the plan ([#1031](https://github.com/kenkoooo/AtCoderProblems/issues/1031)).

### Longest Streak (JST) Count

#### Example
Expand All @@ -59,8 +54,6 @@ https://kenkoooo.com/atcoder/atcoder-api/v3/streak_ranking?from=0&to=10
https://kenkoooo.com/atcoder/atcoder-api/v3/user/streak_rank?user=kenkoooo
```

Deprecated ~~https://kenkoooo.com/atcoder/resources/streaks.json~~ This old API will be removed soon. You can see more detail about the plan ([#981](https://github.com/kenkoooo/AtCoderProblems/issues/981)).

### Language List

#### Example
Expand All @@ -78,8 +71,6 @@ https://kenkoooo.com/atcoder/atcoder-api/v3/language_ranking?from=0&to=10&langua
https://kenkoooo.com/atcoder/atcoder-api/v3/user/language_rank?user=kenkoooo
```

Deprecated ~~https://kenkoooo.com/atcoder/resources/lang.json~~ This old API will be removed soon. You can see more detail about the plan ([#1002](https://github.com/kenkoooo/AtCoderProblems/issues/1002)).

## Submission API

### User Submissions
Expand All @@ -99,16 +90,6 @@ https://kenkoooo.com/atcoder/atcoder-api/v3/user/submissions?user={user_id}&from
https://kenkoooo.com/atcoder/atcoder-api/v3/user/submissions?user=chokudai&from_second=1560046356
```

### [Deprecated] ~~User Submissions~~

This API is deprecated. Please use `/v3/user/submissions` instead. You can see more detail about the deprecation plan ([#961](https://github.com/kenkoooo/AtCoderProblems/issues/961)).

#### Interface

```
https://kenkoooo.com/atcoder/atcoder-api/results?user={user_id}
```

### Submissions at the time

#### Interface
Expand All @@ -123,8 +104,13 @@ https://kenkoooo.com/atcoder/atcoder-api/v3/from/{unix_time_second}

## Deprecated

- `/v2/user_info`
- `/atcoder/atcoder-api/info/*`
- `/atcoder-api/v2/user_info`
- `/atcoder-api/info/*`
- `/atcoder-api/results`
- `/resources/ac.json`
- `/resources/lang.json`
- `/resources/streaks.json`
- `/resources/sums.json`

## Datasets

Expand Down

0 comments on commit 4bd8ed9

Please sign in to comment.