nc-photos/app/lib/entity/favorite/data_source.dart

36 lines
1.1 KiB
Dart
Raw Normal View History

2022-01-25 11:08:13 +01:00
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/entity_converter.dart';
2022-01-25 11:08:13 +01:00
import 'package:nc_photos/entity/favorite.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/np_api_util.dart';
import 'package:np_api/np_api.dart' as api;
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2022-01-25 11:08:13 +01:00
2022-12-16 16:01:04 +01:00
part 'data_source.g.dart';
@npLog
2022-01-25 11:08:13 +01:00
class FavoriteRemoteDataSource implements FavoriteDataSource {
const FavoriteRemoteDataSource();
@override
list(Account account, File dir) async {
_log.info("[list] ${dir.path}");
final response = await ApiUtil.fromAccount(account).files().report(
2022-01-25 11:08:13 +01:00
path: dir.path,
favorite: true,
);
if (!response.isGood) {
_log.severe("[list] Failed requesting server: $response");
throw ApiException(
response: response,
message: "Server responed with an error: HTTP ${response.statusCode}",
);
2022-01-25 11:08:13 +01:00
}
final apiFavorites = await api.FavoriteParser().parse(response.body);
return apiFavorites.map(ApiFavoriteConverter.fromApi).toList();
2022-01-25 11:08:13 +01:00
}
}