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
Executable → Regular
+17
View File
@@ -0,0 +1,17 @@
from app.routers.projects import router as projects
from app.routers.customers import router as customers
from app.routers.systems import router as systems
from app.routers.contracts import router as contracts
from app.routers.purchases import router as purchases
from app.routers.documents import router as documents
from app.routers.ui import router as ui
__all__ = [
"projects",
"customers",
"systems",
"contracts",
"purchases",
"documents",
"ui",
]
Binary file not shown.
Regular → Executable
+138 -138
View File
@@ -1,139 +1,139 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import License, LicenseType, Product
from app.schemas import LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate
router = APIRouter()
# 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()
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import License, LicenseType, Product
from app.schemas import LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate
router = APIRouter()
# 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"}
Regular → Executable
+182 -182
View File
@@ -1,183 +1,183 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
router = APIRouter()
# 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()
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
router = APIRouter()
# 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"}
+51
View File
@@ -0,0 +1,51 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import Project, System, Guardian, Module, SystemModule
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, GuardianCreate, GuardianUpdate
router = APIRouter()
# Project routes
@router.get("/projects")
async def get_projects(db: Session = Depends(get_db)):
projects = db.query(Project).all()
return projects
@router.get("/projects/{project_id}")
async def get_project(project_id: int, db: Session = Depends(get_db)):
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
return project
@router.post("/projects")
async def create_project(project: ProjectCreate, db: Session = Depends(get_db)):
db_project = Project(**project.dict())
db.add(db_project)
db.commit()
db.refresh(db_project)
return db_project
@router.put("/projects/{project_id}")
async def update_project(project_id: int, project: ProjectUpdate, db: Session = Depends(get_db)):
db_project = db.query(Project).filter(Project.id == project_id).first()
if not db_project:
raise HTTPException(status_code=404, detail="Project not found")
for key, value in project.dict(exclude_unset=True).items():
setattr(db_project, key, value)
db.commit()
db.refresh(db_project)
return db_project
@router.delete("/projects/{project_id}")
async def delete_project(project_id: int, db: Session = Depends(get_db)):
db_project = db.query(Project).filter(Project.id == project_id).first()
if not db_project:
raise HTTPException(status_code=404, detail="Project not found")
db.delete(db_project)
db.commit()
return {"message": "Project deleted successfully"}
+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"}
+110 -12
View File
@@ -11,7 +11,7 @@ from typing import Optional
from app.database import get_db
from app.services.resource_allocation_service import ResourceAllocationService
from app.services.procurement_flow_service import ProcurementFlowService
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase, SystemModule, SpecificationItem, PurchaseItem, Contract, PurchaseSpecification
router = APIRouter(prefix="/ui", tags=["UI"])
templates = Jinja2Templates(directory="app/templates")
@@ -75,9 +75,9 @@ async def project_detail(request: Request, project_id: int, db: Session = Depend
if not project:
raise HTTPException(status_code=404, detail="Project not found")
customers = db.query(Project).filter(Project.id == project_id).first().customers
customers = project.customers
systems = db.query(System).filter(System.project_id == project_id).all()
contracts = db.query(Project).filter(Project.id == project_id).first().contracts
contracts = db.query(Contract).filter(Contract.project_id == project_id).all()
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
@@ -118,8 +118,8 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
if not system:
raise HTTPException(status_code=404, detail="System not found")
# Get Common part (guardian_id = NULL)
common_modules = db.query(SystemModule).filter(
# Get Common part (guardian_id = NULL) with joined loading
common_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == None
).all()
@@ -129,13 +129,13 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
guardian_data = []
for guardian in guardians:
core = db.query(SystemModule).filter(
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == guardian.id,
Module.name == "Core"
).first()
other_modules = db.query(SystemModule).filter(
other_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == guardian.id
).all()
@@ -164,12 +164,12 @@ async def guardian_detail(request: Request, guardian_id: int, db: Session = Depe
if not guardian:
raise HTTPException(status_code=404, detail="Guardian not found")
core = db.query(SystemModule).filter(
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.guardian_id == guardian_id,
Module.name == "Core"
).first()
modules = db.query(SystemModule).filter(
modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.guardian_id == guardian_id
).all()
@@ -205,6 +205,9 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
if not resource:
raise HTTPException(status_code=404, detail="Resource not found")
# Get systems for this project
systems = db.query(System).filter(System.project_id == resource.project_id).all()
# Get allocations for this resource
allocations = db.query(ResourceAllocation).filter(
ResourceAllocation.resource_id == resource_id
@@ -233,7 +236,8 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
"request": request,
"resource": resource,
"allocations": allocation_details,
"remaining": remaining
"remaining": remaining,
"systems": systems
}
)
@@ -297,7 +301,7 @@ async def specification_detail(request: Request, specification_id: int, db: Sess
if not specification:
raise HTTPException(status_code=404, detail="Specification not found")
items = db.query(SpecificationItem).filter(
items = db.query(SpecificationItem).join(Module, SpecificationItem.module_id == Module.id).filter(
SpecificationItem.specification_id == specification_id
).all()
@@ -327,7 +331,7 @@ async def purchases_list(request: Request, project_id: Optional[int] = None, db:
@router.get("/purchases/{purchase_id}")
async def purchase_detail(request: Request, purchase_id: int, db: Session = Depends(get_db)):
"""Purchase detail page."""
"Purchase detail page."
purchase = db.query(Purchase).filter(Purchase.id == purchase_id).first()
if not purchase:
raise HTTPException(status_code=404, detail="Purchase not found")
@@ -355,9 +359,103 @@ async def purchase_detail(request: Request, purchase_id: int, db: Session = Depe
)
@router.get("/projects")
async def projects_list(request: Request, db: Session = Depends(get_db)):
"""List all projects."""
projects = db.query(Project).all()
return templates.TemplateResponse(
"projects/list.html",
{"request": request, "projects": projects}
)
async def project_systems_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Systems list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
systems = db.query(System).filter(System.project_id == project_id).all()
return templates.TemplateResponse(
"systems/list.html",
{"request": request, "systems": systems, "project_id": project_id}
)
@router.get("/projects/{project_id}/resources")
async def project_resources_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Resources list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
return templates.TemplateResponse(
"resources/list.html",
{"request": request, "resources": resources, "project_id": project_id}
)
@router.get("/projects/{project_id}/specifications")
async def project_specifications_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Specifications list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
specifications = db.query(Specification).filter(Specification.project_id == project_id).all()
return templates.TemplateResponse(
"specifications/list.html",
{"request": request, "specifications": specifications, "project_id": project_id}
)
@router.get("/projects/{project_id}/purchases")
async def project_purchases_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Purchases list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
return templates.TemplateResponse(
"purchases/list.html",
{"request": request, "purchases": purchases, "project_id": project_id}
)
@router.get("/seed")
async def seed_demo_data(db: Session = Depends(get_db)):
"""Seed demo data endpoint."""
from app.utils.seed_data import seed_demo_data
seed_demo_data(db)
return {"message": "Demo data seeded successfully"}
@router.get("/resources/{resource_id}/allocate")
async def allocate_resource(request: Request, resource_id: int, system_id: int = Query(...), guardian_id: Optional[int] = Query(None), quantity: int = Query(...), db: Session = Depends(get_db)):
"""Allocate resource to system/guardian."""
# Use ResourceAllocationService for business logic
service = ResourceAllocationService(db)
result = service.allocate_resource(resource_id, system_id, guardian_id, quantity)
if result['success']:
return templates.TemplateResponse(
"resources/allocated.html",
{
"request": request,
"allocation": result['allocation'],
"resource": result['resource'],
"system": result['system'],
"guardian": result.get('guardian')
}
)
else:
return templates.TemplateResponse(
"resources/allocate_error.html",
{
"request": request,
"error": result['error'],
"resource": result.get('resource'),
"resource_id": resource_id
}
)