Automated Action 27c9268a6a Implement HR platform backend with FastAPI and SQLite
- Set up project structure with FastAPI framework
- Create database models for users, employees, departments, and job titles
- Implement JWT authentication and authorization system
- Set up SQLite database with SQLAlchemy ORM
- Add Alembic migrations for database versioning
- Create CRUD API endpoints for employee management
- Implement category-based search functionality
- Add OpenAPI documentation and health check endpoint
- Update README with comprehensive setup and usage instructions
2025-06-03 01:18:41 +00:00

80 lines
2.5 KiB
Python

from fastapi import FastAPI, Depends
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import datetime
from sqlalchemy.orm import Session
from app.api.routes import api_router
from app.core.config import settings
from app.db import session
app = FastAPI(
title=settings.PROJECT_NAME,
description="""
HR Platform API provides functionality for managing employees, departments, and job titles.
## Authentication
All API endpoints are protected with JWT authentication (except for /auth/login, /auth/register, and /health).
To authenticate, you need to:
1. Login using the `/api/v1/auth/login` endpoint to get an access token
2. Include the token in the Authorization header for all requests: `Authorization: Bearer <token>`
## Features
* **User Management**: Create and manage user accounts with different permission levels
* **Employee Management**: Add, update, delete, and search employees
* **Department Management**: Organize employees by departments
* **Job Title Management**: Manage job positions
* **Category-Based Search**: Search employees by various criteria including skills and categories
""",
version="1.0.0",
openapi_url="/openapi.json",
docs_url="/docs",
redoc_url="/redoc",
contact={
"name": "HR Platform Support",
"email": "support@hrplatform.example.com",
},
license_info={
"name": "MIT License",
"url": "https://opensource.org/licenses/MIT",
},
)
# Set up CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API router
app.include_router(api_router, prefix=settings.API_V1_STR)
# Health check endpoint
@app.get("/health", tags=["health"])
async def health_check(db: Session = Depends(session.get_db)):
health_status = {
"status": "ok",
"api": "up",
"timestamp": datetime.datetime.now().isoformat(),
}
# Check database connection
try:
# Execute a simple query to check database connection
db.execute("SELECT 1")
health_status["database"] = "up"
except Exception as e:
health_status["database"] = "down"
health_status["database_error"] = str(e)
health_status["status"] = "degraded"
return health_status
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)