File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed
atcoder-problems-backend/sql-client/src/internal Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: PgPool ;
2
- use anyhow:: { bail , Context , Result } ;
2
+ use anyhow:: { ensure , Context , Result } ;
3
3
use async_trait:: async_trait;
4
4
use serde:: Serialize ;
5
5
use sqlx:: Row ;
@@ -152,9 +152,8 @@ impl ProblemListManager for PgPool {
152
152
let new_list_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
153
153
154
154
let list = self . get_list ( internal_user_id) . await ?;
155
- if list. len ( ) >= MAX_LIST_NUM {
156
- bail ! ( "Cannot create a list anymore" ) ;
157
- }
155
+
156
+ ensure ! ( list. len( ) < MAX_LIST_NUM , "Cannot create a list anymore" ) ;
158
157
159
158
sqlx:: query (
160
159
r"
@@ -202,9 +201,11 @@ impl ProblemListManager for PgPool {
202
201
. try_map ( |row| row. try_get :: < String , _ > ( "problem_id" ) )
203
202
. fetch_all ( self )
204
203
. await ?;
205
- if problems. len ( ) >= MAX_ITEM_NUM {
206
- bail ! ( "Cannot create a list item anymore" ) ;
207
- }
204
+
205
+ ensure ! (
206
+ problems. len( ) < MAX_ITEM_NUM ,
207
+ "Cannot create a list item anymore"
208
+ ) ;
208
209
209
210
sqlx:: query (
210
211
r"
Original file line number Diff line number Diff line change 1
1
use crate :: PgPool ;
2
- use anyhow:: { bail , Context , Result } ;
2
+ use anyhow:: { ensure , Context , Result } ;
3
3
use async_trait:: async_trait;
4
4
use serde:: { Deserialize , Serialize } ;
5
5
use sqlx:: Row ;
@@ -332,9 +332,10 @@ impl VirtualContestManager for PgPool {
332
332
problems : & [ VirtualContestItem ] ,
333
333
user_id : & str ,
334
334
) -> Result < ( ) > {
335
- if problems. len ( ) > MAX_PROBLEM_NUM_PER_CONTEST {
336
- bail ! ( "The number of problems exceeded." ) ;
337
- }
335
+ ensure ! (
336
+ problems. len( ) <= MAX_PROBLEM_NUM_PER_CONTEST ,
337
+ "The number of problems exceeded."
338
+ ) ;
338
339
339
340
// Checks if the target contest exists
340
341
sqlx:: query (
You can’t perform that action at this time.
0 commit comments