2024-03-20 19:32:04 +01:00
import { Body , Controller , Get , HttpCode , HttpStatus , Post , Query } from '@nestjs/common' ;
2025-11-11 17:01:14 -05:00
import { ApiOperation , ApiTags } from '@nestjs/swagger' ;
2024-03-20 23:53:07 +01:00
import { AssetResponseDto } from 'src/dtos/asset-response.dto' ;
import { AuthDto } from 'src/dtos/auth.dto' ;
import { PersonResponseDto } from 'src/dtos/person.dto' ;
2023-10-10 16:34:25 +02:00
import {
2025-07-29 00:48:39 +02:00
LargeAssetSearchDto ,
2024-02-12 20:50:47 -05:00
MetadataSearchDto ,
2024-02-24 01:42:37 +01:00
PlacesResponseDto ,
2024-09-23 12:09:26 -04:00
RandomSearchDto ,
2024-03-20 23:53:07 +01:00
SearchExploreResponseDto ,
2023-10-10 16:34:25 +02:00
SearchPeopleDto ,
2024-02-24 01:42:37 +01:00
SearchPlacesDto ,
2024-03-20 23:53:07 +01:00
SearchResponseDto ,
2025-06-07 11:12:53 +10:00
SearchStatisticsResponseDto ,
2024-03-20 23:53:07 +01:00
SearchSuggestionRequestDto ,
2024-02-12 20:50:47 -05:00
SmartSearchDto ,
2025-06-07 11:12:53 +10:00
StatisticsSearchDto ,
2024-03-20 23:53:07 +01:00
} from 'src/dtos/search.dto' ;
2025-11-11 17:01:14 -05:00
import { ApiTag , Permission } from 'src/enum' ;
2024-03-20 15:15:01 -05:00
import { Auth , Authenticated } from 'src/middleware/auth.guard' ;
2024-03-21 00:07:30 +01:00
import { SearchService } from 'src/services/search.service' ;
2023-03-02 21:47:08 -05:00
2025-11-11 17:01:14 -05:00
@ApiTags ( ApiTag . Search )
2023-03-02 21:47:08 -05:00
@Controller ( 'search' )
export class SearchController {
2023-03-24 00:53:56 -04:00
constructor ( private service : SearchService ) { }
2023-03-02 21:47:08 -05:00
2024-02-17 11:00:55 -06:00
@Post ( 'metadata' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search assets by metadata' ,
description : 'Search for assets based on various metadata criteria.' ,
} )
2024-11-20 14:47:25 -05:00
searchAssets ( @Auth ( ) auth : AuthDto , @Body ( ) dto : MetadataSearchDto ) : Promise < SearchResponseDto > {
2024-02-12 20:50:47 -05:00
return this . service . searchMetadata ( auth , dto ) ;
}
2025-06-07 11:12:53 +10:00
@Post ( 'statistics' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetStatistics } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search asset statistics' ,
description : 'Retrieve statistical data about assets based on search criteria, such as the total matching count.' ,
} )
2025-06-07 11:12:53 +10:00
searchAssetStatistics ( @Auth ( ) auth : AuthDto , @Body ( ) dto : StatisticsSearchDto ) : Promise < SearchStatisticsResponseDto > {
return this . service . searchStatistics ( auth , dto ) ;
}
2024-09-23 12:09:26 -04:00
@Post ( 'random' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search random assets' ,
description : 'Retrieve a random selection of assets based on the provided criteria.' ,
} )
2024-09-30 00:29:35 -04:00
searchRandom ( @Auth ( ) auth : AuthDto , @Body ( ) dto : RandomSearchDto ) : Promise < AssetResponseDto [ ] > {
2024-09-23 12:09:26 -04:00
return this . service . searchRandom ( auth , dto ) ;
}
2025-07-29 00:48:39 +02:00
@Post ( 'large-assets' )
@Authenticated ( { permission : Permission.AssetRead } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search large assets' ,
description : 'Search for assets that are considered large based on specified criteria.' ,
} )
2025-07-29 00:48:39 +02:00
searchLargeAssets ( @Auth ( ) auth : AuthDto , @Query ( ) dto : LargeAssetSearchDto ) : Promise < AssetResponseDto [ ] > {
return this . service . searchLargeAssets ( auth , dto ) ;
}
2024-02-17 11:00:55 -06:00
@Post ( 'smart' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Smart asset search' ,
description : 'Perform a smart search for assets by using machine learning vectors to determine relevance.' ,
} )
2024-02-17 11:00:55 -06:00
searchSmart ( @Auth ( ) auth : AuthDto , @Body ( ) dto : SmartSearchDto ) : Promise < SearchResponseDto > {
2024-02-12 20:50:47 -05:00
return this . service . searchSmart ( auth , dto ) ;
}
2023-03-05 15:44:31 -05:00
@Get ( 'explore' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Retrieve explore data' ,
description : 'Retrieve data for the explore section, such as popular people and places.' ,
} )
2023-12-09 23:34:12 -05:00
getExploreData ( @Auth ( ) auth : AuthDto ) : Promise < SearchExploreResponseDto [ ] > {
2025-04-30 13:41:23 -04:00
return this . service . getExploreData ( auth ) ;
2023-03-05 15:44:31 -05:00
}
2023-11-25 15:46:20 +00:00
@Get ( 'person' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.PersonRead } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search people' ,
description : 'Search for people by name.' ,
} )
2023-12-09 23:34:12 -05:00
searchPerson ( @Auth ( ) auth : AuthDto , @Query ( ) dto : SearchPeopleDto ) : Promise < PersonResponseDto [ ] > {
return this . service . searchPerson ( auth , dto ) ;
2023-11-25 15:46:20 +00:00
}
2024-02-13 13:54:58 -06:00
2024-02-24 01:42:37 +01:00
@Get ( 'places' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Search places' ,
description : 'Search for places by name.' ,
} )
2024-02-24 01:42:37 +01:00
searchPlaces ( @Query ( ) dto : SearchPlacesDto ) : Promise < PlacesResponseDto [ ] > {
return this . service . searchPlaces ( dto ) ;
}
2024-03-19 23:23:57 -04:00
@Get ( 'cities' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Retrieve assets by city' ,
description :
'Retrieve a list of assets with each asset belonging to a different city. This endpoint is used on the places pages to show a single thumbnail for each city the user has assets in.' ,
} )
2024-03-19 23:23:57 -04:00
getAssetsByCity ( @Auth ( ) auth : AuthDto ) : Promise < AssetResponseDto [ ] > {
return this . service . getAssetsByCity ( auth ) ;
}
2024-02-13 13:54:58 -06:00
@Get ( 'suggestions' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.AssetRead } )
2025-11-11 17:01:14 -05:00
@ApiOperation ( {
summary : 'Retrieve search suggestions' ,
description :
'Retrieve search suggestions based on partial input. This endpoint is used for typeahead search features.' ,
} )
2024-02-13 13:54:58 -06:00
getSearchSuggestions ( @Auth ( ) auth : AuthDto , @Query ( ) dto : SearchSuggestionRequestDto ) : Promise < string [ ] > {
2024-08-01 21:27:40 -06:00
// TODO fix open api generation to indicate that results can be nullable
return this . service . getSearchSuggestions ( auth , dto ) as Promise < string [ ] > ;
2024-02-13 13:54:58 -06:00
}
2023-03-02 21:47:08 -05:00
}