40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import '../../utils/api.dart';
|
|
import '../../utils/constant.dart';
|
|
import '../model/data_output.dart';
|
|
import '../model/property_model.dart';
|
|
|
|
class FavoriteRepository {
|
|
Future<void> addToFavorite(int id, String type) async {
|
|
Map<String, dynamic> parameters = {Api.propertyId: id, Api.type: type};
|
|
|
|
await Api.post(url: Api.addFavourite, parameter: parameters);
|
|
}
|
|
|
|
Future<void> removeFavorite(int id) async {
|
|
Map<String, dynamic> parameters = {
|
|
Api.propertyId: id,
|
|
};
|
|
|
|
await Api.post(url: Api.removeFavorite, parameter: parameters);
|
|
}
|
|
|
|
Future<DataOutput<PropertyModel>> fetchFavorites({required int offset}) async {
|
|
Map<String, dynamic> parameters = {
|
|
Api.offset: offset,
|
|
Api.limit: Constant.loadLimit
|
|
};
|
|
|
|
Map<String, dynamic> response = await Api.get(
|
|
url: Api.getFavoriteProperty,
|
|
queryParameters: parameters,
|
|
);
|
|
|
|
List<PropertyModel> modelList = (response['data'] as List)
|
|
.map((e) => PropertyModel.fromMap(e))
|
|
.toList();
|
|
|
|
return DataOutput<PropertyModel>(
|
|
total: response['total'] ?? 0, modelList: modelList);
|
|
}
|
|
}
|