Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed May 20, 2024
1 parent cf14cba commit 63f9bc2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ docker-build-detached: ## Startup docker with build switch
docker-compose up --build -d

docker-restart:
docker-compose down
docker-compose up --build -d
docker compose down
docker compose up --build -d

docker-test: docker-restart
pytest -s

setup: test-setup requirements## setup requirements

Expand Down
8 changes: 6 additions & 2 deletions src/api/v2/report.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import logging

from fastapi import APIRouter, status
from fastapi.exceptions import HTTPException

from src.app.repositories.report import Report
from src.app.views.input.report import Detection
from src.app.views.response.ok import Ok

logger = logging.getLogger(__name__)
router = APIRouter(tags=["Report"])


@router.post("/report", status_code=status.HTTP_201_CREATED, response_model=Ok)
async def post_reports(detection: list[Detection]):
async def post_reports(detections: list[Detection]):
report = Report()
data = await report.parse_data(detection)
data = await report.parse_data(detections)
if not data:
logger.debug(detections[0])
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail="invalid data")
await report.send_to_kafka(data)
return Ok()
4 changes: 2 additions & 2 deletions src/app/repositories/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def _filter_valid_time(self, data: list[Detection]) -> list[Detection]:
current_time = int(time.time())
min_ts = current_time - 25200
max_ts = current_time + 3600
return [d for d in data if min_ts < d.ts < max_ts]
return [d for d in data if min_ts > d.ts > max_ts]

def _check_unique_reporter(self, data: list[Detection]) -> list[Detection] | None:
return None if len(set(d.reporter for d in data)) > 1 else data

async def parse_data(self, data: list[dict]) -> list[Detection] | None:
async def parse_data(self, data: list[Detection]) -> list[Detection] | None:
"""
Parse and validate a list of detection data.
"""
Expand Down
Empty file added tests/test_report.py
Empty file.

0 comments on commit 63f9bc2

Please sign in to comment.