@@ -1058,6 +1058,35 @@ impl MutationRoot {
10581058 Ok ( Climb ( id) )
10591059 }
10601060
1061+ async fn add_climber < ' a > (
1062+ & self ,
1063+ ctx : & Context < ' a > ,
1064+ #[ graphql( desc = "First name" ) ] first_name : String ,
1065+ #[ graphql( desc = "Last name" ) ] last_name : String ,
1066+ ) -> Result < Climber > {
1067+ let data = ctx. data :: < AppData > ( ) ?;
1068+ let client = match & data. pg_pool {
1069+ Some ( pool) => pool. get ( ) . await ?,
1070+ None => {
1071+ return Err ( "Database connection is not available" . into ( ) ) ;
1072+ }
1073+ } ;
1074+
1075+ let id = client
1076+ . query_one (
1077+ "
1078+ INSERT INTO climbers (first_name, last_name)
1079+ VALUES ($1, $2)
1080+ RETURNING id
1081+ " ,
1082+ & [ & first_name, & last_name] ,
1083+ )
1084+ . await ?
1085+ . get :: < _ , i32 > ( 0 ) ;
1086+
1087+ Ok ( Climber ( id) )
1088+ }
1089+
10611090 async fn remove_climb_grade < ' a > (
10621091 & self ,
10631092 ctx : & Context < ' a > ,
@@ -1108,6 +1137,28 @@ impl MutationRoot {
11081137 Ok ( Climb ( id) )
11091138 }
11101139
1140+ async fn remove_climber < ' a > (
1141+ & self ,
1142+ ctx : & Context < ' a > ,
1143+ #[ graphql( desc = "Climber id" ) ] id : ID ,
1144+ ) -> Result < Climber > {
1145+ let id: i32 = id. 0 . parse ( ) . map_err ( |_| "Invalid ID format" ) ?;
1146+ let data = ctx. data :: < AppData > ( ) ?;
1147+ let client = match & data. pg_pool {
1148+ Some ( pool) => pool. get ( ) . await ?,
1149+ None => {
1150+ return Err ( "Database connection is not available" . into ( ) ) ;
1151+ }
1152+ } ;
1153+
1154+ client
1155+ . execute ( "DELETE FROM climbers WHERE id = $1" , & [ & id] )
1156+ . await ?;
1157+
1158+ // TODO Does this make sense?
1159+ Ok ( Climber ( id) )
1160+ }
1161+
11111162 async fn add_formation < ' a > (
11121163 & self ,
11131164 ctx : & Context < ' a > ,
0 commit comments