diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index ca9c6bb9..a15f6a6f 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -7,10 +7,10 @@ import 'package:http/http.dart' as http; /** - * The InvenTreeObject class provides a base-level object + * The InvenTreeModel class provides a base-level object * for interacting with InvenTree data. */ -class InvenTreeObject { +class InvenTreeModel { // Override the endpoint URL for each subclass String URL = ""; @@ -22,12 +22,12 @@ class InvenTreeObject { var api = InvenTreeAPI(); // Default empty object constructor - InvenTreeObject() { + InvenTreeModel() { jsondata.clear(); } - // Construct an InvenTreeObject from a JSON data object - InvenTreeObject.fromJson(Map json) { + // Construct an InvenTreeModel from a JSON data object + InvenTreeModel.fromJson(Map json) { // Store the json object jsondata = json; @@ -44,31 +44,47 @@ class InvenTreeObject { int get parentId => jsondata['parent'] ?? -1; // Create a new object from JSON data (not a constructor!) - InvenTreeObject createFromJson(Map json) { + InvenTreeModel createFromJson(Map json) { - var obj = InvenTreeObject.fromJson(json); + var obj = InvenTreeModel.fromJson(json); return obj; } String get url{ return path.join(URL, pk.toString()); } + /* + // Search this Model type in the database + Future> search(String searchTerm) async { + + String addr = url + "?search=" + search; + + print("Searching endpoint: $url"); + + // TODO - Add "timeout" + // TODO - Add error catching + + var response = + + } + */ + // Return list of objects from the database, with optional filters - Future> list({Map filters}) async { + Future> list({Map filters}) async { if (filters == null) { filters = {}; } - print("Listing endpoint: " + URL); + print("Listing endpoint: $URL"); // TODO - Add "timeout" // TODO - Add error catching var response = await InvenTreeAPI().get(URL, params:filters); - // A list of "InvenTreeObject" items - List results = new List(); + // A list of "InvenTreeModel" items + List results = new List(); if (response.statusCode != 200) { print("Error retreiving data"); @@ -84,7 +100,7 @@ class InvenTreeObject { for (var d in data) { // Create a new object (of the current class type - InvenTreeObject obj = createFromJson(d); + InvenTreeModel obj = createFromJson(d); if (obj != null) { results.add(obj); diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 4f51fa41..6597a82d 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -6,7 +6,7 @@ import 'dart:convert'; import 'package:path/path.dart' as path; import 'package:http/http.dart' as http; -class InvenTreePartCategory extends InvenTreeObject { +class InvenTreePartCategory extends InvenTreeModel { @override String URL = "part/category/"; @@ -19,7 +19,7 @@ class InvenTreePartCategory extends InvenTreeObject { } @override - InvenTreeObject createFromJson(Map json) { + InvenTreeModel createFromJson(Map json) { var cat = InvenTreePartCategory.fromJson(json); // TODO ? @@ -29,7 +29,7 @@ class InvenTreePartCategory extends InvenTreeObject { } -class InvenTreePart extends InvenTreeObject { +class InvenTreePart extends InvenTreeModel { @override String URL = "part/"; @@ -45,7 +45,7 @@ class InvenTreePart extends InvenTreeObject { } @override - InvenTreeObject createFromJson(Map json) { + InvenTreeModel createFromJson(Map json) { var part = InvenTreePart.fromJson(json);