Skip to content

Commit 306c54e

Browse files
committed
Add Project crud using flask-restplus
1 parent a075598 commit 306c54e

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

requirements/prod.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Flask
2-
flask-restplus
3-
flake8
1+
Flask==1.1.1
2+
flask-restplus==0.13.0
3+
flake8==3.7.9
4+
Werkzeug==0.16.1

time_tracker_api/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from flask import Flask
2+
from flask_restplus import Api
23

34

45
def create_app():
5-
app = Flask(__name__)
6-
return app
6+
flask_app = Flask(__name__)
7+
app = Api(app=flask_app)
8+
9+
from time_tracker_api.projects.projects_endpoints import ns as projects_ns
10+
app.add_namespace(projects_ns)
11+
12+
return flask_app
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from flask_restplus import Namespace
2+
from flask_restplus import Resource
3+
4+
ns = Namespace('projects', description='Api for resource `Projects`')
5+
6+
7+
@ns.route('/')
8+
class Projects(Resource):
9+
@ns.doc('list_projects')
10+
def get(self):
11+
"""List all projects"""
12+
print("List all projects")
13+
return {}, 200
14+
15+
@ns.doc('create_project')
16+
def post(self):
17+
"""Create a project"""
18+
print("List all projects")
19+
return {}, 201
20+
21+
22+
@ns.route('/<string:uid>')
23+
@ns.response(404, 'Project not found')
24+
@ns.param('uid', 'The project identifier')
25+
class Project(Resource):
26+
@ns.doc('get_project')
27+
def get(self, uid):
28+
"""Retrieve a project"""
29+
print("Retrieve Project")
30+
return {}
31+
32+
@ns.doc('delete_project')
33+
@ns.response(204, 'Project deleted')
34+
def delete(self, uid):
35+
"""Deletes a project"""
36+
print("Delete Project")
37+
return None, 204
38+
39+
@ns.doc('put_project')
40+
def put(self, uid):
41+
"""Create or replace a project"""
42+
print("Create or Replace Project")
43+
return {}
44+
45+
@ns.doc('update_project_status')
46+
@ns.param('uid', 'The project identifier')
47+
@ns.response(204, 'State of the project successfully updated')
48+
def post(self, uid):
49+
"""Updates a project using form data"""
50+
print("Update Project using form data")
51+
return {}

time_tracker_api/projects/views.py

Whitespace-only changes.

0 commit comments

Comments
 (0)