Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example/test/widget_test.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ class LaravelRestApiActionsBody {

LaravelRestApiActionsBody({required this.fields});

factory LaravelRestApiActionsBody.fromJson(Map<String, dynamic> json) {
return LaravelRestApiActionsBody(
fields:
(json['fields'] as List<dynamic>)
.map((e) => Action.fromJson(e as Map<String, dynamic>))
.toList(),
);
}

Map<String, dynamic> toJson() {
return {'fields': fields.map((action) => action.toJson()).toList()};
}
Expand All @@ -23,10 +14,6 @@ class Action {

Action({required this.name, required this.value});

factory Action.fromJson(Map<String, dynamic> json) {
return Action(name: json['name'] as String, value: json['value'] as String);
}

Map<String, dynamic> toJson() {
return {'name': name, 'value': value};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,6 @@ class LaravelRestApiSearchBody {
this.limit,
});

factory LaravelRestApiSearchBody.fromJson(Map<String, dynamic> json) {
return LaravelRestApiSearchBody(
text: json['text'] != null ? TextSearch.fromJson(json['text']) : null,
scopes:
(json['scopes'] as List<dynamic>?)
?.map((e) => Scope.fromJson(e))
.toList(),
filters:
(json['filters'] as List<dynamic>?)
?.map((e) => Filter.fromJson(e))
.toList(),
sorts:
(json['sorts'] as List<dynamic>?)
?.map((e) => Sort.fromJson(e))
.toList(),
selects:
(json['selects'] as List<dynamic>?)
?.map((e) => Select.fromJson(e))
.toList(),
includes:
(json['includes'] as List<dynamic>?)
?.map((e) => Include.fromJson(e))
.toList(),
aggregates:
(json['aggregates'] as List<dynamic>?)
?.map((e) => Aggregate.fromJson(e))
.toList(),
instructions:
(json['instructions'] as List<dynamic>?)
?.map((e) => Instruction.fromJson(e))
.toList(),
gates:
(json['gates'] as List<dynamic>?)?.map((e) => e as String).toList(),
page: json['page'] as int?,
limit: json['limit'] as int?,
);
}

Map<String, dynamic> toJson() {
return {
if (text != null) 'text': text!.toJson(),
Expand All @@ -88,10 +50,6 @@ class TextSearch {

TextSearch({this.value});

factory TextSearch.fromJson(Map<String, dynamic> json) {
return TextSearch(value: json['value'] as String?);
}

Map<String, dynamic> toJson() {
return {if (value != null) 'value': value};
}
Expand All @@ -103,13 +61,6 @@ class Scope {

Scope({required this.name, this.parameters});

factory Scope.fromJson(Map<String, dynamic> json) {
return Scope(
name: json['name'] as String,
parameters: json['parameters'] as List<dynamic>?,
);
}

Map<String, dynamic> toJson() {
return {'name': name, if (parameters != null) 'parameters': parameters};
}
Expand All @@ -124,19 +75,6 @@ class Filter {

Filter({this.field, this.operator, this.value, this.type, this.nested});

factory Filter.fromJson(Map<String, dynamic> 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<dynamic>?)
?.map((e) => Filter.fromJson(e))
.toList(),
);
}

Map<String, dynamic> toJson() {
return {
if (field != null) 'field': field,
Expand All @@ -154,13 +92,6 @@ class Sort {

Sort({required this.field, required this.direction});

factory Sort.fromJson(Map<String, dynamic> json) {
return Sort(
field: json['field'] as String,
direction: json['direction'] as String,
);
}

Map<String, dynamic> toJson() {
return {'field': field, 'direction': direction};
}
Expand All @@ -171,10 +102,6 @@ class Select {

Select({required this.field});

factory Select.fromJson(Map<String, dynamic> json) {
return Select(field: json['field'] as String);
}

Map<String, dynamic> toJson() {
return {'field': field};
}
Expand All @@ -189,25 +116,6 @@ class Include {

Include({required this.relation, this.includes, this.filters, this.selects, this.limit});

factory Include.fromJson(Map<String, dynamic> json) {
return Include(
relation: json['relation'] as String,
includes:
(json['includes'] as List<dynamic>?)
?.map((e) => Include.fromJson(e))
.toList(),
filters:
(json['filters'] as List<dynamic>?)
?.map((e) => Filter.fromJson(e))
.toList(),
selects:
(json['selects'] as List<dynamic>?)
?.map((e) => Select.fromJson(e))
.toList(),
limit: json['limit'] as int?,
);
}

Map<String, dynamic> toJson() {
return {
'relation': relation,
Expand All @@ -233,18 +141,6 @@ class Aggregate {
this.filters,
});

factory Aggregate.fromJson(Map<String, dynamic> json) {
return Aggregate(
relation: json['relation'] as String,
type: json['type'] as String,
field: json['field'] as String,
filters:
(json['filters'] as List<dynamic>?)
?.map((e) => Filter.fromJson(e))
.toList(),
);
}

Map<String, dynamic> toJson() {
return {
'relation': relation,
Expand All @@ -261,16 +157,6 @@ class Instruction {

Instruction({required this.name, required this.fields});

factory Instruction.fromJson(Map<String, dynamic> json) {
return Instruction(
name: json['name'] as String,
fields:
(json['fields'] as List<dynamic>)
.map((e) => Field.fromJson(e))
.toList(),
);
}

Map<String, dynamic> toJson() {
return {'name': name, 'fields': fields.map((e) => e.toJson()).toList()};
}
Expand All @@ -282,10 +168,6 @@ class Field {

Field({required this.name, required this.value});

factory Field.fromJson(Map<String, dynamic> json) {
return Field(name: json['name'] as String, value: json['value']);
}

Map<String, dynamic> toJson() {
return {'name': name, 'value': value};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ class LaravelRestApiMutateResponse {

LaravelRestApiMutateResponse({required this.created, required this.updated});

factory LaravelRestApiMutateResponse.fromJson(Map<String, dynamic> json) {
return LaravelRestApiMutateResponse(
created: List<dynamic>.from(json['created'] ?? []),
updated: List<dynamic>.from(json['updated'] ?? []),
);
}

Map<String, dynamic> toJson() {
return {'created': created, 'updated': updated};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ class PaginatedResponse<T> {
required this.meta,
});

factory PaginatedResponse.fromJson(Map<String, dynamic> json) {
return PaginatedResponse(
currentPage: json['current_page'],
data:
(json['data'] as List<dynamic>)
.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<String, dynamic> toJson() {
return {
'current_page': currentPage,
Expand All @@ -56,14 +40,6 @@ class UserData {

UserData({required this.id, required this.name, required this.gates});

factory UserData.fromJson(Map<String, dynamic> json) {
return UserData(
id: json['id'],
name: json['name'],
gates: Gates.fromJson(json['gates']),
);
}

Map<String, dynamic> toJson() {
return {'id': id, 'name': name, 'gates': gates.toJson()};
}
Expand All @@ -84,16 +60,6 @@ class Gates {
required this.authorizedToForceDelete,
});

factory Gates.fromJson(Map<String, dynamic> 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<String, dynamic> toJson() {
return {
'authorized_to_view': authorizedToView,
Expand All @@ -110,10 +76,6 @@ class MetaData {

MetaData({required this.gates});

factory MetaData.fromJson(Map<String, dynamic> json) {
return MetaData(gates: MetaGates.fromJson(json['gates']));
}

Map<String, dynamic> toJson() {
return {'gates': gates.toJson()};
}
Expand All @@ -124,10 +86,6 @@ class MetaGates {

MetaGates({required this.authorizedToCreate});

factory MetaGates.fromJson(Map<String, dynamic> json) {
return MetaGates(authorizedToCreate: json['authorized_to_create']);
}

Map<String, dynamic> toJson() {
return {'authorized_to_create': authorizedToCreate};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
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<String, dynamic> json);

Future<RestApiResponse<int>> actions({
required LaravelRestApiActionsBody data,
Map<String, String>? headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
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<String, dynamic> json);

Future<RestApiResponse<LaravelRestApiMutateResponse>> mutate({
required LaravelRestApiMutateBody body,
Map<String, String>? headers,
Expand Down
6 changes: 1 addition & 5 deletions test/actions_factory_mock_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemModel> {
class ItemRepository with ActionsFactory {
MockDio mockDio;
ItemRepository(this.mockDio);

Expand All @@ -18,9 +17,6 @@ class ItemRepository with ActionsFactory<ItemModel> {

@override
RestApiClient get httpClient => MockApiHttpClient(dio: mockDio);

@override
ItemModel fromJson(Map<String, dynamic> item) => ItemModel.fromJson(item);
}

void main() {
Expand Down
5 changes: 1 addition & 4 deletions test/mutate_factory_mock_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemModel> {
class ItemRepository with MutateFactory {
MockDio mockDio;
ItemRepository(this.mockDio);

Expand All @@ -18,9 +18,6 @@ class ItemRepository with MutateFactory<ItemModel> {

@override
RestApiClient get httpClient => MockApiHttpClient(dio: mockDio);

@override
ItemModel fromJson(Map<String, dynamic> item) => ItemModel.fromJson(item);
}

void main() {
Expand Down