Skip to content

Commit b2e15eb

Browse files
authored
Merge pull request #1367 from hotate29/case-insensitive
Case insensitive漏れを修正
2 parents d8fd2f4 + d71c24c commit b2e15eb

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

atcoder-problems-backend/sql-client/src/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Problem {
1818
pub title: String,
1919
}
2020

21-
#[derive(Debug, Clone, Serialize, Default, Deserialize, sqlx::FromRow)]
21+
#[derive(Debug, Clone, PartialEq, Serialize, Default, Deserialize, sqlx::FromRow)]
2222
pub struct Submission {
2323
pub id: i64,
2424
pub epoch_second: i64,

atcoder-problems-backend/sql-client/src/submission_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl SubmissionClient for PgPool {
121121
r"
122122
SELECT * FROM submissions
123123
WHERE result = 'AC'
124-
AND LOWER(user_id) = ANY($1)
124+
AND LOWER(user_id) = ANY(SELECT LOWER(u) FROM UNNEST($1) AS a(u))
125125
",
126126
)
127127
.bind(user_ids)
@@ -163,7 +163,7 @@ impl SubmissionClient for PgPool {
163163
} => sqlx::query_as(
164164
r"
165165
SELECT * FROM submissions
166-
WHERE LOWER(user_id) = ANY($1)
166+
WHERE LOWER(user_id) = ANY(SELECT LOWER(u) FROM UNNEST($1) AS a(u))
167167
AND problem_id = ANY($2)
168168
AND epoch_second >= $3
169169
AND epoch_second <= $4

atcoder-problems-backend/sql-client/tests/test_submission_client.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,63 @@ async fn test_update_submissions() {
193193
assert_eq!(submissions[0].point, 100.0);
194194
assert_eq!(submissions[0].execution_time, Some(1));
195195
}
196+
197+
#[sqlx::test]
198+
async fn case_insensitive() {
199+
let pool = utils::initialize_and_connect_to_test_sql().await;
200+
201+
let submission = Submission {
202+
id: 0,
203+
user_id: "CASE_insensitive".to_owned(),
204+
result: "AC".to_owned(),
205+
point: 100.0,
206+
execution_time: Some(1),
207+
problem_id: "test-problem".to_owned(),
208+
..Default::default()
209+
};
210+
211+
pool.update_submissions(&[submission.clone()])
212+
.await
213+
.unwrap();
214+
215+
let submissions = pool
216+
.get_submissions(SubmissionRequest::FromUserAndTime {
217+
user_id: "case_INSENSITIVE",
218+
from_second: 0,
219+
count: 1,
220+
})
221+
.await
222+
.unwrap();
223+
224+
assert_eq!(submissions, &[submission.clone()]);
225+
226+
let submissions = pool
227+
.get_submissions(SubmissionRequest::UserAll {
228+
user_id: "case_INSENSITIVE",
229+
})
230+
.await
231+
.unwrap();
232+
233+
assert_eq!(submissions, &[submission.clone()]);
234+
235+
let submissions = pool
236+
.get_submissions(SubmissionRequest::UsersAccepted {
237+
user_ids: &["case_INSENSITIVE"],
238+
})
239+
.await
240+
.unwrap();
241+
242+
assert_eq!(submissions, &[submission.clone()]);
243+
244+
let submissions = pool
245+
.get_submissions(SubmissionRequest::UsersProblemsTime {
246+
user_ids: &["case_INSENSITIVE"],
247+
problem_ids: &["test-problem"],
248+
from_second: 0,
249+
to_second: 1,
250+
})
251+
.await
252+
.unwrap();
253+
254+
assert_eq!(submissions, &[submission.clone()]);
255+
}

0 commit comments

Comments
 (0)