summaryrefslogtreecommitdiff
path: root/src/controllers/comments_controller.py
blob: c9bab0d6020182688f1c6c1efdfc203acac1cb74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Blueprint, request, abort, render_template
from src.queries import CommentsQuery
from src.services import CreateCommentService


comments_blueprint = Blueprint('comments_controller',
                               '__comments_controller__')
query = CommentsQuery()


@comments_blueprint.post('/api/comments')
def create():
    service = CreateCommentService(request.args | request.form)
    status_code = service.call()

    if status_code == 404:
        abort(404)

    return render_template('comments/index.jinja',
                           page=query.comments_of_post(
                               request.args.get('path')
                           ))


@comments_blueprint.get('/api/comments/new')
def new():
    return render_template('comments/form.jinja')


@comments_blueprint.get('/api/comments')
def index():
    post = request.args.get('path')
    page = query.comments_of_post(post)

    if page.total == 0:
        abort(404)

    return render_template('comments/index.jinja',
                           page=page)