diff options
author | HombreLaser <sebastian-440@live.com> | 2024-02-21 12:12:52 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2024-02-21 12:12:52 -0600 |
commit | d5d73505832bb39cf8e7fa5a49ff8e3d56690d71 (patch) | |
tree | fd562db4c6872ffc65b27e4be712c162015d621a /src | |
parent | 11799b5bb5cac1fb53ea676337e679c94d3bc3e8 (diff) |
Add reply form rendering
Diffstat (limited to 'src')
-rw-r--r-- | src/controllers/replies_controller.py | 12 | ||||
-rw-r--r-- | src/queries/comments_query.py | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/controllers/replies_controller.py b/src/controllers/replies_controller.py index 7972a27..bd47a44 100644 --- a/src/controllers/replies_controller.py +++ b/src/controllers/replies_controller.py @@ -1,19 +1,23 @@ from flask import Blueprint, request, abort, render_template from src.services import CreateReplyService +from src.queries import CommentsQuery +from src.database.models import Comment +from src.database import db replies_blueprint = Blueprint('replies_controller', '__replies_controller__') +comments_query = CommentsQuery() @replies_blueprint.get('/api/comments/<int:comment_id>/replies') def index(comment_id): - pass + return render_template('replies/index.jinja', page=comments_query.replies_of(comment_id)) -@replies_blueprint.get('/api/replies/<int:comment_id>/new') -def new(comment_id): - return render_template('replies/form.jinja', comment_id=comment_id) +@replies_blueprint.get('/api/replies/new') +def new(): + return render_template('replies/form.jinja') @replies_blueprint.post('/api/comments/<int:comment_id>/replies') diff --git a/src/queries/comments_query.py b/src/queries/comments_query.py index dca4694..e343667 100644 --- a/src/queries/comments_query.py +++ b/src/queries/comments_query.py @@ -1,5 +1,5 @@ from src.database import db -from src.database.models import Comment +from src.database.models import Comment, Reply from src.queries.base_query import BaseQuery @@ -12,5 +12,10 @@ class CommentsQuery(BaseQuery): def comments_of_post(self, post): return db.paginate( - db.select(Comment).where(Comment.post == post).order_by(Comment.created_at.desc()), + db.select(Comment).where(Comment.post == post).order_by(Comment.created_at.desc()) + ) + + def replies_of(self, comment_id): + return db.paginate( + db.select(Reply).where(Reply.comment_id == comment_id).order_by(Reply.created_at.desc()) ) |