Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use OrderAmountInputSchema #7036

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/api/custom/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from app.api.helpers.order import calculate_order_amount, create_pdf_tickets_for_holder
from app.api.helpers.permission_manager import has_access
from app.api.helpers.storage import UPLOAD_PATHS, generate_hash
from app.api.custom.schema.order_amount import OrderAmountInputSchema
from app.api.schema.attendees import AttendeeSchema
from app.api.schema.orders import OrderSchema
from app.extensions.limiter import limiter
Expand Down Expand Up @@ -115,8 +116,8 @@ def resend_emails():

@order_blueprint.route('/calculate-amount', methods=['POST'])
def calculate_amount():
data = request.get_json()
return jsonify(calculate_order_amount(data['tickets'], data.get('discount-code')))
data, errors = OrderAmountInputSchema().load(request.get_json())
return jsonify(calculate_order_amount(data['tickets'], data.get('discount_code')))


@order_blueprint.route('/create-order', methods=['POST'])
Expand Down
12 changes: 12 additions & 0 deletions app/api/custom/schema/order_amount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from marshmallow import Schema, fields


class TicketSchema(Schema):
id = fields.Integer(required=True)
quantity = fields.Integer(default=1)
price = fields.Float()


class OrderAmountInputSchema(Schema):
tickets = fields.Nested(TicketSchema, many=True)
discount_code = fields.Integer(load_from='discount-code')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black would make changes.

2 changes: 1 addition & 1 deletion app/api/helpers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def calculate_order_amount(tickets, discount_code=None):
included=tax_included,
amount=round(total_tax, 2),
percent=tax.rate if tax else 0.0,
name=tax.name
name=tax.name,
)

return dict(
Expand Down