a working product with ugly ui

This commit is contained in:
2025-12-12 20:15:27 +05:00
parent e6d04f986f
commit 4d3085623a
77 changed files with 8750 additions and 0 deletions

94
app/routers/maps.py Normal file
View File

@@ -0,0 +1,94 @@
"""Maps router for CRUD operations."""
from typing import List
from uuid import UUID
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.database import get_db
from app.dependencies import get_current_user, get_optional_current_user
from app.models.user import User
from app.schemas.map import MapCreate, MapUpdate, MapResponse
from app.services import map_service
router = APIRouter(prefix="/api/maps", tags=["maps"])
@router.get("", response_model=List[MapResponse])
async def list_user_maps(
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Get all maps owned by the current user."""
maps = map_service.get_user_maps(db, current_user.id)
return maps
@router.post("", response_model=MapResponse, status_code=status.HTTP_201_CREATED)
async def create_map(
map_data: MapCreate,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Create a new map."""
new_map = map_service.create_map(db, map_data, current_user.id)
return new_map
@router.get("/public", response_model=MapResponse)
async def get_public_map(db: Session = Depends(get_db)):
"""Get the default public map (no authentication required)."""
public_map = map_service.get_default_public_map(db)
if not public_map:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="No public map available"
)
return public_map
@router.get("/{map_id}", response_model=MapResponse)
async def get_map(
map_id: UUID,
current_user: User = Depends(get_optional_current_user),
db: Session = Depends(get_db)
):
"""Get a specific map by ID. Requires authentication unless it's the public map."""
map_obj = map_service.get_map_by_id(db, map_id, current_user)
return map_obj
@router.patch("/{map_id}", response_model=MapResponse)
async def update_map(
map_id: UUID,
map_data: MapUpdate,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Update a map. Only the owner or admin can update."""
updated_map = map_service.update_map(db, map_id, map_data, current_user)
return updated_map
@router.delete("/{map_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_map(
map_id: UUID,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Delete a map. Only the owner or admin can delete."""
map_service.delete_map(db, map_id, current_user)
return None
@router.post("/{map_id}/set-default-public", response_model=MapResponse)
async def set_default_public(
map_id: UUID,
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""Set a map as the default public map. Admin only."""
updated_map = map_service.set_default_public_map(db, map_id, current_user)
return updated_map