33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from fastapi.security import OAuth2PasswordBearer
|
|
from services.points_of_interest_service import PointsOfInterestService
|
|
from models.schemas import CreatePointOfInterest, UpdatePointOfInterest
|
|
from config.database import get_db
|
|
|
|
router = APIRouter()
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/auth/token")
|
|
|
|
@router.post("/", status_code=201)
|
|
async def create_point(point: CreatePointOfInterest, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await PointsOfInterestService.create_point_of_interest(point, db, token)
|
|
|
|
@router.get("/{point_id}")
|
|
async def get_point(point_id: int):
|
|
async with get_db() as db:
|
|
return await PointsOfInterestService.get_point_of_interest(point_id, db)
|
|
|
|
@router.get("/")
|
|
async def get_all_points():
|
|
async with get_db() as db:
|
|
return await PointsOfInterestService.get_all_points_of_interest(db)
|
|
|
|
@router.put("/{point_id}")
|
|
async def update_point(point_id: int, point: UpdatePointOfInterest, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await PointsOfInterestService.update_point_of_interest(point_id, point, db, token)
|
|
|
|
@router.delete("/{point_id}")
|
|
async def delete_point(point_id: int, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await PointsOfInterestService.delete_point_of_interest(point_id, db, token) |