~homeworkprod/byceps

ref: 342e5296ae417372e544ce931b442e98301c17a1 byceps/byceps/blueprints/api/v1/attendance/views.py -rw-r--r-- 1.4 KiB
342e5296 — Jochen Kupperschmidt Require body blocks in base templates 2 months ago
                                                                                
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
40
41
42
43
44
45
46
47
48
"""
byceps.blueprints.api.v1.attendance.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import abort, request
from marshmallow import ValidationError

from .....services.party import service as party_service
from .....services.ticketing import attendance_service
from .....services.user import service as user_service
from .....util.framework.blueprint import create_blueprint
from .....util.views import respond_no_content

from ...decorators import api_token_required

from .schemas import CreateArchivedAttendanceRequest


blueprint = create_blueprint('api_v1_attendance', __name__)


@blueprint.route('/archived_attendances', methods=['POST'])
@api_token_required
@respond_no_content
def create_archived_attendance():
    """Create an archived attendance of the user at the party."""
    if not request.is_json:
        abort(415)

    schema = CreateArchivedAttendanceRequest()
    try:
        req = schema.load(request.get_json())
    except ValidationError as e:
        abort(400, str(e.normalized_messages()))

    user = user_service.find_user(req['user_id'])
    if not user:
        abort(400, 'User ID unknown')

    party = party_service.find_party(req['party_id'])
    if not party:
        abort(400, 'Party ID unknown')

    attendance_service.create_archived_attendance(user.id, party.id)