Add API(v2) to get all projects info 35/37735/1
authorchenjiankun <chenjiankun1@huawei.com>
Wed, 19 Jul 2017 07:21:24 +0000 (07:21 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Wed, 19 Jul 2017 07:21:24 +0000 (07:21 +0000)
JIRA: YARDSTICK-732

API: /api/v2/yardstick/projects
METHOD: GET

Change-Id: Ifd67f11f516270d96c0e80b5b8c76a939583d9e5
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/database/v2/handlers.py
api/resources/v2/projects.py

index 095ad72..7aa02a0 100644 (file)
@@ -130,6 +130,9 @@ class V2ContainerHandler(object):
 
 class V2ProjectHandler(object):
 
+    def list_all(self):
+        return V2Project.query.all()
+
     def insert(self, kwargs):
         project = V2Project(**kwargs)
         db_session.add(project)
index e787cc3..1c3c76b 100644 (file)
@@ -5,11 +5,22 @@ from datetime import datetime
 from api import ApiResource
 from api.database.v2.handlers import V2ProjectHandler
 from yardstick.common.utils import result_handler
+from yardstick.common.utils import change_obj_to_dict
 from yardstick.common import constants as consts
 
 
 class V2Projects(ApiResource):
 
+    def get(self):
+        project_handler = V2ProjectHandler()
+        projects = [change_obj_to_dict(p) for p in project_handler.list_all()]
+
+        for p in projects:
+            tasks = p['tasks']
+            p['tasks'] = tasks.split(',') if tasks else []
+
+        return result_handler(consts.API_SUCCESS, {'projects': projects})
+
     def post(self):
         return self._dispatch_post()