Move history geo enrichment into history service

This commit is contained in:
2026-04-17 16:28:53 +02:00
parent 8c6950afc1
commit 487f252a4d
4 changed files with 109 additions and 50 deletions

View File

@@ -15,10 +15,7 @@ Routes
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
if TYPE_CHECKING:
import aiohttp
from typing import Literal
from fastapi import APIRouter, HTTPException, Query, Request
@@ -30,7 +27,7 @@ from app.dependencies import (
)
from app.models.ban import BanOrigin, TimeRange
from app.models.history import HistoryListResponse, IpDetailResponse
from app.services import geo_service, history_service
from app.services import history_service
router: APIRouter = APIRouter(prefix="/api/history", tags=["History"])
@@ -95,9 +92,6 @@ async def get_history(
and the total matching count.
"""
async def _enricher(addr: str) -> geo_service.GeoInfo | None:
return await geo_service.lookup(addr, http_session)
return await history_service.list_history(
socket_path,
range_=range,
@@ -107,7 +101,7 @@ async def get_history(
source=source,
page=page,
page_size=page_size,
geo_enricher=_enricher,
http_session=http_session,
db=db,
)
@@ -133,9 +127,6 @@ async def get_history_archive(
page_size: int = Query(default=_DEFAULT_PAGE_SIZE, ge=1, le=500, description="Items per page (max 500)."),
) -> HistoryListResponse:
async def _enricher(addr: str) -> geo_service.GeoInfo | None:
return await geo_service.lookup(addr, http_session)
return await history_service.list_history(
socket_path,
range_=range,
@@ -144,7 +135,7 @@ async def get_history_archive(
source="archive",
page=page,
page_size=page_size,
geo_enricher=_enricher,
http_session=http_session,
db=db,
)
@@ -180,13 +171,10 @@ async def get_ip_history(
HTTPException: 404 if the IP has no history in the database.
"""
async def _enricher(addr: str) -> geo_service.GeoInfo | None:
return await geo_service.lookup(addr, http_session)
detail: IpDetailResponse | None = await history_service.get_ip_detail(
socket_path,
ip,
geo_enricher=_enricher,
http_session=http_session,
)
if detail is None: