All checks were successful
hufs-notice-crawler-cicd / build_push_deploy (push) Successful in 8m35s
31 lines
737 B
Python
31 lines
737 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import Depends, FastAPI
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.config import get_settings
|
|
from app.db import Base, engine, get_db
|
|
from app.schemas import CrawlResponse
|
|
from app.service import CrawlService
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_: FastAPI):
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
|
|
settings = get_settings()
|
|
app = FastAPI(title=settings.app_name, lifespan=lifespan)
|
|
|
|
|
|
@app.get("/health")
|
|
def health() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
@app.post("/api/v1/crawl", response_model=CrawlResponse)
|
|
def crawl_notices(db: Session = Depends(get_db)) -> CrawlResponse:
|
|
service = CrawlService(db)
|
|
return service.crawl_new_posts()
|