Move relationship types + dashboard recent off the machines blueprint
- Add /api/assets/relationshiptypes (GET/POST) serving RelationshipType; point relationshipTypesApi at it instead of the legacy /api/machines blueprint. - Dashboard recent-devices widget reads assetsApi.list (asset shape) instead of machinesApi. No frontend code references machinesApi anymore. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,51 @@ def delete_asset_status(status_id: int):
|
||||
return success_response(message='Asset status deleted')
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Relationship Types
|
||||
# =============================================================================
|
||||
|
||||
@assets_bp.route('/relationshiptypes', methods=['GET'])
|
||||
@jwt_required(optional=True)
|
||||
def list_relationship_types():
|
||||
"""List all asset relationship types."""
|
||||
types = RelationshipType.query.order_by(RelationshipType.relationshiptype).all()
|
||||
return success_response([{
|
||||
'relationshiptypeid': t.relationshiptypeid,
|
||||
'relationshiptype': t.relationshiptype,
|
||||
'description': t.description
|
||||
} for t in types])
|
||||
|
||||
|
||||
@assets_bp.route('/relationshiptypes', methods=['POST'])
|
||||
@jwt_required()
|
||||
def create_relationship_type():
|
||||
"""Create a new asset relationship type."""
|
||||
data = request.get_json()
|
||||
if not data or not data.get('relationshiptype'):
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR, 'relationshiptype is required')
|
||||
|
||||
if RelationshipType.query.filter_by(relationshiptype=data['relationshiptype']).first():
|
||||
return error_response(
|
||||
ErrorCodes.CONFLICT,
|
||||
f"Relationship type '{data['relationshiptype']}' already exists",
|
||||
http_code=409
|
||||
)
|
||||
|
||||
rel_type = RelationshipType(
|
||||
relationshiptype=data['relationshiptype'],
|
||||
description=data.get('description')
|
||||
)
|
||||
db.session.add(rel_type)
|
||||
db.session.commit()
|
||||
|
||||
return success_response({
|
||||
'relationshiptypeid': rel_type.relationshiptypeid,
|
||||
'relationshiptype': rel_type.relationshiptype,
|
||||
'description': rel_type.description
|
||||
}, message='Relationship type created', http_code=201)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Assets
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user