diff --git a/helpers/school_helpers.py b/helpers/school_helpers.py new file mode 100644 index 0000000..0b0e888 --- /dev/null +++ b/helpers/school_helpers.py @@ -0,0 +1,112 @@ +from typing import List, Dict, Optional, Union, Any +from datetime import datetime +from sqlalchemy.orm import Session +from models.school import School +from schemas.school import SchoolCreate, SchoolUpdate + +def validate_storage_type(storage_type: str) -> bool: + """ + Validate if storage type is one of the allowed values. + + Args: + storage_type: The storage type to validate + + Returns: + bool: True if storage type is valid, False otherwise + """ + valid_types = ['Warehouse', 'Cold Storage', 'Secure Vault', 'General Storage'] + return storage_type in valid_types + +def validate_security_level(security_level: str) -> bool: + """ + Validate if security level is one of the allowed values. + + Args: + security_level: The security level to validate + + Returns: + bool: True if security level is valid, False otherwise + """ + valid_levels = ['Low', 'Medium', 'High', 'Maximum'] + return security_level in valid_levels + +def calculate_available_space(total_space: int, occupied_space: int) -> int: + """ + Calculate available storage space. + + Args: + total_space: Total square footage + occupied_space: Currently occupied space + + Returns: + int: Available space in square feet + """ + available = total_space - occupied_space + return max(0, available) + +def check_capacity_limits(current_capacity: int, requested_space: int) -> bool: + """ + Check if requested storage space is within capacity limits. + + Args: + current_capacity: Current storage capacity + requested_space: Requested additional space + + Returns: + bool: True if space is available, False otherwise + """ + return current_capacity >= requested_space + +def get_available_temperature_controlled_facilities( + db: Session, + min_space: int = 0 +) -> List[School]: + """ + Get list of available temperature controlled storage facilities. + + Args: + db: Database session + min_space: Minimum space required + + Returns: + List of School objects meeting the criteria + """ + return db.query(School).filter( + School.temperature_controlled == True, + School.is_active == True, + School.available_space >= min_space + ).all() + +def update_facility_space( + db: Session, + facility_id: int, + space_change: int +) -> Union[School, Dict[str, str]]: + """ + Update available space for a storage facility. + + Args: + db: Database session + facility_id: ID of the facility to update + space_change: Change in space (positive for increase, negative for decrease) + + Returns: + Updated School object or error dict + """ + facility = db.query(School).filter(School.id == facility_id).first() + if not facility: + return {"error": "Facility not found"} + + new_available_space = facility.available_space - space_change + + if new_available_space < 0: + return {"error": "Insufficient space available"} + + if new_available_space > facility.square_footage: + return {"error": "Cannot exceed total facility space"} + + facility.available_space = new_available_space + db.commit() + db.refresh(facility) + + return facility \ No newline at end of file