aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/controllers/category.py6
-rw-r--r--pyaggr3g470r/models/category.py8
-rw-r--r--pyaggr3g470r/views/api/category.py31
3 files changed, 45 insertions, 0 deletions
diff --git a/pyaggr3g470r/controllers/category.py b/pyaggr3g470r/controllers/category.py
new file mode 100644
index 00000000..b6fc591c
--- /dev/null
+++ b/pyaggr3g470r/controllers/category.py
@@ -0,0 +1,6 @@
+from .abstract import AbstractController
+from pyaggr3g470r.models import Category
+
+
+class CategoryController(AbstractController):
+ _db_cls = Category
diff --git a/pyaggr3g470r/models/category.py b/pyaggr3g470r/models/category.py
new file mode 100644
index 00000000..513227a5
--- /dev/null
+++ b/pyaggr3g470r/models/category.py
@@ -0,0 +1,8 @@
+from bootstrap import db
+
+
+class Category(db.Model):
+ id = db.Column(db.Integer(), primary_key=True)
+ name = db.Column(db.String())
+
+ user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
diff --git a/pyaggr3g470r/views/api/category.py b/pyaggr3g470r/views/api/category.py
new file mode 100644
index 00000000..31f46751
--- /dev/null
+++ b/pyaggr3g470r/views/api/category.py
@@ -0,0 +1,31 @@
+from flask import g
+
+from pyaggr3g470r.controllers.category import CategoryController
+from pyaggr3g470r.views.api.common import (PyAggResourceNew,
+ PyAggResourceExisting,
+ PyAggResourceMulti)
+
+
+CAT_ATTRS = {'name': {'type': str},
+ 'user_id': {'type': int}}
+
+
+class CategoryNewAPI(PyAggResourceNew):
+ controller_cls = CategoryController
+ attrs = CAT_ATTRS
+
+
+class CategoryAPI(PyAggResourceExisting):
+ controller_cls = CategoryController
+ attrs = CAT_ATTRS
+
+
+class CategoriesAPI(PyAggResourceMulti):
+ controller_cls = CategoryController
+ attrs = CAT_ATTRS
+
+
+g.api.add_resource(CategoryNewAPI, '/category', endpoint='category_new.json')
+g.api.add_resource(CategoryAPI, '/category/<int:obj_id>',
+ endpoint='category.json')
+g.api.add_resource(CategoriesAPI, '/categories', endpoint='categories.json')
bgstack15