From f4797683e8ca9676f4a37381b3746589bcb7b8d0 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sat, 9 Feb 2019 18:55:51 -0500 Subject: [PATCH] Created category model, closes #76 --- app/api/categories.py | 7 ++++--- client/src/models/categories.js | 16 ++++++++++++++++ client/src/views/Categories.vue | 29 +++++++++++++++++------------ client/src/views/Dataset.vue | 8 +++++--- 4 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 client/src/models/categories.js diff --git a/app/api/categories.py b/app/api/categories.py index 07b0dd05..8e556d8c 100644 --- a/app/api/categories.py +++ b/app/api/categories.py @@ -1,5 +1,6 @@ from flask_restplus import Namespace, Resource, reqparse from flask_login import login_required, current_user +from mongoengine.errors import NotUniqueError from ..util.pagination_util import Pagination from ..util import query_util @@ -37,7 +38,7 @@ def post(self): supercategory = args.get('supercategory') metadata = args.get('metadata', {}) color = args.get('color') - + try: category = CategoryModel( name=name, @@ -46,8 +47,8 @@ def post(self): metadata=metadata ) category.save() - except (ValueError, TypeError) as e: - return {'message': str(e)}, 400 + except NotUniqueError as e: + return {'message': 'Category already exists. Check the undo tab to fully delete the category.'}, 400 return query_util.fix_ids(category) diff --git a/client/src/models/categories.js b/client/src/models/categories.js new file mode 100644 index 00000000..9d8568b9 --- /dev/null +++ b/client/src/models/categories.js @@ -0,0 +1,16 @@ +import axios from "axios"; + +const baseURL = "/api/category/"; + +export default { + allData(params) { + return axios.get(baseURL + "data", { + params: { + ...params + } + }); + }, + create(create) { + return axios.post(baseURL, { ...create }); + } +}; diff --git a/client/src/views/Categories.vue b/client/src/views/Categories.vue index be617d6e..b7e5d6c8 100755 --- a/client/src/views/Categories.vue +++ b/client/src/views/Categories.vue @@ -146,7 +146,9 @@