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