49 lines
1.2 KiB
Dart
49 lines
1.2 KiB
Dart
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'api_response.freezed.dart';
|
|
part 'api_response.g.dart';
|
|
|
|
@Freezed(genericArgumentFactories: true)
|
|
class ApiResponse<T> with _$ApiResponse<T> {
|
|
const factory ApiResponse({
|
|
required bool success,
|
|
required String message,
|
|
T? data,
|
|
Map<String, dynamic>? meta,
|
|
}) = _ApiResponse<T>;
|
|
|
|
factory ApiResponse.fromJson(
|
|
Map<String, dynamic> json,
|
|
T Function(Object?) fromJsonT,
|
|
) =>
|
|
_$ApiResponseFromJson(json, fromJsonT);
|
|
}
|
|
|
|
@Freezed(genericArgumentFactories: true)
|
|
class PaginatedResponse<T> with _$PaginatedResponse<T> {
|
|
const factory PaginatedResponse({
|
|
required List<T> items,
|
|
required int page,
|
|
required int limit,
|
|
required int total,
|
|
required int totalPages,
|
|
}) = _PaginatedResponse<T>;
|
|
|
|
factory PaginatedResponse.fromJson(
|
|
Map<String, dynamic> json,
|
|
T Function(Object?) fromJsonT,
|
|
) =>
|
|
_$PaginatedResponseFromJson(json, fromJsonT);
|
|
}
|
|
|
|
@freezed
|
|
class PaginationParams with _$PaginationParams {
|
|
const factory PaginationParams({
|
|
@Default(1) int page,
|
|
@Default(20) int limit,
|
|
String? search,
|
|
String? sortBy,
|
|
@Default('asc') String sortOrder,
|
|
}) = _PaginationParams;
|
|
}
|