ICRUD<T, P> class abstract

Interface to implement to query a rest API or database for Create, Read, Update, and Delete of Items-Item.

The first generic type is the item type.

the second generic type is for the query parameter type

class MyItemsRepository implements ICRUD<Item, Param> {
  @override
  ICRUD<void> init()async{
    //initialize any plugging here
  }

  @override
  Future<List<Item>> read(Param? param) async {
    final items = await http.get('uri/${param.user.id}');
    //After parsing
    return items;

    //OR
    // if(param.queryType=='GetCompletedItems'){
    //    final items = await http.get('uri/${param.user.id}/completed');
    //    return items;
    // }else if(param.queryType == 'GetActiveItems'){
    //   final items = await http.get('uri/${param.user.id}/active');
    //    return items;
    // }
  }
  @override
  Future<Item> create(Item item, Param? param) async {
    final result = await http.post('uri/${param.user.id}/items');
    return item.copyWith(id: result['id']);
  }

  @override
  Future<dynamic> update(List<Item> items, Param? param) async {
    //Update items
    return numberOfUpdatedRows;
  }
  @override
  Future<dynamic> delete(List<Item> items, Param? param) async {
    //Delete items
  }

  @override
  void dispose() {
    //Cleaning resources
  }

// You can add here custom methods to perform other requests to the backend

}

Constructors

ICRUD()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

create(T item, P? param) Future<T>
Create an Item
delete(List<T> items, P? param) Future
Delete a list of items
dispose() → void
It is called when the injected model is disposed
init() Future<void>
Initialize any plugging and return the initialized instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(P? param) Future<List<T>>
Read from rest API or a database and get a list of items
toString() String
A string representation of this object.
inherited
update(List<T> items, P? param) Future
Update a list of items

Operators

operator ==(Object other) bool
The equality operator.
inherited