Skip to content

Commit

Permalink
Merge pull request #1367 from hotate29/case-insensitive
Browse files Browse the repository at this point in the history
Case insensitive漏れを修正
  • Loading branch information
kenkoooo authored Mar 7, 2023
2 parents d8fd2f4 + d71c24c commit b2e15eb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion atcoder-problems-backend/sql-client/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Problem {
pub title: String,
}

#[derive(Debug, Clone, Serialize, Default, Deserialize, sqlx::FromRow)]
#[derive(Debug, Clone, PartialEq, Serialize, Default, Deserialize, sqlx::FromRow)]
pub struct Submission {
pub id: i64,
pub epoch_second: i64,
Expand Down
4 changes: 2 additions & 2 deletions atcoder-problems-backend/sql-client/src/submission_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl SubmissionClient for PgPool {
r"
SELECT * FROM submissions
WHERE result = 'AC'
AND LOWER(user_id) = ANY($1)
AND LOWER(user_id) = ANY(SELECT LOWER(u) FROM UNNEST($1) AS a(u))
",
)
.bind(user_ids)
Expand Down Expand Up @@ -163,7 +163,7 @@ impl SubmissionClient for PgPool {
} => sqlx::query_as(
r"
SELECT * FROM submissions
WHERE LOWER(user_id) = ANY($1)
WHERE LOWER(user_id) = ANY(SELECT LOWER(u) FROM UNNEST($1) AS a(u))
AND problem_id = ANY($2)
AND epoch_second >= $3
AND epoch_second <= $4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,63 @@ async fn test_update_submissions() {
assert_eq!(submissions[0].point, 100.0);
assert_eq!(submissions[0].execution_time, Some(1));
}

#[sqlx::test]
async fn case_insensitive() {
let pool = utils::initialize_and_connect_to_test_sql().await;

let submission = Submission {
id: 0,
user_id: "CASE_insensitive".to_owned(),
result: "AC".to_owned(),
point: 100.0,
execution_time: Some(1),
problem_id: "test-problem".to_owned(),
..Default::default()
};

pool.update_submissions(&[submission.clone()])
.await
.unwrap();

let submissions = pool
.get_submissions(SubmissionRequest::FromUserAndTime {
user_id: "case_INSENSITIVE",
from_second: 0,
count: 1,
})
.await
.unwrap();

assert_eq!(submissions, &[submission.clone()]);

let submissions = pool
.get_submissions(SubmissionRequest::UserAll {
user_id: "case_INSENSITIVE",
})
.await
.unwrap();

assert_eq!(submissions, &[submission.clone()]);

let submissions = pool
.get_submissions(SubmissionRequest::UsersAccepted {
user_ids: &["case_INSENSITIVE"],
})
.await
.unwrap();

assert_eq!(submissions, &[submission.clone()]);

let submissions = pool
.get_submissions(SubmissionRequest::UsersProblemsTime {
user_ids: &["case_INSENSITIVE"],
problem_ids: &["test-problem"],
from_second: 0,
to_second: 1,
})
.await
.unwrap();

assert_eq!(submissions, &[submission.clone()]);
}

0 comments on commit b2e15eb

Please sign in to comment.