category repo
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../common/api/api_failure.dart';
|
||||
|
||||
part 'category.freezed.dart';
|
||||
|
||||
part 'entities/category_entity.dart';
|
||||
part 'failures/category_failure.dart';
|
||||
part 'repositories/i_category_repository.dart';
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,59 @@
|
||||
part of '../category.dart';
|
||||
|
||||
@freezed
|
||||
class ListCategory with _$ListCategory {
|
||||
const factory ListCategory({
|
||||
required List<Category> categories,
|
||||
required int totalCount,
|
||||
required int page,
|
||||
required int limit,
|
||||
required int totalPages,
|
||||
}) = _ListCategory;
|
||||
|
||||
factory ListCategory.empty() => const ListCategory(
|
||||
categories: [],
|
||||
totalCount: 0,
|
||||
page: 0,
|
||||
limit: 0,
|
||||
totalPages: 0,
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Category with _$Category {
|
||||
const factory Category({
|
||||
required String id,
|
||||
required String organizationId,
|
||||
required String name,
|
||||
required String description,
|
||||
required String businessType,
|
||||
required int order,
|
||||
required Map<String, dynamic> metadata,
|
||||
required String createdAt,
|
||||
required String updatedAt,
|
||||
}) = _Category;
|
||||
|
||||
factory Category.empty() => const Category(
|
||||
id: '',
|
||||
organizationId: '',
|
||||
name: '',
|
||||
description: '',
|
||||
businessType: '',
|
||||
order: 0,
|
||||
metadata: {},
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
);
|
||||
|
||||
factory Category.all() => const Category(
|
||||
id: 'all',
|
||||
organizationId: '',
|
||||
name: 'Semua',
|
||||
businessType: 'restaurant',
|
||||
metadata: {},
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
description: '',
|
||||
order: 1,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
part of '../category.dart';
|
||||
|
||||
@freezed
|
||||
sealed class CategoryFailure with _$CategoryFailure {
|
||||
const factory CategoryFailure.serverError(ApiFailure failure) = _ServerError;
|
||||
const factory CategoryFailure.unexpectedError() = _UnexpectedError;
|
||||
const factory CategoryFailure.empty() = _Empty;
|
||||
const factory CategoryFailure.localStorageError(String erroMessage) =
|
||||
_LocalStorageError;
|
||||
const factory CategoryFailure.dynamicErrorMessage(String erroMessage) =
|
||||
_DynamicErrorMessage;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
part of '../category.dart';
|
||||
|
||||
abstract class ICategoryRepository {
|
||||
Future<Either<CategoryFailure, ListCategory>> getCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
bool forceRemote = false,
|
||||
});
|
||||
|
||||
Future<Either<CategoryFailure, Category>> getCategoryById(String id);
|
||||
|
||||
Future<Either<CategoryFailure, String>> syncAllCategories();
|
||||
|
||||
Future<Either<CategoryFailure, ListCategory>> refreshCategories({
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
});
|
||||
|
||||
Future<bool> hasLocalCategories();
|
||||
|
||||
Future<Either<CategoryFailure, Map<String, dynamic>>> getDatabaseStats();
|
||||
|
||||
void clearCache();
|
||||
}
|
||||
Reference in New Issue
Block a user