flask plugin new output, minus the scaffold's AssetType seeding: printed parts are quantity-based consumables, not ADR-001 assets. on_install seeds the three plugin settings instead. Manifest pins core >=0.11.0, depends on employees (badge name resolution), ships disabled until a site opts in.
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""Printedparts plugin API routes."""
|
|
|
|
from flask import Blueprint, request
|
|
from flask_jwt_extended import jwt_required
|
|
|
|
from shopdb.api import (
|
|
success_response,
|
|
error_response,
|
|
paginated_response,
|
|
ErrorCodes,
|
|
get_pagination_params,
|
|
paginate_query,
|
|
)
|
|
|
|
from ..models import Printedparts
|
|
|
|
|
|
printedparts_bp = Blueprint('printedparts', __name__)
|
|
|
|
|
|
@printedparts_bp.route('', methods=['GET'])
|
|
@jwt_required(optional=True)
|
|
def list_printedparts():
|
|
"""List printedparts assets, paginated."""
|
|
page, per_page = get_pagination_params(request)
|
|
|
|
query = Printedparts.query
|
|
items, total = paginate_query(query, page, per_page)
|
|
data = [item.to_dict() for item in items]
|
|
|
|
return paginated_response(data, page, per_page, total)
|
|
|
|
|
|
@printedparts_bp.route('/<int:assetid>', methods=['GET'])
|
|
@jwt_required(optional=True)
|
|
def get_printedparts(assetid: int):
|
|
"""Get a single printedparts by assetid."""
|
|
item = Printedparts.query.get(assetid)
|
|
if not item:
|
|
return error_response(
|
|
ErrorCodes.NOT_FOUND,
|
|
f'Printedparts with assetid {assetid} not found',
|
|
http_code=404,
|
|
)
|
|
return success_response(item.to_dict())
|