API: added method to get all projects for user.
@@ -54,17 +54,43 @@ project_model = api.model('ProjectModel', {
'public': fields.Boolean
})
+@ns.route('')
+class Projects(Resource):
+
+ @auth_required(['user'])
+ def get(self):
+ b = request.get_json()
+ username = b['username']
+
+ user_id = g.db.execute_one("""
+ SELECT id
+ FROM "user"
+ WHERE username = %s
+ """, [username])[0]['id']
+
+ response = g.db.execute_many_dict("""
+ SELECT name, id, type, public
+ FROM project p
+ INNER JOIN collaborators c
+ WHERE c.project_id = p.id
+ AND c.owner = true
+ AND c.user_id = %s
+ """, [user_id])
+
+ return response
+
+
@ns.route('/<project_id>')
class Project(Resource):
@auth_required(['user', 'project'])
@api.marshal_with(project_model)
def get(self, project_id):
- p = g.db.execute_one_dict('''
+ p = g.db.execute_one_dict("""
SELECT name, id, type, public
FROM project
WHERE id = %s
- ''', [project_id])
+ """, [project_id])
return p
@ns.route('/<project_id>/state.svg')
@@ -73,9 +99,9 @@ class State(Resource):
@nocache
def get(self, project_id):
- p = g.db.execute_one_dict('''
+ p = g.db.execute_one_dict("""
SELECT type FROM project WHERE id = %s
- ''', [project_id])
+ """, [project_id])
project_type = p['type']
