|
7 | 7 | from flask_restx import Namespace, Resource |
8 | 8 |
|
9 | 9 | from compliance_api.auth import auth |
10 | | -from compliance_api.exceptions import BadRequestError, ResourceNotFoundError |
| 10 | +from compliance_api.exceptions import ResourceNotFoundError |
11 | 11 | from compliance_api.services.order.order import OrderService |
12 | 12 | from compliance_api.services.order.order_approval import OrderApprovalService |
13 | 13 |
|
14 | 14 | from ..schemas import ( |
15 | 15 | CreateOrderApprovalSchema, OrderApprovalSchema, OrderCreateSchema, OrderIssueSchema, OrderReplaceSchema, |
16 | | - OrderSchema, OrderStatusSchema, OrderUpdateSchema, ResetOrderFieldSchema, UpdateOrderApprovalStatusSchema) |
| 16 | + OrderSchema, OrderStatusSchema, OrderUpdateSchema, RenderRequestSchema, ResetOrderFieldSchema, |
| 17 | + UpdateOrderApprovalStatusSchema) |
17 | 18 | from ..utils.util import cors_preflight |
18 | 19 | from .apihelper import Api as ApiHelper |
19 | 20 |
|
|
49 | 50 | reset_order_field_model = ApiHelper.convert_ma_schema_to_restx_model( |
50 | 51 | API, ResetOrderFieldSchema(), "ResetOrderField" |
51 | 52 | ) |
| 53 | +order_render_request_model = ApiHelper.convert_ma_schema_to_restx_model( |
| 54 | + API, RenderRequestSchema(), "OrderRenderRequest" |
| 55 | +) |
52 | 56 |
|
53 | 57 | order_replace_model = ApiHelper.convert_ma_schema_to_restx_model( |
54 | 58 | API, OrderReplaceSchema(), "OrderReplace" |
@@ -250,23 +254,12 @@ class OrderPreview(Resource): |
250 | 254 | @API.response(code=200, description="Success") |
251 | 255 | @API.response(404, "Not Found") |
252 | 256 | @ApiHelper.swagger_decorators(API, endpoint_description="Preview order") |
253 | | - @API.doc( |
254 | | - params={ |
255 | | - "output_format": { |
256 | | - "description": "The output format of the order report", |
257 | | - "type": "string", |
258 | | - "required": False, |
259 | | - "default": "html", |
260 | | - "enum": ["html", "pdf"], |
261 | | - } |
262 | | - } |
263 | | - ) |
| 257 | + @API.expect(order_render_request_model) |
264 | 258 | @auth.require |
265 | 259 | def post(order_id): # pylint: disable=no-self-use, unused-argument |
266 | 260 | """Preview order.""" |
267 | | - output_format = request.args.get("output_format", "html") |
268 | | - if output_format not in ["html", "pdf"]: |
269 | | - raise BadRequestError("Invalid output format") |
| 261 | + render_request = RenderRequestSchema().load(API.payload or {}) |
| 262 | + output_format = render_request.get("output_format", "html") |
270 | 263 | response, order = OrderService.render(order_id, output_format) |
271 | 264 | if output_format == "pdf": |
272 | 265 | return send_file( |
|
0 commit comments