
- Set up project structure with FastAPI application - Implement SQLAlchemy models for users, services, projects, team members, contacts - Create API endpoints for website functionality - Implement JWT authentication system with user roles - Add file upload functionality for media - Configure CORS and health check endpoints - Add database migrations with Alembic - Create comprehensive README with setup instructions
94 lines
2.4 KiB
Python
94 lines
2.4 KiB
Python
from typing import Any, List
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app import crud, models, schemas
|
|
from app.api import deps
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/", response_model=schemas.Contact)
|
|
def create_contact_message(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
contact_in: schemas.ContactCreate,
|
|
) -> Any:
|
|
"""
|
|
Create new contact message.
|
|
"""
|
|
contact = crud.contact.create(db, obj_in=contact_in)
|
|
return contact
|
|
|
|
|
|
@router.get("/", response_model=List[schemas.Contact])
|
|
def read_contact_messages(
|
|
db: Session = Depends(deps.get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: models.User = Depends(deps.get_current_active_superuser),
|
|
) -> Any:
|
|
"""
|
|
Retrieve contact messages.
|
|
"""
|
|
contacts = crud.contact.get_multi(db, skip=skip, limit=limit)
|
|
return contacts
|
|
|
|
|
|
@router.get("/{id}", response_model=schemas.Contact)
|
|
def read_contact_message(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
current_user: models.User = Depends(deps.get_current_active_superuser),
|
|
) -> Any:
|
|
"""
|
|
Get contact message by ID.
|
|
"""
|
|
contact = crud.contact.get(db, id=id)
|
|
if not contact:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Contact message not found",
|
|
)
|
|
return contact
|
|
|
|
|
|
@router.put("/{id}/read", response_model=schemas.Contact)
|
|
def mark_contact_as_read(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
current_user: models.User = Depends(deps.get_current_active_superuser),
|
|
) -> Any:
|
|
"""
|
|
Mark a contact message as read.
|
|
"""
|
|
contact = crud.contact.mark_as_read(db, id=id)
|
|
if not contact:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Contact message not found",
|
|
)
|
|
return contact
|
|
|
|
|
|
@router.delete("/{id}", response_model=schemas.Contact)
|
|
def delete_contact_message(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
current_user: models.User = Depends(deps.get_current_active_superuser),
|
|
) -> Any:
|
|
"""
|
|
Delete a contact message.
|
|
"""
|
|
contact = crud.contact.get(db, id=id)
|
|
if not contact:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Contact message not found",
|
|
)
|
|
contact = crud.contact.remove(db, id=id)
|
|
return contact |