40 lines
985 B
Python
40 lines
985 B
Python
from fastapi import APIRouter, HTTPException
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
activity_logs = [] # In-memory storage
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/login")
|
|
async def log_activity(
|
|
user_id: str = "demo_user",
|
|
action: str = "login",
|
|
details: str = "User logged in"
|
|
):
|
|
"""Activity logging endpoint"""
|
|
if not user_id:
|
|
raise HTTPException(status_code=400, detail="User ID is required")
|
|
|
|
log_id = str(uuid.uuid4())
|
|
activity_logs.append({
|
|
"id": log_id,
|
|
"user_id": user_id,
|
|
"action": action,
|
|
"details": details,
|
|
"timestamp": datetime.now().isoformat(),
|
|
"metadata": {
|
|
"ip_address": "127.0.0.1",
|
|
"user_agent": "demo_agent"
|
|
}
|
|
})
|
|
|
|
return {
|
|
"message": "Activity logged successfully",
|
|
"log_id": log_id,
|
|
"user_id": user_id,
|
|
"features": {
|
|
"retention_days": 30,
|
|
"analytics_enabled": True
|
|
}
|
|
} |