forked from eatvio/eatvio_app
fixed likes and favourite sync and adeded filter leayoutfor diets
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/data/diet/models/diet_likes_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
@@ -9,17 +10,17 @@ abstract class DietService {
|
||||
factory DietService(Dio dio, {String baseUrl}) = _DietService;
|
||||
|
||||
@POST('/api/diets/{id}/like')
|
||||
Future<void> likeDiet({
|
||||
Future<DietLikesModel> likeDiet({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
@POST('/api/diets/{id}/add_to_favorite')
|
||||
Future<void> addToFavorite({
|
||||
Future<Diet> addToFavorite({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
@POST('/api/diets/{id}/remove_from_favorite')
|
||||
Future<void> removeFromFavorite({
|
||||
Future<Diet> removeFromFavorite({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ class _DietService implements DietService {
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<void> likeDiet({required int id}) async {
|
||||
Future<DietLikesModel> likeDiet({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
final _options = _setStreamType<DietLikesModel>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
@@ -43,16 +43,24 @@ class _DietService implements DietService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late DietLikesModel _value;
|
||||
try {
|
||||
_value = DietLikesModel.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addToFavorite({required int id}) async {
|
||||
Future<Diet> addToFavorite({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
final _options = _setStreamType<Diet>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
@@ -68,16 +76,24 @@ class _DietService implements DietService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late Diet _value;
|
||||
try {
|
||||
_value = Diet.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeFromFavorite({required int id}) async {
|
||||
Future<Diet> removeFromFavorite({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
final _options = _setStreamType<Diet>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
@@ -93,7 +109,15 @@ class _DietService implements DietService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late Diet _value;
|
||||
try {
|
||||
_value = Diet.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user