mirror of
https://github.com/immich-app/immich.git
synced 2026-01-13 00:05:02 -05:00
* Allow submission of null country
* Update searchAssetBuilder to handle nulls
andWhere({country:null}) produces `"exifInfo"."country" = NULL`. We want
`"exifInfo"."country" IS NULL`, so we have to treat NULL as a special
case
* Allow null country in frontend
* Make the query code a bit more straightforward
* Remove unused brackets import
* Remove log message
* Don't change whitespace for no reason
* Fix prettier style issue
* Update search.dto.ts validators per @jrasm91's recommendation
* Update api types
* Combine null country and state into one guard clause
* chore: clean up
* chore: add e2e for null/empty city, state, country search
* refactor: server returns suggestion for null values
* chore: clean up
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
Co-authored-by: Jason Rasmussen <jason@rasm.me>
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { Body, Controller, Get, HttpCode, HttpStatus, Post, Query } from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
import { PersonResponseDto } from 'src/dtos/person.dto';
|
|
import {
|
|
MetadataSearchDto,
|
|
PlacesResponseDto,
|
|
SearchExploreResponseDto,
|
|
SearchPeopleDto,
|
|
SearchPlacesDto,
|
|
SearchResponseDto,
|
|
SearchSuggestionRequestDto,
|
|
SmartSearchDto,
|
|
} from 'src/dtos/search.dto';
|
|
import { Auth, Authenticated } from 'src/middleware/auth.guard';
|
|
import { SearchService } from 'src/services/search.service';
|
|
|
|
@ApiTags('Search')
|
|
@Controller('search')
|
|
export class SearchController {
|
|
constructor(private service: SearchService) {}
|
|
|
|
@Post('metadata')
|
|
@HttpCode(HttpStatus.OK)
|
|
@Authenticated()
|
|
searchMetadata(@Auth() auth: AuthDto, @Body() dto: MetadataSearchDto): Promise<SearchResponseDto> {
|
|
return this.service.searchMetadata(auth, dto);
|
|
}
|
|
|
|
@Post('smart')
|
|
@HttpCode(HttpStatus.OK)
|
|
@Authenticated()
|
|
searchSmart(@Auth() auth: AuthDto, @Body() dto: SmartSearchDto): Promise<SearchResponseDto> {
|
|
return this.service.searchSmart(auth, dto);
|
|
}
|
|
|
|
@Get('explore')
|
|
@Authenticated()
|
|
getExploreData(@Auth() auth: AuthDto): Promise<SearchExploreResponseDto[]> {
|
|
return this.service.getExploreData(auth) as Promise<SearchExploreResponseDto[]>;
|
|
}
|
|
|
|
@Get('person')
|
|
@Authenticated()
|
|
searchPerson(@Auth() auth: AuthDto, @Query() dto: SearchPeopleDto): Promise<PersonResponseDto[]> {
|
|
return this.service.searchPerson(auth, dto);
|
|
}
|
|
|
|
@Get('places')
|
|
@Authenticated()
|
|
searchPlaces(@Query() dto: SearchPlacesDto): Promise<PlacesResponseDto[]> {
|
|
return this.service.searchPlaces(dto);
|
|
}
|
|
|
|
@Get('cities')
|
|
@Authenticated()
|
|
getAssetsByCity(@Auth() auth: AuthDto): Promise<AssetResponseDto[]> {
|
|
return this.service.getAssetsByCity(auth);
|
|
}
|
|
|
|
@Get('suggestions')
|
|
@Authenticated()
|
|
getSearchSuggestions(@Auth() auth: AuthDto, @Query() dto: SearchSuggestionRequestDto): Promise<string[]> {
|
|
// TODO fix open api generation to indicate that results can be nullable
|
|
return this.service.getSearchSuggestions(auth, dto) as Promise<string[]>;
|
|
}
|
|
}
|