Prepare Specs UI for Windows review

This commit is contained in:
Alex
2026-10-10 11:30:27 +00:00
parent 6e6035c789
commit 25511870ff
68 changed files with 1931 additions and 1070 deletions
+2 -354
View File
@@ -1,8 +1,8 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import Project, System, Key, Guardian, License, LicenseType, Product, ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, KeyCreate, KeyUpdate, GuardianCreate, GuardianUpdate, LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate, ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
from app.models import Project, System, Guardian, Module, SystemModule
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, GuardianCreate, GuardianUpdate
router = APIRouter()
@@ -94,50 +94,6 @@ async def delete_system(system_id: int, db: Session = Depends(get_db)):
db.commit()
return {"message": "System deleted successfully"}
# Key routes
@router.get("/keys")
async def get_keys(db: Session = Depends(get_db)):
keys = db.query(Key).all()
return keys
@router.get("/keys/{key_id}")
async def get_key(key_id: int, db: Session = Depends(get_db)):
key = db.query(Key).filter(Key.id == key_id).first()
if not key:
raise HTTPException(status_code=404, detail="Key not found")
return key
@router.post("/keys")
async def create_key(key: KeyCreate, db: Session = Depends(get_db)):
db_key = Key(**key.dict())
db.add(db_key)
db.commit()
db.refresh(db_key)
return db_key
@router.put("/keys/{key_id}")
async def update_key(key_id: int, key: KeyUpdate, db: Session = Depends(get_db)):
db_key = db.query(Key).filter(Key.id == key_id).first()
if not db_key:
raise HTTPException(status_code=404, detail="Key not found")
for key, value in key.dict(exclude_unset=True).items():
setattr(db_key, key, value)
db.commit()
db.refresh(db_key)
return db_key
@router.delete("/keys/{key_id}")
async def delete_key(key_id: int, db: Session = Depends(get_db)):
db_key = db.query(Key).filter(Key.id == key_id).first()
if not db_key:
raise HTTPException(status_code=404, detail="Key not found")
db.delete(db_key)
db.commit()
return {"message": "Key deleted successfully"}
# Guardian routes
@router.get("/guardians")
async def get_guardians(db: Session = Depends(get_db)):
@@ -181,311 +137,3 @@ async def delete_guardian(guardian_id: int, db: Session = Depends(get_db)):
db.delete(db_guardian)
db.commit()
return {"message": "Guardian deleted successfully"}
# License routes
@router.get("/licenses")
async def get_licenses(db: Session = Depends(get_db)):
licenses = db.query(License).all()
return licenses
@router.get("/licenses/{license_id}")
async def get_license(license_id: int, db: Session = Depends(get_db)):
license = db.query(License).filter(License.id == license_id).first()
if not license:
raise HTTPException(status_code=404, detail="License not found")
return license
@router.post("/licenses")
async def create_license(license: LicenseCreate, db: Session = Depends(get_db)):
db_license = License(**license.dict())
db.add(db_license)
db.commit()
db.refresh(db_license)
return db_license
@router.put("/licenses/{license_id}")
async def update_license(license_id: int, license: LicenseUpdate, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
for key, value in license.dict(exclude_unset=True).items():
setattr(db_license, key, value)
db.commit()
db.refresh(db_license)
return db_license
@router.delete("/licenses/{license_id}")
async def delete_license(license_id: int, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
db.delete(db_license)
db.commit()
return {"message": "License deleted successfully"}
# LicenseType routes
@router.get("/license_types")
async def get_license_types(db: Session = Depends(get_db)):
license_types = db.query(LicenseType).all()
return license_types
@router.get("/license_types/{license_type_id}")
async def get_license_type(license_type_id: int, db: Session = Depends(get_db)):
license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not license_type:
raise HTTPException(status_code=404, detail="License type not found")
return license_type
@router.post("/license_types")
async def create_license_type(license_type: LicenseTypeCreate, db: Session = Depends(get_db)):
db_license_type = LicenseType(**license_type.dict())
db.add(db_license_type)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.put("/license_types/{license_type_id}")
async def update_license_type(license_type_id: int, license_type: LicenseTypeUpdate, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
for key, value in license_type.dict(exclude_unset=True).items():
setattr(db_license_type, key, value)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.delete("/license_types/{license_type_id}")
async def delete_license_type(license_type_id: int, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
db.delete(db_license_type)
db.commit()
return {"message": "License type deleted successfully"}
# Product routes
@router.get("/products")
async def get_products(db: Session = Depends(get_db)):
products = db.query(Product).all()
return products
@router.get("/products/{product_id}")
async def get_product(product_id: int, db: Session = Depends(get_db)):
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
return product
@router.post("/products")
async def create_product(product: ProductCreate, db: Session = Depends(get_db)):
db_product = Product(**product.dict())
db.add(db_product)
db.commit()
db.refresh(db_product)
return db_product
@router.put("/products/{product_id}")
async def update_product(product_id: int, product: ProductUpdate, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
for key, value in product.dict(exclude_unset=True).items():
setattr(db_product, key, value)
db.commit()
db.refresh(db_product)
return db_product
@router.delete("/products/{product_id}")
async def delete_product(product_id: int, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
db.delete(db_product)
db.commit()
return {"message": "Product deleted successfully"}
# ResourcePool routes
@router.get("/resource_pools")
async def get_resource_pools(db: Session = Depends(get_db)):
pools = db.query(ResourcePool).all()
return pools
@router.get("/resource_pools/{pool_id}")
async def get_resource_pool(pool_id: int, db: Session = Depends(get_db)):
pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
return pool
@router.post("/resource_pools")
async def create_resource_pool(pool: ResourcePoolCreate, db: Session = Depends(get_db)):
db_pool = ResourcePool(**pool.dict())
db.add(db_pool)
db.commit()
db.refresh(db_pool)
return db_pool
@router.put("/resource_pools/{pool_id}")
async def update_resource_pool(pool_id: int, pool: ResourcePoolUpdate, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
for key, value in pool.dict(exclude_unset=True).items():
setattr(db_pool, key, value)
db.commit()
db.refresh(db_pool)
return db_pool
@router.delete("/resource_pools/{pool_id}")
async def delete_resource_pool(pool_id: int, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
db.delete(db_pool)
db.commit()
return {"message": "Resource pool deleted successfully"}
# PoolResource routes
@router.get("/pool_resources")
async def get_pool_resources(db: Session = Depends(get_db)):
resources = db.query(PoolResource).all()
return resources
@router.get("/pool_resources/{resource_id}")
async def get_pool_resource(resource_id: int, db: Session = Depends(get_db)):
resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
return resource
@router.post("/pool_resources")
async def create_pool_resource(resource: PoolResourceCreate, db: Session = Depends(get_db)):
db_resource = PoolResource(**resource.dict())
db.add(db_resource)
db.commit()
db.refresh(db_resource)
return db_resource
@router.put("/pool_resources/{resource_id}")
async def update_pool_resource(resource_id: int, resource: PoolResourceUpdate, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
for key, value in resource.dict(exclude_unset=True).items():
setattr(db_resource, key, value)
db.commit()
db.refresh(db_resource)
return db_resource
@router.delete("/pool_resources/{resource_id}")
async def delete_pool_resource(resource_id: int, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
db.delete(db_resource)
db.commit()
return {"message": "Pool resource deleted successfully"}
# PoolReceipt routes
@router.get("/pool_receipts")
async def get_pool_receipts(db: Session = Depends(get_db)):
receipts = db.query(PoolReceipt).all()
return receipts
@router.get("/pool_receipts/{receipt_id}")
async def get_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
return receipt
@router.post("/pool_receipts")
async def create_pool_receipt(receipt: PoolReceiptCreate, db: Session = Depends(get_db)):
db_receipt = PoolReceipt(**receipt.dict())
db.add(db_receipt)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.put("/pool_receipts/{receipt_id}")
async def update_pool_receipt(receipt_id: int, receipt: PoolReceiptUpdate, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
for key, value in receipt.dict(exclude_unset=True).items():
setattr(db_receipt, key, value)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.delete("/pool_receipts/{receipt_id}")
async def delete_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
db.delete(db_receipt)
db.commit()
return {"message": "Pool receipt deleted successfully"}
# PoolAllocation routes
@router.get("/pool_allocations")
async def get_pool_allocations(db: Session = Depends(get_db)):
allocations = db.query(PoolAllocation).all()
return allocations
@router.get("/pool_allocations/{allocation_id}")
async def get_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
return allocation
@router.post("/pool_allocations")
async def create_pool_allocation(allocation: PoolAllocationCreate, db: Session = Depends(get_db)):
db_allocation = PoolAllocation(**allocation.dict())
db.add(db_allocation)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.put("/pool_allocations/{allocation_id}")
async def update_pool_allocation(allocation_id: int, allocation: PoolAllocationUpdate, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
for key, value in allocation.dict(exclude_unset=True).items():
setattr(db_allocation, key, value)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.delete("/pool_allocations/{allocation_id}")
async def delete_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
db.delete(db_allocation)
db.commit()
return {"message": "Pool allocation deleted successfully"}