1 | """ |
||
2 | byceps.blueprints.api.attendance.views |
||
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
4 | |||
5 | :Copyright: 2006-2019 Jochen Kupperschmidt |
||
6 | :License: Modified BSD, see LICENSE for details. |
||
7 | """ |
||
8 | |||
9 | from flask import abort, request |
||
10 | |||
11 | from ....services.party import service as party_service |
||
12 | from ....services.ticketing import attendance_service |
||
13 | from ....services.user import service as user_service |
||
14 | from ....util.framework.blueprint import create_blueprint |
||
15 | from ....util.views import respond_no_content |
||
16 | |||
17 | from ..decorators import api_token_required |
||
18 | |||
19 | |||
20 | blueprint = create_blueprint('api_attendance', __name__) |
||
21 | |||
22 | |||
23 | @blueprint.route('/archived_attendances', methods=['POST']) |
||
24 | @api_token_required |
||
25 | @respond_no_content |
||
26 | def create_archived_attendance(): |
||
27 | """Create an archived attendance of the user at the party.""" |
||
28 | user = _get_user_or_400() |
||
29 | party = _get_party_or_400() |
||
30 | |||
31 | attendance_service.create_archived_attendance(user.id, party.id) |
||
32 | |||
33 | |||
34 | def _get_user_or_400(): |
||
1 ignored issue
–
show
Duplication
introduced
by
Loading history...
|
|||
35 | user_id = request.form['user_id'] |
||
36 | if not user_id: |
||
37 | abort(400, 'User ID missing') |
||
38 | |||
39 | user = user_service.find_user(user_id) |
||
40 | if not user: |
||
41 | abort(400, 'User ID unknown') |
||
42 | |||
43 | return user |
||
44 | |||
45 | |||
46 | def _get_party_or_400(): |
||
47 | party_id = request.form['party_id'] |
||
48 | if party_id is None: |
||
49 | abort(400, 'Party ID missing') |
||
50 | |||
51 | party = party_service.find_party(party_id) |
||
52 | if not party: |
||
53 | abort(400, 'Party ID unknown') |
||
54 | |||
55 | return party |
||
56 |