from flask import Blueprint, jsonify from flask.views import MethodView class TaskApiBlueprint(Blueprint): """ Blueprint for the tasks REST API. """ def __init__(self): super().__init__('rest_api_tasks', __name__, url_prefix='/tasks') self.add_url_rule( '/', view_func=TaskCollectionView.as_view(TaskCollectionView.__name__), methods=['GET', 'POST'], ) self.add_url_rule( '/', view_func=TaskItemView.as_view(TaskItemView.__name__), methods=['GET', 'PATCH', 'DELETE'], ) class TaskCollectionView(MethodView): """ View class for `/tasks` endpoint. """ def get(self): """ Get list of all tasks. """ # TODO: Get actual data return jsonify({ 'count': 1, 'items': [ { 'id': 1, 'title': 'Do stuff', 'description': '', 'status': 'open', }, ], }), 200 def post(self): """ Create a new task. """ # TODO: Implement raise NotImplementedError class TaskItemView(MethodView): """ View class for `/tasks/` endpoint. """ def get(self, task_id: int): """ Get a single task by ID. """ # TODO: Get actual data return jsonify({ 'id': task_id, 'title': 'Do stuff', 'description': '', 'status': 'open', }), 200 def patch(self, task_id: int): """ Update a single task by ID. """ # TODO: Implement raise NotImplementedError def delete(self, task_id: int): """ Delete a single task by ID. """ # TODO: Implement raise NotImplementedError