-
Notifications
You must be signed in to change notification settings - Fork 4
Reply/feature #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import logging | ||
| from datetime import datetime | ||
|
|
||
| from flask import Blueprint | ||
| from flask_jwt_extended import get_jwt_identity, jwt_required | ||
| from flask_restful import (Api, Resource, abort, fields, inputs, marshal_with, reqparse) | ||
| from sqlalchemy import or_ | ||
| from typing import Optional | ||
| from src.new_backend.models import Collection, Comment, Paper, Reply, db, User | ||
| from .user_utils import get_user | ||
|
|
||
| app = Blueprint('replies', __name__) | ||
| api = Api(app) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| replies_fields = { | ||
| 'id': fields.String, | ||
| 'user': fields.String(attribute='user.username'), | ||
| 'text': fields.String, | ||
| 'createdAt': fields.DateTime(dt_format='rfc822', attribute='creation_date'), | ||
| } | ||
|
|
||
| EMPTY_FIELD_MSG = 'This field cannot be blank' | ||
|
|
||
| class ReplyResource(Resource): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be confusing to have 2
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll also ensure that we won't have two copies of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. I would suggest the owner of the code to clean and remove unused code because it can be confusing. For example, MongoDB seems to be replaced with PostgreSQL. Also, new_backend, main, app, src in the same project makes it a little bit confusing. I think one common convention is app/main.py.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right (and I apologize about that), the code is still patchy but we're working on fixing that. |
||
| method_decorators = [jwt_required] | ||
|
|
||
| def _get_reply(self, reply_id): | ||
|
|
||
| reply = Reply.query.get_or_404(reply_id) | ||
|
|
||
| user = get_user() | ||
|
|
||
| if reply.user != user: | ||
| abort(403, message='unauthorized to modify the reply') | ||
|
|
||
| return reply | ||
|
|
||
|
|
||
| @marshal_with(replies_fields, envelope='reply') | ||
| def post(self, reply_id): | ||
|
|
||
| reply = self._get_reply(reply_id) | ||
|
|
||
| edit_reply_parser = reqparse.RequestParser() | ||
| edit_reply_parser.add_argument('text', help=EMPTY_FIELD_MSG, type=str, location='json', required=False) | ||
| data = edit_reply_parser.parse_args() | ||
| reply.text = data['text'] | ||
|
|
||
| db.session.commit() | ||
|
|
||
| return reply | ||
|
|
||
|
|
||
| api.add_resource(ReplyResource, "/<reply_id>") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is necessary here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is optional. At least, people will know it is an option they can use and explore. It is a simple podman command to get started. Ideally, you would have a Dockerfile with a docker-compose file in this project. The setup and configuration time would have been saved for anyone who wants to contribute to this project.
For your information, Podman 2.0 was released less than one month ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in regards to Docker :)
#9