Create Article CRUD Routes
bryanwong8 opened this issue · comments
Is your feature request related to a problem? Please describe.
We need to implement CRUD routes for Articles to allow them to be created, updated, deleted, and searched.
Describe the solution you'd like
Routes need to be created:
- CreateArticle -
/api/articles
POST - FetchArticles -
/api/articles
GET - UpdateArticle -
/api/articles/<int:article_id>
PUT - DeleteArticle -
/api/articles/<int:article_id>
DEL - FetchArticle -
/api/articles/<int:article_id>
GET
Routes/functions to implement/change
Should create a ArticleCrud class to implement the CRUD routes with Flask-Restful
example:
class ModelCRUD(Resource):
def get(self):
def post(self):
def put(self):
def delete(self):
Additional context
- CreateArticle: When creating an Article, validate it with the ArticleFormSchema. Create a function called create_article in utils.py in the articles folder. The function should create the Article and return it. In the route call the create_article function, add it to the db session and commit it. If successful, return:
{
"message": "Successfully created Article"
}, 201
- UpdateArticle: Update an Article by first validating the form data with the ArticleFormData schema. Query for the Article by the id given in the route. Create a function called update_article in utils.py in the articles folder it should take in the Article and form data as parameters. The function should update the Article's parameters. If successful, return:
{
"message": "Article successfully updated"
}, 200
- DeleteArticle: Query for the Article by id. Use db.session.delete() to delete the object. If successful, return:
{
"message": "Article successfully deleted"
}, 200
- FecthArticle: Query for the Article by id. Return the serialization with ArticleSchema.
- FetchArticles: Query for a maximum of 15 Articles and serialize and return it with ArticlesSchema