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