You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-09 23:17:29 +02:00
feat: Search filtering logic (#6968)
* commit * controller/service/repository logic * use enum * openapi * suggest people * suggest place/camera * cursor hover * refactor * Add try catch * Remove get people with name service * Remove deadcode * people selection * People placement * sort people * Update server/src/domain/repositories/metadata.repository.ts Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> * pr feedback * styling * done * open api * fix test * use string type * remmove bad merge * use correct type * fix test * fix lint * remove unused code * remove unused code * pr feedback * pr feedback --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
1
mobile/openapi/lib/api.dart
generated
1
mobile/openapi/lib/api.dart
generated
@@ -153,6 +153,7 @@ part 'model/search_explore_response_dto.dart';
|
||||
part 'model/search_facet_count_response_dto.dart';
|
||||
part 'model/search_facet_response_dto.dart';
|
||||
part 'model/search_response_dto.dart';
|
||||
part 'model/search_suggestion_type.dart';
|
||||
part 'model/server_config_dto.dart';
|
||||
part 'model/server_features_dto.dart';
|
||||
part 'model/server_info_response_dto.dart';
|
||||
|
82
mobile/openapi/lib/api/search_api.dart
generated
82
mobile/openapi/lib/api/search_api.dart
generated
@@ -60,11 +60,90 @@ class SearchApi {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'GET /search/suggestions' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [SearchSuggestionType] type (required):
|
||||
///
|
||||
/// * [String] country:
|
||||
///
|
||||
/// * [String] make:
|
||||
///
|
||||
/// * [String] model:
|
||||
///
|
||||
/// * [String] state:
|
||||
Future<Response> getSearchSuggestionsWithHttpInfo(SearchSuggestionType type, { String? country, String? make, String? model, String? state, }) async {
|
||||
// ignore: prefer_const_declarations
|
||||
final path = r'/search/suggestions';
|
||||
|
||||
// ignore: prefer_final_locals
|
||||
Object? postBody;
|
||||
|
||||
final queryParams = <QueryParam>[];
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
if (country != null) {
|
||||
queryParams.addAll(_queryParams('', 'country', country));
|
||||
}
|
||||
if (make != null) {
|
||||
queryParams.addAll(_queryParams('', 'make', make));
|
||||
}
|
||||
if (model != null) {
|
||||
queryParams.addAll(_queryParams('', 'model', model));
|
||||
}
|
||||
if (state != null) {
|
||||
queryParams.addAll(_queryParams('', 'state', state));
|
||||
}
|
||||
queryParams.addAll(_queryParams('', 'type', type));
|
||||
|
||||
const contentTypes = <String>[];
|
||||
|
||||
|
||||
return apiClient.invokeAPI(
|
||||
path,
|
||||
'GET',
|
||||
queryParams,
|
||||
postBody,
|
||||
headerParams,
|
||||
formParams,
|
||||
contentTypes.isEmpty ? null : contentTypes.first,
|
||||
);
|
||||
}
|
||||
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [SearchSuggestionType] type (required):
|
||||
///
|
||||
/// * [String] country:
|
||||
///
|
||||
/// * [String] make:
|
||||
///
|
||||
/// * [String] model:
|
||||
///
|
||||
/// * [String] state:
|
||||
Future<List<String>?> getSearchSuggestions(SearchSuggestionType type, { String? country, String? make, String? model, String? state, }) async {
|
||||
final response = await getSearchSuggestionsWithHttpInfo(type, country: country, make: make, model: model, state: state, );
|
||||
if (response.statusCode >= HttpStatus.badRequest) {
|
||||
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
||||
}
|
||||
// When a remote server returns no body with a status of 204, we shall not decode it.
|
||||
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
|
||||
// FormatException when trying to decode an empty string.
|
||||
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
|
||||
final responseBody = await _decodeBodyBytes(response);
|
||||
return (await apiClient.deserializeAsync(responseBody, 'List<String>') as List)
|
||||
.cast<String>()
|
||||
.toList(growable: false);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'GET /search' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [bool] clip:
|
||||
/// @deprecated
|
||||
///
|
||||
/// * [bool] motion:
|
||||
///
|
||||
@@ -142,7 +221,6 @@ class SearchApi {
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [bool] clip:
|
||||
/// @deprecated
|
||||
///
|
||||
/// * [bool] motion:
|
||||
///
|
||||
|
2
mobile/openapi/lib/api_client.dart
generated
2
mobile/openapi/lib/api_client.dart
generated
@@ -388,6 +388,8 @@ class ApiClient {
|
||||
return SearchFacetResponseDto.fromJson(value);
|
||||
case 'SearchResponseDto':
|
||||
return SearchResponseDto.fromJson(value);
|
||||
case 'SearchSuggestionType':
|
||||
return SearchSuggestionTypeTypeTransformer().decode(value);
|
||||
case 'ServerConfigDto':
|
||||
return ServerConfigDto.fromJson(value);
|
||||
case 'ServerFeaturesDto':
|
||||
|
3
mobile/openapi/lib/api_helper.dart
generated
3
mobile/openapi/lib/api_helper.dart
generated
@@ -109,6 +109,9 @@ String parameterToString(dynamic value) {
|
||||
if (value is ReactionType) {
|
||||
return ReactionTypeTypeTransformer().encode(value).toString();
|
||||
}
|
||||
if (value is SearchSuggestionType) {
|
||||
return SearchSuggestionTypeTypeTransformer().encode(value).toString();
|
||||
}
|
||||
if (value is SharedLinkType) {
|
||||
return SharedLinkTypeTypeTransformer().encode(value).toString();
|
||||
}
|
||||
|
94
mobile/openapi/lib/model/search_suggestion_type.dart
generated
Normal file
94
mobile/openapi/lib/model/search_suggestion_type.dart
generated
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
|
||||
class SearchSuggestionType {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const SearchSuggestionType._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const country = SearchSuggestionType._(r'country');
|
||||
static const state = SearchSuggestionType._(r'state');
|
||||
static const city = SearchSuggestionType._(r'city');
|
||||
static const cameraMake = SearchSuggestionType._(r'camera-make');
|
||||
static const cameraModel = SearchSuggestionType._(r'camera-model');
|
||||
|
||||
/// List of all possible values in this [enum][SearchSuggestionType].
|
||||
static const values = <SearchSuggestionType>[
|
||||
country,
|
||||
state,
|
||||
city,
|
||||
cameraMake,
|
||||
cameraModel,
|
||||
];
|
||||
|
||||
static SearchSuggestionType? fromJson(dynamic value) => SearchSuggestionTypeTypeTransformer().decode(value);
|
||||
|
||||
static List<SearchSuggestionType> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SearchSuggestionType>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SearchSuggestionType.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [SearchSuggestionType] to String,
|
||||
/// and [decode] dynamic data back to [SearchSuggestionType].
|
||||
class SearchSuggestionTypeTypeTransformer {
|
||||
factory SearchSuggestionTypeTypeTransformer() => _instance ??= const SearchSuggestionTypeTypeTransformer._();
|
||||
|
||||
const SearchSuggestionTypeTypeTransformer._();
|
||||
|
||||
String encode(SearchSuggestionType data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a SearchSuggestionType.
|
||||
///
|
||||
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||
///
|
||||
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||
/// and users are still using an old app with the old code.
|
||||
SearchSuggestionType? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case r'country': return SearchSuggestionType.country;
|
||||
case r'state': return SearchSuggestionType.state;
|
||||
case r'city': return SearchSuggestionType.city;
|
||||
case r'camera-make': return SearchSuggestionType.cameraMake;
|
||||
case r'camera-model': return SearchSuggestionType.cameraModel;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [SearchSuggestionTypeTypeTransformer] instance.
|
||||
static SearchSuggestionTypeTypeTransformer? _instance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user