File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ use crate::schema::area::Area;
44use crate :: schema:: climb:: Climb ;
55use crate :: AppData ;
66
7+ use super :: Image ;
8+
79#[ derive( SimpleObject , InputObject ) ]
810#[ graphql( input_name = "CoordinateInput" ) ]
911pub struct Coordinate {
@@ -161,4 +163,28 @@ impl Formation {
161163
162164 Ok ( climbs)
163165 }
166+
167+ async fn images ( & self , ctx : & Context < ' _ > ) -> Result < Vec < Image > > {
168+ let data = ctx. data :: < AppData > ( ) ?;
169+ let client = match & data. pg_pool {
170+ Some ( pool) => pool. get ( ) . await ?,
171+ None => {
172+ return Err ( "Database connection is not available" . into ( ) ) ;
173+ }
174+ } ;
175+
176+ let result = client
177+ . query (
178+ "SELECT image_id FROM formations_in_image WHERE formation_id = $1" ,
179+ & [ & self . 0 ] ,
180+ )
181+ . await ?;
182+
183+ let images = result
184+ . into_iter ( )
185+ . map ( |row| row. try_get ( 0 ) . map ( Image ) )
186+ . collect :: < Result < Vec < Image > , _ > > ( ) ?;
187+
188+ Ok ( images)
189+ }
164190}
You can’t perform that action at this time.
0 commit comments