103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
"""Map sharing routes."""
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from uuid import UUID
|
|
|
|
from app.database import get_db
|
|
from app.dependencies import get_current_user
|
|
from app.models.user import User
|
|
from app.schemas.map_share import (
|
|
MapShareCreate,
|
|
MapShareUpdate,
|
|
MapShareResponse,
|
|
MapShareLinkCreate,
|
|
MapShareLinkResponse
|
|
)
|
|
from app.services import map_share_service
|
|
|
|
router = APIRouter(prefix="/api/maps/{map_id}/share", tags=["map-sharing"])
|
|
|
|
|
|
@router.post("/users", response_model=MapShareResponse, status_code=status.HTTP_201_CREATED)
|
|
async def share_map_with_user(
|
|
map_id: UUID,
|
|
share_data: MapShareCreate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Share a map with a specific user."""
|
|
share = map_share_service.create_map_share(db, map_id, share_data, current_user)
|
|
return share
|
|
|
|
|
|
@router.get("/users", response_model=List[MapShareResponse])
|
|
async def get_map_shares_list(
|
|
map_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get all users this map is shared with."""
|
|
shares = map_share_service.get_map_shares(db, map_id, current_user)
|
|
return shares
|
|
|
|
|
|
@router.put("/users/{share_id}", response_model=MapShareResponse)
|
|
async def update_map_share_permissions(
|
|
map_id: UUID,
|
|
share_id: UUID,
|
|
update_data: MapShareUpdate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Update share permissions for a user."""
|
|
share = map_share_service.update_map_share(db, map_id, share_id, update_data, current_user)
|
|
return share
|
|
|
|
|
|
@router.delete("/users/{share_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def revoke_map_share(
|
|
map_id: UUID,
|
|
share_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Revoke map share from a user."""
|
|
await map_share_service.delete_map_share(db, map_id, share_id, current_user)
|
|
return None
|
|
|
|
|
|
@router.post("/links", response_model=MapShareLinkResponse, status_code=status.HTTP_201_CREATED)
|
|
async def create_map_share_link(
|
|
map_id: UUID,
|
|
link_data: MapShareLinkCreate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Create a public/guest share link."""
|
|
link = map_share_service.create_share_link(db, map_id, link_data, current_user)
|
|
return link
|
|
|
|
|
|
@router.get("/links", response_model=List[MapShareLinkResponse])
|
|
async def get_map_share_links_list(
|
|
map_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Get all share links for a map."""
|
|
links = map_share_service.get_share_links(db, map_id, current_user)
|
|
return links
|
|
|
|
|
|
@router.delete("/links/{link_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_map_share_link(
|
|
map_id: UUID,
|
|
link_id: UUID,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Delete a share link."""
|
|
await map_share_service.delete_share_link(db, map_id, link_id, current_user)
|
|
return None
|