forked from eatvio/eatvio_app
144 lines
3.7 KiB
Dart
144 lines
3.7 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:eatvio_app/features/blog_post_create/repositories/blog_post_repository.dart';
|
|
import 'package:eatvio_app/features/blog_post_create/services/blog_post_service.dart';
|
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
|
|
|
class FixtureBlogPostRepository extends BlogPostRepository {
|
|
FixtureBlogPostRepository() : super(blogPostService: _NoopBlogPostService());
|
|
|
|
final List<BlogPostCreatePayload> createPayloads = <BlogPostCreatePayload>[];
|
|
final List<BlogPostUpdatePayload> updatePayloads = <BlogPostUpdatePayload>[];
|
|
final List<int> deleteCalls = <int>[];
|
|
|
|
Duration createDelay = Duration.zero;
|
|
Duration updateDelay = Duration.zero;
|
|
Duration deleteDelay = Duration.zero;
|
|
|
|
Object? createError;
|
|
Object? updateError;
|
|
Object? deleteError;
|
|
|
|
@override
|
|
Future<void> createBlogPost(String? title, String? videoUrl, String? description, XFile? image) async {
|
|
createPayloads.add(
|
|
BlogPostCreatePayload(
|
|
title: title,
|
|
description: description,
|
|
videoUrl: videoUrl,
|
|
imageName: image?.name,
|
|
),
|
|
);
|
|
if (createDelay > Duration.zero) {
|
|
await Future.delayed(createDelay);
|
|
}
|
|
if (createError != null) {
|
|
throw createError!;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> updateBlogPost(int id, String? title, String? videoUrl, String? description, XFile? image, String? oldImageUrl) async {
|
|
updatePayloads.add(
|
|
BlogPostUpdatePayload(
|
|
id: id,
|
|
title: title,
|
|
description: description,
|
|
videoUrl: videoUrl,
|
|
imageName: image?.name,
|
|
oldImageUrl: oldImageUrl,
|
|
),
|
|
);
|
|
if (updateDelay > Duration.zero) {
|
|
await Future.delayed(updateDelay);
|
|
}
|
|
if (updateError != null) {
|
|
throw updateError!;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteBlogPost(int id) async {
|
|
deleteCalls.add(id);
|
|
if (deleteDelay > Duration.zero) {
|
|
await Future.delayed(deleteDelay);
|
|
}
|
|
if (deleteError != null) {
|
|
throw deleteError!;
|
|
}
|
|
}
|
|
}
|
|
|
|
class BlogPostCreatePayload {
|
|
BlogPostCreatePayload({
|
|
required this.title,
|
|
required this.description,
|
|
required this.videoUrl,
|
|
required this.imageName,
|
|
});
|
|
|
|
final String? title;
|
|
final String? description;
|
|
final String? videoUrl;
|
|
final String? imageName;
|
|
|
|
Map<String, dynamic> toJson() => <String, dynamic>{
|
|
'title': title,
|
|
'description_md': description,
|
|
'video_url': videoUrl,
|
|
'image_name': imageName,
|
|
};
|
|
}
|
|
|
|
class BlogPostUpdatePayload {
|
|
BlogPostUpdatePayload({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.videoUrl,
|
|
required this.imageName,
|
|
required this.oldImageUrl,
|
|
});
|
|
|
|
final int id;
|
|
final String? title;
|
|
final String? description;
|
|
final String? videoUrl;
|
|
final String? imageName;
|
|
final String? oldImageUrl;
|
|
|
|
Map<String, dynamic> toJson() => <String, dynamic>{
|
|
'id': id,
|
|
'title': title,
|
|
'description_md': description,
|
|
'video_url': videoUrl,
|
|
'image_name': imageName,
|
|
'old_image_url': oldImageUrl,
|
|
};
|
|
}
|
|
|
|
class _NoopBlogPostService implements BlogPostService {
|
|
@override
|
|
Future<void> createBlogPost({required FormData formData}) {
|
|
throw UnimplementedError('Fixture overrides repository methods directly.');
|
|
}
|
|
|
|
@override
|
|
Future<void> deleteBlogPost({required int id}) {
|
|
throw UnimplementedError('Fixture overrides repository methods directly.');
|
|
}
|
|
|
|
@override
|
|
Future<void> updateBlogPost({required int id, required FormData formData}) {
|
|
throw UnimplementedError('Fixture overrides repository methods directly.');
|
|
}
|
|
}
|
|
|
|
class FeedReloadProbe {
|
|
int loadRequests = 0;
|
|
|
|
Future<void> loadFeedBlogPostList() async {
|
|
loadRequests += 1;
|
|
}
|
|
}
|
|
|