2022-06-26 03:46:51 +09:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2025-07-18 04:25:25 +08:00
|
|
|
import 'package:immich_mobile/infrastructure/repositories/search_api.repository.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
2025-07-18 04:25:25 +08:00
|
|
|
import 'package:immich_mobile/providers/infrastructure/search.provider.dart';
|
2024-05-02 15:59:14 -05:00
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2026-04-15 23:00:27 +05:30
|
|
|
import 'package:immich_mobile/utils/debug_print.dart';
|
2024-04-26 00:49:31 -05:00
|
|
|
import 'package:logging/logging.dart';
|
2022-07-13 07:23:48 -05:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-27 12:43:29 -06:00
|
|
|
|
2022-07-13 07:23:48 -05:00
|
|
|
final searchServiceProvider = Provider(
|
2026-04-15 23:00:27 +05:30
|
|
|
(ref) => SearchService(ref.watch(apiServiceProvider), ref.watch(searchApiRepositoryProvider)),
|
2022-07-13 07:23:48 -05:00
|
|
|
);
|
2022-06-26 03:46:51 +09:00
|
|
|
|
2022-02-27 12:43:29 -06:00
|
|
|
class SearchService {
|
2022-07-13 07:23:48 -05:00
|
|
|
final ApiService _apiService;
|
2025-07-18 04:25:25 +08:00
|
|
|
final SearchApiRepository _searchApiRepository;
|
2022-08-03 00:04:34 -05:00
|
|
|
|
2024-04-26 00:49:31 -05:00
|
|
|
final _log = Logger("SearchService");
|
2026-04-15 23:00:27 +05:30
|
|
|
SearchService(this._apiService, this._searchApiRepository);
|
2022-02-27 12:43:29 -06:00
|
|
|
|
2024-04-01 09:45:11 -05:00
|
|
|
Future<List<String>?> getSearchSuggestions(
|
|
|
|
|
SearchSuggestionType type, {
|
|
|
|
|
String? country,
|
|
|
|
|
String? state,
|
|
|
|
|
String? make,
|
|
|
|
|
String? model,
|
2023-03-28 10:34:06 -05:00
|
|
|
}) async {
|
2022-03-02 16:44:24 -06:00
|
|
|
try {
|
2025-07-18 04:25:25 +08:00
|
|
|
return await _searchApiRepository.getSearchSuggestions(
|
2024-04-01 09:45:11 -05:00
|
|
|
type,
|
|
|
|
|
country: country,
|
|
|
|
|
state: state,
|
|
|
|
|
make: make,
|
|
|
|
|
model: model,
|
2023-03-28 10:34:06 -05:00
|
|
|
);
|
2024-04-01 09:45:11 -05:00
|
|
|
} catch (e) {
|
2026-07-30 01:56:46 -07:00
|
|
|
dPrint(() => "[ERROR] [getSearchSuggestions] $e");
|
2024-04-01 09:45:11 -05:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 00:49:31 -05:00
|
|
|
Future<List<SearchExploreResponseDto>?> getExploreData() async {
|
2022-03-27 14:58:54 -05:00
|
|
|
try {
|
2024-04-26 00:49:31 -05:00
|
|
|
return await _apiService.searchApi.getExploreData();
|
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
|
_log.severe("Failed to getExploreData", error, stackTrace);
|
2022-03-27 14:58:54 -05:00
|
|
|
}
|
2024-04-26 00:49:31 -05:00
|
|
|
return null;
|
2022-03-27 14:58:54 -05:00
|
|
|
}
|
2024-04-30 22:14:33 -05:00
|
|
|
|
|
|
|
|
Future<List<AssetResponseDto>?> getAllPlaces() async {
|
|
|
|
|
try {
|
|
|
|
|
return await _apiService.searchApi.getAssetsByCity();
|
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
|
_log.severe("Failed to getAllPlaces", error, stackTrace);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-02-27 12:43:29 -06:00
|
|
|
}
|