35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from fastapi.security import OAuth2PasswordBearer
|
|
from services.report_service import ReportService
|
|
from models.schemas import UserReport, UserReportUpdate
|
|
from config.database import get_db
|
|
from services.auth_service import AuthService
|
|
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/auth/token")
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/", status_code=status.HTTP_201_CREATED)
|
|
async def report_user(report: UserReport):
|
|
async with get_db() as db:
|
|
return await ReportService.create_report(report, db)
|
|
|
|
@router.get("/{report_id}", status_code=status.HTTP_200_OK)
|
|
async def get_report(report_id: int, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await ReportService.get_report_by_id(report_id, db, token)
|
|
|
|
@router.get("/", status_code=status.HTTP_200_OK)
|
|
async def get_all_reports(token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await ReportService.get_all_reports(db, token)
|
|
|
|
@router.put("/{report_id}", status_code=status.HTTP_200_OK)
|
|
async def update_report(report_id: int, report_update: UserReportUpdate, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await ReportService.update_report(report_id, report_update, db, token)
|
|
|
|
@router.delete("/{report_id}", status_code=status.HTTP_200_OK)
|
|
async def delete_report(report_id: int, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
return await ReportService.delete_report(report_id, db, token) |