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//replies') def index(comment_id): comment = db.get_or_404(Comment, comment_id) return render_template('replies/index.jinja', page=comments_query.replies_of(comment.id), comment=comment) @replies_blueprint.get('/api/replies/new') def new(): return render_template('replies/form.jinja') @replies_blueprint.post('/api/comments//replies') def create(comment_id): comment = db.get_or_404(Comment, comment_id) service = CreateReplyService(request.form, comment_id) status_code = service.call() if status_code != 200: abort(status_code) return render_template('replies/index.jinja', page=comments_query.replies_of(comment_id), comment=comment)