diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 12:24:49 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 12:24:49 +0200 |
commit | e6afc92bad152f44e3ea352d6fcddb1c386677f6 (patch) | |
tree | 706f07c7d8fc418bcf2cd34e4908b2be16eef579 /pyaggr3g470r/rest.py | |
parent | Updated README and fixed a problem when parsing the publication date of the a... (diff) | |
download | newspipe-e6afc92bad152f44e3ea352d6fcddb1c386677f6.tar.gz newspipe-e6afc92bad152f44e3ea352d6fcddb1c386677f6.tar.bz2 newspipe-e6afc92bad152f44e3ea352d6fcddb1c386677f6.zip |
DELETE method for the REST service has been implemented.
Diffstat (limited to 'pyaggr3g470r/rest.py')
-rw-r--r-- | pyaggr3g470r/rest.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/pyaggr3g470r/rest.py b/pyaggr3g470r/rest.py index 58500f1e..10116f8e 100644 --- a/pyaggr3g470r/rest.py +++ b/pyaggr3g470r/rest.py @@ -149,14 +149,6 @@ class ArticleListAPI(Resource): response.status_code = 501 return response - def delete(self): - """ - DELETE method - no sense here. - """ - response = jsonify({'code': 501, 'message': 'DELETE method not implemented for Article objects.'}) - response.status_code = 501 - return response - class ArticleAPI(Resource): """ Defines a RESTful API for Article elements. @@ -204,11 +196,17 @@ class ArticleAPI(Resource): def delete(self, id): """ - DELETE method - no sense here. + Delete an article. """ - response = jsonify({'code': 501, 'message': 'DELETE method not implemented for Article objects.'}) - response.status_code = 501 - return response + article = Article.query.filter(Article.id == id).first() + if article is not None and article.source.subscriber.id == g.user.id: + db.session.delete(article) + db.session.commit() + return {"message":"ok"} + else: + response = jsonify({'code': 404, 'message': 'Article not found'}) + response.status_code = 404 + return response api.add_resource(ArticleListAPI, '/api/v1.0/articles', endpoint = 'articles.json') api.add_resource(ArticleAPI, '/api/v1.0/articles/<int:id>', endpoint = 'article.json') |