import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart'; import 'package:immich_mobile/shared/models/immich_asset.model.dart'; import 'package:immich_mobile/shared/services/network.service.dart'; class AssetService { final NetworkService _networkService = NetworkService(); Future getAllAsset() async { var res = await _networkService.getRequest(url: "asset/all"); try { Map decodedData = jsonDecode(res.toString()); GetAllAssetResponse result = GetAllAssetResponse.fromMap(decodedData); return result; } catch (e) { debugPrint("Error getAllAsset ${e.toString()}"); } return null; } Future getOlderAsset(String? nextPageKey) async { try { var res = await _networkService.getRequest( url: "asset/all?nextPageKey=$nextPageKey", ); Map decodedData = jsonDecode(res.toString()); GetAllAssetResponse result = GetAllAssetResponse.fromMap(decodedData); if (result.count != 0) { return result; } } catch (e) { debugPrint("Error getAllAsset ${e.toString()}"); } return null; } Future> getNewAsset(String latestDate) async { try { var res = await _networkService.getRequest( url: "asset/new?latestDate=$latestDate", ); List decodedData = jsonDecode(res.toString()); List result = List.from(decodedData.map((a) => ImmichAsset.fromMap(a))); if (result.isNotEmpty) { return result; } return []; } catch (e) { debugPrint("Error getAllAsset ${e.toString()}"); return []; } } }