@@ -15,6 +15,7 @@ use crate::{
1515 datasets:: {
1616 DatasetName ,
1717 listing:: { DatasetListOptions , DatasetListing , DatasetProvider } ,
18+ postgres:: DatasetTileId ,
1819 storage:: { AutoCreateDataset , DatasetStore , SuggestMetaData } ,
1920 upload:: { AdjustFilePath , Upload , UploadDb , UploadId , UploadRootPath , VolumeName , Volumes } ,
2021 } ,
@@ -28,7 +29,7 @@ use crate::{
2829} ;
2930use actix_web:: {
3031 FromRequest , HttpResponse , HttpResponseBuilder , Responder ,
31- web:: { self , Json } ,
32+ web:: { self , Json , Query } ,
3233} ;
3334use gdal:: {
3435 DatasetOptions ,
@@ -63,7 +64,8 @@ use std::{
6364 convert:: { TryFrom , TryInto } ,
6465 path:: Path ,
6566} ;
66- use utoipa:: { ToResponse , ToSchema } ;
67+ use utoipa:: { IntoParams , ToResponse , ToSchema } ;
68+ use validator:: Validate ;
6769
6870pub ( crate ) fn init_dataset_routes < C > ( cfg : & mut web:: ServiceConfig )
6971where
9698 )
9799 . service (
98100 web:: resource ( "/{dataset}/tiles" )
99- . route ( web:: post ( ) . to ( add_dataset_tiles_handler :: < C > ) ) ,
101+ . route ( web:: post ( ) . to ( add_dataset_tiles_handler :: < C > ) )
102+ . route ( web:: get ( ) . to ( get_dataset_tiles_handler :: < C > ) ) ,
100103 )
101104 . service (
102105 web:: resource ( "/{dataset}" )
@@ -246,7 +249,6 @@ pub async fn add_dataset_tiles_handler<C: ApplicationContext>(
246249 & dataset
247250 . data_path
248251 . ok_or ( AddDatasetTilesError :: DatasetIsMissingDataPath ) ?,
249- & session_context,
250252 )
251253 . context ( CannotAddTilesToDataset ) ?;
252254
@@ -345,24 +347,17 @@ fn validate_tile(
345347 Ok ( ( ) )
346348}
347349
348- fn file_path_from_data_path < T : SessionContext > (
349- data_path : & DataPath ,
350- session_context : & T ,
351- ) -> Result < std:: path:: PathBuf > {
350+ fn file_path_from_data_path ( data_path : & DataPath ) -> Result < std:: path:: PathBuf > {
352351 Ok ( match data_path {
353- DataPath :: Volume ( volume_name) => session_context
354- . volumes ( ) ?
352+ DataPath :: Volume ( volume_name) => Volumes :: default ( )
353+ . volumes
355354 . iter ( )
356- . find ( |v| v. name == volume_name. 0 )
355+ . find ( |v| v. name == * volume_name)
357356 . ok_or ( Error :: UnknownVolumeName {
358357 volume_name : volume_name. 0 . clone ( ) ,
359358 } ) ?
360359 . path
361- . clone ( )
362- . ok_or ( Error :: CannotAccessVolumePath {
363- volume_name : volume_name. 0 . clone ( ) ,
364- } ) ?
365- . into ( ) ,
360+ . clone ( ) ,
366361 DataPath :: Upload ( upload_id) => upload_id. root_path ( ) ?,
367362 } )
368363}
@@ -445,6 +440,71 @@ pub async fn get_dataset_handler<C: ApplicationContext>(
445440 Ok ( web:: Json ( dataset) )
446441}
447442
443+ #[ derive( Clone , Serialize , Deserialize , PartialEq , Debug , ToSchema ) ]
444+ pub struct DatasetTile {
445+ pub id : DatasetTileId ,
446+ pub time : crate :: api:: model:: datatypes:: TimeInterval ,
447+ pub spatial_partition : SpatialPartition2D ,
448+ pub band : u32 ,
449+ pub z_index : u32 ,
450+ pub params : GdalDatasetParameters ,
451+ }
452+
453+ #[ derive( Debug , Deserialize , IntoParams , Validate ) ]
454+ pub struct GetDatasetTilesParams {
455+ pub offset : u32 ,
456+ #[ validate( range( min = 1 , max = 100 ) ) ]
457+ pub limit : u32 ,
458+ // TODO: filter by time, space, filename, ...
459+ }
460+
461+ /// Retrieves details about a dataset using the internal name.
462+ #[ utoipa:: path(
463+ tag = "Datasets" ,
464+ get,
465+ path = "/dataset/{dataset}/tiles" ,
466+ responses(
467+ ( status = 200 , description = "OK" , body = Vec <DatasetTile >) ,
468+ ( status = 401 , response = crate :: api:: model:: responses:: UnauthorizedUserResponse )
469+ ) ,
470+ params(
471+ ( "dataset" = DatasetName , description = "Dataset Name" ) ,
472+ GetDatasetTilesParams
473+ ) ,
474+ security(
475+ ( "session_token" = [ ] )
476+ )
477+ ) ]
478+ pub async fn get_dataset_tiles_handler < C : ApplicationContext > (
479+ dataset : web:: Path < DatasetName > ,
480+ session : C :: Session ,
481+ params : Query < GetDatasetTilesParams > ,
482+ app_ctx : web:: Data < C > ,
483+ ) -> Result < impl Responder , GetDatasetTilesError > {
484+ let session_ctx = app_ctx. session_context ( session) . db ( ) ;
485+
486+ let real_dataset = dataset. into_inner ( ) ;
487+
488+ let dataset_id = session_ctx
489+ . resolve_dataset_name_to_id ( & real_dataset)
490+ . await
491+ . context ( CannotLoadDatasetForGettingTiles ) ?;
492+
493+ // handle the case where the dataset name is not known
494+ let dataset_id = dataset_id
495+ . ok_or ( error:: Error :: UnknownDatasetName {
496+ dataset_name : real_dataset. to_string ( ) ,
497+ } )
498+ . context ( CannotLoadDatasetForGettingTiles ) ?;
499+
500+ let tiles = session_ctx
501+ . get_dataset_tiles ( dataset_id, & params. into_inner ( ) )
502+ . await
503+ . context ( CannotLoadDatasetTiles ) ?;
504+
505+ Ok ( web:: Json ( tiles) )
506+ }
507+
448508/// Update details about a dataset using the internal name.
449509#[ utoipa:: path(
450510 tag = "Datasets" ,
0 commit comments