X-Git-Url: https://hackdaworld.org/gitweb/?p=outofuni%2Ftavern2.git;a=blobdiff_plain;f=lib%2Fproduct_category_service.dart;fp=lib%2Fproduct_category_service.dart;h=f246a71183bb69148c668305e146d9b89c94cc8a;hp=c62e7ef0e18e2475141e5afbcf54c8a4d867c475;hb=b2028ca4879e48884436ee0c2aee7fae6ddaeb5a;hpb=3307c69f4b16867ba7522626b6b0acf2d6d9a478 diff --git a/lib/product_category_service.dart b/lib/product_category_service.dart index c62e7ef..f246a71 100644 --- a/lib/product_category_service.dart +++ b/lib/product_category_service.dart @@ -11,9 +11,7 @@ class ProductCategoryService { static const _server='http://10.8.0.1:5984'; static const _db='tavern'; static const _viewname='_design/product_categories/_view/byname'; - static const _viewid='_design/product_categories/_view/byid'; static const _getnameurl=_server+'/'+_db+'/'+_viewname; - static const _getidurl=_server+'/'+_db+'/'+_viewid; static const _posturl=_server+'/'+_db; final BrowserClient _http; @@ -28,7 +26,6 @@ class ProductCategoryService { prodcats.add(new ProductCategory( item['id'], item['value']['name'], - item['value']['id'], item['value']['type'])); } return prodcats; @@ -38,14 +35,13 @@ class ProductCategoryService { } } - Future createProdCategory(String name,String id) async { + Future createProdCategory(String name) async { try { await _http.post( _posturl, headers: {'Content-Type': 'application/json'}, body: JSON.encode({ 'name': name, - 'id': id, 'type': 'product_category' }) ); @@ -58,14 +54,13 @@ class ProductCategoryService { Future getById(String id) async { try { ProductCategory prodcat; - String url=_getidurl+'?key="'+id+'"'; + String url=_server+'/'+_db+'/'+id; final response = await _http.get(url); var item=JSON.decode(response.body); prodcat = new ProductCategory( - item['rows'][0]['value']['_id'], - item['rows'][0]['value']['name'], - item['rows'][0]['value']['id'], - item['rows'][0]['value']['type'] + item['_id'], + item['name'], + item['type'] ); return prodcat; } @@ -74,31 +69,26 @@ class ProductCategoryService { } } - Future updateProdCategory(String oldid,String name, - String id) async { + Future updateProdCategory(String id,String name) async { try { - String url=_getidurl+'?key="'+oldid+'"'; + String url=_server+'/'+_db+'/'+id; final response = await _http.get(url); - print('Debug UPDATE GET URL: '+url); - print('Debug UPDATE GET response: '+response.body); var resbody=JSON.decode(response.body); - resbody['rows'][0]['value']['name']=name; - resbody['rows'][0]['value']['id']=id; - final response_put = await _http.put( - _posturl+'/'+resbody['rows'][0]['id'], + resbody['name']=name; + await _http.put( + _posturl+'/'+id, headers: {'Content-Type': 'application/json'}, - body: JSON.encode(resbody['rows'][0]['value']) + body: JSON.encode(resbody) ); - print('Debug UPDATE PUT response: '+response_put.body); } catch(e) { throw _handleError(e); } } - Future deleteProdCategory(String doc_id) async { + Future deleteProdCategory(String id) async { try { - var url=_server+'/'+_db+'/'+doc_id; + var url=_server+'/'+_db+'/'+id; var response = await _http.get(url); var reso=JSON.decode(response.body); url=_server+'/'+_db+'/_purge/';