Passed
Push — main ( a21473...138f92 )
by Jochen
04:19
created

_get_party_or_404()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 1
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
"""
2
byceps.blueprints.api.v1.ticketing
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from flask import abort, jsonify
10
11 1
from .....services.party import service as party_service
12 1
from .....services.party.transfer.models import Party
13 1
from .....services.ticketing import ticket_service
14
15 1
from .....typing import PartyID
16 1
from .....util.framework.blueprint import create_blueprint
17
18 1
from ...decorators import api_token_required
19
20
21 1
blueprint = create_blueprint('ticketing', __name__)
22
23
24 1
@blueprint.get('/sale_stats/<party_id>')
25 1
@api_token_required
26
def get_sale_stats(party_id):
27
    """Return the number of maximum and sold tickets, respectively, for
28
    that party.
29
    """
30 1
    party = _get_party_or_404(party_id)
31
32 1
    sale_stats = ticket_service.get_ticket_sale_stats(party.id)
33
34 1
    return jsonify(
35
        {
36
            'tickets_max': sale_stats.tickets_max,
37
            'tickets_sold': sale_stats.tickets_sold,
38
        }
39
    )
40
41
42 1
def _get_party_or_404(party_id: PartyID) -> Party:
43 1
    party = party_service.find_party(party_id)
44
45 1
    if party is None:
46
        abort(404)
47
48
    return party
49