printedparts stage 1: scaffold, no AssetType, manifest per spec
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.
This commit is contained in:
45
plugins/printedparts/api/routes.py
Normal file
45
plugins/printedparts/api/routes.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""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())
|
||||
Reference in New Issue
Block a user