API improvements and maybe some "eh" reporting style improvements.

This commit is contained in:
Yaro Kasear 2025-09-12 12:58:37 -05:00
parent 31cc630dcf
commit cc4bdafa0b
2 changed files with 35 additions and 10 deletions

View file

@ -6,26 +6,41 @@ def generate_crud_blueprint(model, service):
@bp.get('/')
def list_items():
items = service.list(request.args)
try:
return jsonify([item.as_dict() for item in items])
except Exception as e:
return jsonify({"status": "error", "error": str(e)})
@bp.get('/<int:id>')
def get_item(id):
item = service.get(id, request.args)
try:
return jsonify(item.as_dict())
except Exception as e:
return jsonify({"status": "error", "error": str(e)})
@bp.post('/')
def create_item():
obj = service.create(request.json)
try:
return jsonify(obj.as_dict())
except Exception as e:
return jsonify({"status": "error", "error": str(e)})
@bp.patch('/<int:id>')
def update_item(id):
obj = service.update(id, request.json)
try:
return jsonify(obj.as_dict())
except Exception as e:
return jsonify({"status": "error", "error": str(e)})
@bp.delete('/<int:id>')
def delete_item(id):
service.delete(id)
return '', 204
try:
return jsonify({"status": "success"}), 204
except Exception as e:
return jsonify({"status": "error", "error": str(e)})
return bp

View file

@ -1,17 +1,27 @@
{% extends 'base.html' %}
{% block style %}
.chart-container { height: 420px; }
.pivot-cell { min-width: 0; min-height: 0; }
.table-responsive { max-height: 420px; overflow: auto; }
#pivot thead th { position: sticky; top: 0; z-index: 1; background: var(--bs-body-bg); }
{% endblock %}
{% block main %}
<h1 class="display-2 text-center">{{ title or "Inventory Manager" }}</h1>
<p class="lead text-center">Find out about all of your assets.</p>
<div class="row">
<div class="col">
<div class="col pivot-cell">
<p class="display-6 text-center">Active Worklogs</p>
{{ logs | safe }}
</div>
<div class="col">
<p class="display-6 text-center">Inventory PivotTable</p>
<div class="col pivot-cell">
<p class="display-6 text-center">Inventory Report</p>
<div class="d-flex flex-wrap gap-2 align-items-end mb-2">
<div>
@ -52,11 +62,11 @@
<button id="export" class="btn btn-sm btn-outline-secondary">Export CSV</button>
</div>
<div class="table-responsive" style="max-height: 520px; overflow: auto;">
<div class="table-responsive" style="overflow: auto;">
<table id="pivot" class="table table-sm table-bordered align-middle mb-2"></table>
</div>
<div class="chart-container" style="height:420px;">
<div class="chart-container">
<canvas id="pivot-chart"></canvas>
</div>
</div>