2022-02-27 20:43:29 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-06-25 20:46:51 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-03-16 17:19:31 +02:00
|
|
|
import 'package:immich_mobile/modules/search/models/curated_location.model.dart';
|
2022-03-27 21:58:54 +02:00
|
|
|
import 'package:immich_mobile/modules/search/models/curated_object.model.dart';
|
2022-03-03 00:44:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
import 'package:immich_mobile/shared/services/network.service.dart';
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
final searchServiceProvider =
|
|
|
|
Provider((ref) => SearchService(ref.watch(networkServiceProvider)));
|
|
|
|
|
2022-02-27 20:43:29 +02:00
|
|
|
class SearchService {
|
2022-06-25 20:46:51 +02:00
|
|
|
final NetworkService _networkService;
|
|
|
|
SearchService(this._networkService);
|
2022-02-27 20:43:29 +02:00
|
|
|
|
|
|
|
Future<List<String>?> getUserSuggestedSearchTerms() async {
|
|
|
|
try {
|
|
|
|
var res = await _networkService.getRequest(url: "asset/searchTerm");
|
|
|
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
|
|
|
|
|
|
|
return List.from(decodedData);
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [getUserSuggestedSearchTerms] ${e.toString()}");
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2022-03-03 00:44:24 +02:00
|
|
|
|
|
|
|
Future<List<ImmichAsset>?> searchAsset(String searchTerm) async {
|
|
|
|
try {
|
|
|
|
var res = await _networkService.postRequest(
|
|
|
|
url: "asset/search",
|
|
|
|
data: {"searchTerm": searchTerm},
|
|
|
|
);
|
|
|
|
|
|
|
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
List<ImmichAsset> result =
|
|
|
|
List.from(decodedData.map((a) => ImmichAsset.fromMap(a)));
|
2022-03-03 00:44:24 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [searchAsset] ${e.toString()}");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-03-16 17:19:31 +02:00
|
|
|
|
|
|
|
Future<List<CuratedLocation>?> getCuratedLocation() async {
|
|
|
|
try {
|
|
|
|
var res = await _networkService.getRequest(url: "asset/allLocation");
|
|
|
|
|
|
|
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
List<CuratedLocation> result =
|
|
|
|
List.from(decodedData.map((a) => CuratedLocation.fromMap(a)));
|
2022-03-16 17:19:31 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [getCuratedLocation] ${e.toString()}");
|
|
|
|
throw Error();
|
|
|
|
}
|
|
|
|
}
|
2022-03-27 21:58:54 +02:00
|
|
|
|
|
|
|
Future<List<CuratedObject>?> getCuratedObjects() async {
|
|
|
|
try {
|
|
|
|
var res = await _networkService.getRequest(url: "asset/allObjects");
|
|
|
|
|
|
|
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
List<CuratedObject> result =
|
|
|
|
List.from(decodedData.map((a) => CuratedObject.fromMap(a)));
|
2022-03-27 21:58:54 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("[ERROR] [CuratedObject] ${e.toString()}");
|
|
|
|
throw Error();
|
|
|
|
}
|
|
|
|
}
|
2022-02-27 20:43:29 +02:00
|
|
|
}
|