diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart deleted file mode 100644 index ab73b3a..0000000 --- a/example/test/widget_test.dart +++ /dev/null @@ -1 +0,0 @@ -void main() {} diff --git a/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_actions_body.dart b/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_actions_body.dart index ad0ab4a..95bee74 100644 --- a/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_actions_body.dart +++ b/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_actions_body.dart @@ -3,15 +3,6 @@ class LaravelRestApiActionsBody { LaravelRestApiActionsBody({required this.fields}); - factory LaravelRestApiActionsBody.fromJson(Map json) { - return LaravelRestApiActionsBody( - fields: - (json['fields'] as List) - .map((e) => Action.fromJson(e as Map)) - .toList(), - ); - } - Map toJson() { return {'fields': fields.map((action) => action.toJson()).toList()}; } @@ -23,10 +14,6 @@ class Action { Action({required this.name, required this.value}); - factory Action.fromJson(Map json) { - return Action(name: json['name'] as String, value: json['value'] as String); - } - Map toJson() { return {'name': name, 'value': value}; } diff --git a/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_search_body.dart b/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_search_body.dart index 5a96bb3..b961365 100644 --- a/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_search_body.dart +++ b/lib/data/core/models/laravel_rest_api/body/laravel_rest_api_search_body.dart @@ -25,44 +25,6 @@ class LaravelRestApiSearchBody { this.limit, }); - factory LaravelRestApiSearchBody.fromJson(Map json) { - return LaravelRestApiSearchBody( - text: json['text'] != null ? TextSearch.fromJson(json['text']) : null, - scopes: - (json['scopes'] as List?) - ?.map((e) => Scope.fromJson(e)) - .toList(), - filters: - (json['filters'] as List?) - ?.map((e) => Filter.fromJson(e)) - .toList(), - sorts: - (json['sorts'] as List?) - ?.map((e) => Sort.fromJson(e)) - .toList(), - selects: - (json['selects'] as List?) - ?.map((e) => Select.fromJson(e)) - .toList(), - includes: - (json['includes'] as List?) - ?.map((e) => Include.fromJson(e)) - .toList(), - aggregates: - (json['aggregates'] as List?) - ?.map((e) => Aggregate.fromJson(e)) - .toList(), - instructions: - (json['instructions'] as List?) - ?.map((e) => Instruction.fromJson(e)) - .toList(), - gates: - (json['gates'] as List?)?.map((e) => e as String).toList(), - page: json['page'] as int?, - limit: json['limit'] as int?, - ); - } - Map toJson() { return { if (text != null) 'text': text!.toJson(), @@ -88,10 +50,6 @@ class TextSearch { TextSearch({this.value}); - factory TextSearch.fromJson(Map json) { - return TextSearch(value: json['value'] as String?); - } - Map toJson() { return {if (value != null) 'value': value}; } @@ -103,13 +61,6 @@ class Scope { Scope({required this.name, this.parameters}); - factory Scope.fromJson(Map json) { - return Scope( - name: json['name'] as String, - parameters: json['parameters'] as List?, - ); - } - Map toJson() { return {'name': name, if (parameters != null) 'parameters': parameters}; } @@ -124,19 +75,6 @@ class Filter { Filter({this.field, this.operator, this.value, this.type, this.nested}); - factory Filter.fromJson(Map json) { - return Filter( - field: json['field'] as String?, - operator: json['operator'] as String?, - value: json['value'], - type: json['type'] as String?, - nested: - (json['nested'] as List?) - ?.map((e) => Filter.fromJson(e)) - .toList(), - ); - } - Map toJson() { return { if (field != null) 'field': field, @@ -154,13 +92,6 @@ class Sort { Sort({required this.field, required this.direction}); - factory Sort.fromJson(Map json) { - return Sort( - field: json['field'] as String, - direction: json['direction'] as String, - ); - } - Map toJson() { return {'field': field, 'direction': direction}; } @@ -171,10 +102,6 @@ class Select { Select({required this.field}); - factory Select.fromJson(Map json) { - return Select(field: json['field'] as String); - } - Map toJson() { return {'field': field}; } @@ -189,25 +116,6 @@ class Include { Include({required this.relation, this.includes, this.filters, this.selects, this.limit}); - factory Include.fromJson(Map json) { - return Include( - relation: json['relation'] as String, - includes: - (json['includes'] as List?) - ?.map((e) => Include.fromJson(e)) - .toList(), - filters: - (json['filters'] as List?) - ?.map((e) => Filter.fromJson(e)) - .toList(), - selects: - (json['selects'] as List?) - ?.map((e) => Select.fromJson(e)) - .toList(), - limit: json['limit'] as int?, - ); - } - Map toJson() { return { 'relation': relation, @@ -233,18 +141,6 @@ class Aggregate { this.filters, }); - factory Aggregate.fromJson(Map json) { - return Aggregate( - relation: json['relation'] as String, - type: json['type'] as String, - field: json['field'] as String, - filters: - (json['filters'] as List?) - ?.map((e) => Filter.fromJson(e)) - .toList(), - ); - } - Map toJson() { return { 'relation': relation, @@ -261,16 +157,6 @@ class Instruction { Instruction({required this.name, required this.fields}); - factory Instruction.fromJson(Map json) { - return Instruction( - name: json['name'] as String, - fields: - (json['fields'] as List) - .map((e) => Field.fromJson(e)) - .toList(), - ); - } - Map toJson() { return {'name': name, 'fields': fields.map((e) => e.toJson()).toList()}; } @@ -282,10 +168,6 @@ class Field { Field({required this.name, required this.value}); - factory Field.fromJson(Map json) { - return Field(name: json['name'] as String, value: json['value']); - } - Map toJson() { return {'name': name, 'value': value}; } diff --git a/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_mutate_reponse.dart b/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_mutate_reponse.dart index d16abef..d5fddbb 100644 --- a/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_mutate_reponse.dart +++ b/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_mutate_reponse.dart @@ -4,13 +4,6 @@ class LaravelRestApiMutateResponse { LaravelRestApiMutateResponse({required this.created, required this.updated}); - factory LaravelRestApiMutateResponse.fromJson(Map json) { - return LaravelRestApiMutateResponse( - created: List.from(json['created'] ?? []), - updated: List.from(json['updated'] ?? []), - ); - } - Map toJson() { return {'created': created, 'updated': updated}; } diff --git a/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_search_response.dart b/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_search_response.dart index 9408dd8..d943af1 100644 --- a/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_search_response.dart +++ b/lib/data/core/models/laravel_rest_api/response/laravel_rest_api_search_response.dart @@ -19,22 +19,6 @@ class PaginatedResponse { required this.meta, }); - factory PaginatedResponse.fromJson(Map json) { - return PaginatedResponse( - currentPage: json['current_page'], - data: - (json['data'] as List) - .map((item) => UserData.fromJson(item)) - .toList(), - from: json['from'], - lastPage: json['last_page'], - perPage: json['per_page'], - to: json['to'], - total: json['total'], - meta: MetaData.fromJson(json['meta']), - ); - } - Map toJson() { return { 'current_page': currentPage, @@ -56,14 +40,6 @@ class UserData { UserData({required this.id, required this.name, required this.gates}); - factory UserData.fromJson(Map json) { - return UserData( - id: json['id'], - name: json['name'], - gates: Gates.fromJson(json['gates']), - ); - } - Map toJson() { return {'id': id, 'name': name, 'gates': gates.toJson()}; } @@ -84,16 +60,6 @@ class Gates { required this.authorizedToForceDelete, }); - factory Gates.fromJson(Map json) { - return Gates( - authorizedToView: json['authorized_to_view'], - authorizedToUpdate: json['authorized_to_update'], - authorizedToDelete: json['authorized_to_delete'], - authorizedToRestore: json['authorized_to_restore'], - authorizedToForceDelete: json['authorized_to_force_delete'], - ); - } - Map toJson() { return { 'authorized_to_view': authorizedToView, @@ -110,10 +76,6 @@ class MetaData { MetaData({required this.gates}); - factory MetaData.fromJson(Map json) { - return MetaData(gates: MetaGates.fromJson(json['gates'])); - } - Map toJson() { return {'gates': gates.toJson()}; } @@ -124,10 +86,6 @@ class MetaGates { MetaGates({required this.authorizedToCreate}); - factory MetaGates.fromJson(Map json) { - return MetaGates(authorizedToCreate: json['authorized_to_create']); - } - Map toJson() { return {'authorized_to_create': authorizedToCreate}; } diff --git a/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_actions_factory.dart b/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_actions_factory.dart index fe52a5a..8a40ae0 100644 --- a/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_actions_factory.dart +++ b/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_actions_factory.dart @@ -3,16 +3,13 @@ import 'package:laravel_rest_api_flutter/data/core/models/laravel_rest_api/body/ import '../../rest_api_repository.dart'; /// A mixin to simplify building search requests for Laravel Rest API. -mixin ActionsFactory { +mixin ActionsFactory { /// The base route for the resource (e.g., '/posts'). String get baseRoute; /// The HTTP client used to send requests. Typically a Dio instance. RestApiClient get httpClient; - /// Converts a JSON response into an instance of type `T`. - T fromJson(Map json); - Future> actions({ required LaravelRestApiActionsBody data, Map? headers, diff --git a/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_mutate_factory.dart b/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_mutate_factory.dart index 3b984bc..9313b66 100644 --- a/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_mutate_factory.dart +++ b/lib/data/core/rest_api_factories/laravel_rest_api/laravel_rest_api_mutate_factory.dart @@ -4,16 +4,13 @@ import 'package:laravel_rest_api_flutter/data/core/models/laravel_rest_api/respo import '../../rest_api_repository.dart'; /// A mixin to simplify building search requests for Laravel Rest API. -mixin MutateFactory { +mixin MutateFactory { /// The base route for the resource (e.g., '/posts'). String get baseRoute; /// The HTTP client used to send requests. Typically a http or Dio instance. RestApiClient get httpClient; - /// Converts a JSON response into an instance of type `T`. - T fromJson(Map json); - Future> mutate({ required LaravelRestApiMutateBody body, Map? headers, diff --git a/test/actions_factory_mock_test.dart b/test/actions_factory_mock_test.dart index 3a299b9..836985f 100644 --- a/test/actions_factory_mock_test.dart +++ b/test/actions_factory_mock_test.dart @@ -5,11 +5,10 @@ import 'package:laravel_rest_api_flutter/data/core/rest_api_factories/laravel_re import 'package:mockito/mockito.dart'; import 'package:dio/dio.dart'; -import 'mock/item_model.dart'; import 'mock/mock_http_client.dart'; import 'mock/mock_http_client.mocks.dart'; -class ItemRepository with ActionsFactory { +class ItemRepository with ActionsFactory { MockDio mockDio; ItemRepository(this.mockDio); @@ -18,9 +17,6 @@ class ItemRepository with ActionsFactory { @override RestApiClient get httpClient => MockApiHttpClient(dio: mockDio); - - @override - ItemModel fromJson(Map item) => ItemModel.fromJson(item); } void main() { diff --git a/test/mutate_factory_mock_test.dart b/test/mutate_factory_mock_test.dart index edb6fa0..0aa8f2d 100644 --- a/test/mutate_factory_mock_test.dart +++ b/test/mutate_factory_mock_test.dart @@ -9,7 +9,7 @@ import 'mock/item_model.dart'; import 'mock/mock_http_client.dart'; import 'mock/mock_http_client.mocks.dart'; -class ItemRepository with MutateFactory { +class ItemRepository with MutateFactory { MockDio mockDio; ItemRepository(this.mockDio); @@ -18,9 +18,6 @@ class ItemRepository with MutateFactory { @override RestApiClient get httpClient => MockApiHttpClient(dio: mockDio); - - @override - ItemModel fromJson(Map item) => ItemModel.fromJson(item); } void main() {