- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가 - 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시) - 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리 - 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리 - pytest 66개 (테스트 전용 DB·Redis 사용) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from datetime import date, datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import or_, select
|
|
from sqlalchemy.dialects.postgresql import insert
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from common.database.model.models import Post
|
|
|
|
|
|
class FeedCRUD:
|
|
async def visible(self, s: AsyncSession, now: datetime) -> list[Post]:
|
|
stmt = select(Post).where(
|
|
Post.deleted.is_(False), Post.published_at <= now, or_(Post.end_at.is_(None), Post.end_at > now)
|
|
).order_by(Post.published_at.desc(), Post.position.desc())
|
|
return list((await s.scalars(stmt)).all())
|
|
|
|
async def has_day(self, s: AsyncSession, day: date) -> bool:
|
|
return await s.scalar(select(Post.post_id).where(Post.feed_date == day, Post.deleted.is_(False)).limit(1)) is not None
|
|
|
|
async def insert_day(self, s: AsyncSession, rows: list[dict]) -> None:
|
|
if rows:
|
|
await s.execute(insert(Post).values(rows).on_conflict_do_nothing())
|
|
|
|
async def get(self, s: AsyncSession, post_id: int) -> Optional[Post]:
|
|
post = await s.get(Post, post_id)
|
|
return post if post is not None and not post.deleted else None
|