Automated Action 0fc3927871 Build comprehensive SaaS invoicing application with FastAPI
- Implemented complete authentication system with JWT tokens
- Created user management with registration and profile endpoints
- Built client management with full CRUD operations
- Developed invoice system with line items and automatic calculations
- Set up SQLite database with proper migrations using Alembic
- Added health monitoring and API documentation
- Configured CORS for cross-origin requests
- Included comprehensive README with usage examples
2025-06-23 14:56:50 +00:00

35 lines
1.1 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.db.session import get_db
from app.core.security import get_password_hash, get_current_user
from app.models.user import User
from app.schemas.user import UserCreate, UserResponse
router = APIRouter()
@router.post("/register", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
async def register_user(user: UserCreate, db: Session = Depends(get_db)):
db_user = db.query(User).filter(User.email == user.email).first()
if db_user:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Email already registered"
)
hashed_password = get_password_hash(user.password)
db_user = User(
email=user.email,
hashed_password=hashed_password,
full_name=user.full_name,
company_name=user.company_name
)
db.add(db_user)
db.commit()
db.refresh(db_user)
return db_user
@router.get("/me", response_model=UserResponse)
async def read_users_me(current_user: User = Depends(get_current_user)):
return current_user