50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
import uuid
|
|
from typing import Optional
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/api/employees")
|
|
async def create_employee(
|
|
name: str,
|
|
position: str,
|
|
email: str,
|
|
department: Optional[str] = None,
|
|
salary: Optional[float] = None
|
|
):
|
|
"""Create new employee record"""
|
|
employee_id = str(uuid.uuid4())
|
|
|
|
if email in [emp.get("email") for emp in fake_users_db.values()]:
|
|
raise HTTPException(status_code=400, detail="Employee with this email already exists")
|
|
|
|
employee_data = {
|
|
"id": employee_id,
|
|
"name": name,
|
|
"position": position,
|
|
"email": email,
|
|
"department": department,
|
|
"salary": salary,
|
|
"active": True
|
|
}
|
|
|
|
fake_users_db[employee_id] = employee_data
|
|
|
|
return {
|
|
"message": "Employee created successfully",
|
|
"data": {
|
|
"employee_id": employee_id,
|
|
"name": name,
|
|
"email": email
|
|
},
|
|
"metadata": {
|
|
"created_at": "demo_timestamp",
|
|
"department": department
|
|
},
|
|
"next_steps": [
|
|
"Complete employee onboarding",
|
|
"Assign access credentials",
|
|
"Schedule orientation"
|
|
]
|
|
} |