2022-07-13 12:23:48 +00:00
|
|
|
import 'dart:async';
|
2022-02-03 16:06:44 +00:00
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-06-25 18:46:51 +00:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-08-03 05:04:34 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
2022-07-13 12:23:48 +00:00
|
|
|
import 'package:immich_mobile/shared/services/api.service.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
final assetServiceProvider = Provider(
|
|
|
|
(ref) => AssetService(
|
|
|
|
ref.watch(apiServiceProvider),
|
|
|
|
),
|
|
|
|
);
|
2022-06-25 18:46:51 +00:00
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
class AssetService {
|
2022-07-13 12:23:48 +00:00
|
|
|
final ApiService _apiService;
|
2022-02-03 16:06:44 +00:00
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
AssetService(this._apiService);
|
2022-02-07 02:31:32 +00:00
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
Future<List<AssetResponseDto>?> getAllAsset() async {
|
2022-02-07 02:31:32 +00:00
|
|
|
try {
|
2022-07-13 12:23:48 +00:00
|
|
|
return await _apiService.assetApi.getAllAssets();
|
2022-02-07 02:31:32 +00:00
|
|
|
} catch (e) {
|
2022-07-13 12:23:48 +00:00
|
|
|
debugPrint("Error [getAllAsset] ${e.toString()}");
|
|
|
|
return null;
|
2022-02-07 02:31:32 +00:00
|
|
|
}
|
2022-02-03 16:06:44 +00:00
|
|
|
}
|
2022-02-11 02:40:11 +00:00
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
Future<AssetResponseDto?> getAssetById(String assetId) async {
|
2022-02-11 02:40:11 +00:00
|
|
|
try {
|
2022-07-13 12:23:48 +00:00
|
|
|
return await _apiService.assetApi.getAssetById(assetId);
|
2022-02-13 21:10:42 +00:00
|
|
|
} catch (e) {
|
2022-07-13 12:23:48 +00:00
|
|
|
debugPrint("Error [getAssetById] ${e.toString()}");
|
2022-02-13 21:10:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
Future<List<DeleteAssetResponseDto>?> deleteAssets(
|
|
|
|
Set<AssetResponseDto> deleteAssets,
|
|
|
|
) async {
|
2022-02-13 21:10:42 +00:00
|
|
|
try {
|
2022-07-13 12:23:48 +00:00
|
|
|
List<String> payload = [];
|
2022-02-13 21:10:42 +00:00
|
|
|
|
|
|
|
for (var asset in deleteAssets) {
|
|
|
|
payload.add(asset.id);
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
return await _apiService.assetApi
|
|
|
|
.deleteAsset(DeleteAssetDto(ids: payload));
|
2022-02-11 02:40:11 +00:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Error getAllAsset ${e.toString()}");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 16:06:44 +00:00
|
|
|
}
|