cleaups and content page refresh (in progress)
[outofuni/tavern2.git] / lib / product_category_service.dart
index c62e7ef..f246a71 100644 (file)
@@ -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<Null> createProdCategory(String name,String id) async {
+       Future<Null> 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<ProductCategory> 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<Null> updateProdCategory(String oldid,String name,
-                                       String id) async {
+       Future<Null> 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<Null> deleteProdCategory(String doc_id) async {
+       Future<Null> 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/';