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 11use crate :: PgPool ;
2- use anyhow:: { bail , Context , Result } ;
2+ use anyhow:: { ensure , Context , Result } ;
33use async_trait:: async_trait;
44use serde:: Serialize ;
55use sqlx:: Row ;
@@ -152,9 +152,8 @@ impl ProblemListManager for PgPool {
152152 let new_list_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
153153
154154 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" ) ;
158157
159158 sqlx:: query (
160159 r"
@@ -202,9 +201,11 @@ impl ProblemListManager for PgPool {
202201 . try_map ( |row| row. try_get :: < String , _ > ( "problem_id" ) )
203202 . fetch_all ( self )
204203 . 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+ ) ;
208209
209210 sqlx:: query (
210211 r"
Original file line number Diff line number Diff line change 11use crate :: PgPool ;
2- use anyhow:: { bail , Context , Result } ;
2+ use anyhow:: { ensure , Context , Result } ;
33use async_trait:: async_trait;
44use serde:: { Deserialize , Serialize } ;
55use sqlx:: Row ;
@@ -332,9 +332,10 @@ impl VirtualContestManager for PgPool {
332332 problems : & [ VirtualContestItem ] ,
333333 user_id : & str ,
334334 ) -> 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+ ) ;
338339
339340 // Checks if the target contest exists
340341 sqlx:: query (
You can’t perform that action at this time.
0 commit comments