2022-02-27 20:43:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-06-25 20:46:51 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 07:04:34 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:immich_mobile/shared/services/api.service.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
final searchServiceProvider = Provider(
|
|
|
|
(ref) => SearchService(
|
|
|
|
ref.watch(apiServiceProvider),
|
|
|
|
),
|
|
|
|
);
|
2022-06-25 20:46:51 +02:00
|
|
|
|
2022-02-27 20:43:29 +02:00
|
|
|
class SearchService {
|
2022-07-13 14:23:48 +02:00
|
|
|
final ApiService _apiService;
|
2022-08-03 07:04:34 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
SearchService(this._apiService);
|
2022-02-27 20:43:29 +02:00
|
|
|
|
|
|
|
Future<List<String>?> getUserSuggestedSearchTerms() async {
|
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
return await _apiService.assetApi.getAssetSearchTerms();
|
2022-02-27 20:43:29 +02:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [getUserSuggestedSearchTerms] ${e.toString()}");
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2022-03-03 00:44:24 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
Future<List<AssetResponseDto>?> searchAsset(String searchTerm) async {
|
2022-03-03 00:44:24 +02:00
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
return await _apiService.assetApi
|
|
|
|
.searchAsset(SearchAssetDto(searchTerm: searchTerm));
|
2022-03-03 00:44:24 +02:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [searchAsset] ${e.toString()}");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-03-16 17:19:31 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
Future<List<CuratedLocationsResponseDto>?> getCuratedLocation() async {
|
2022-03-16 17:19:31 +02:00
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
var locations = await _apiService.assetApi.getCuratedLocations();
|
2022-03-16 17:19:31 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
return locations;
|
2022-03-16 17:19:31 +02:00
|
|
|
} catch (e) {
|
2022-07-13 14:23:48 +02:00
|
|
|
debugPrint("Error [getCuratedLocation] ${e.toString()}");
|
|
|
|
return [];
|
2022-03-16 17:19:31 +02:00
|
|
|
}
|
|
|
|
}
|
2022-03-27 21:58:54 +02:00
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
Future<List<CuratedObjectsResponseDto>?> getCuratedObjects() async {
|
2022-03-27 21:58:54 +02:00
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
return await _apiService.assetApi.getCuratedObjects();
|
2022-03-27 21:58:54 +02:00
|
|
|
} catch (e) {
|
2022-07-13 14:23:48 +02:00
|
|
|
debugPrint("Error [getCuratedObjects] ${e.toString()}");
|
|
|
|
throw [];
|
2022-03-27 21:58:54 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-27 20:43:29 +02:00
|
|
|
}
|