feat: initial MVP - FastAPI backend + Vue3 frontend + docker-compose
- backend: FastAPI + SQLAlchemy 2.0(async) + asyncpg + Alembic - 7 API routes: auth/me/articles/sources/bookmarks/subscriptions/admin - models: User/Source/Article/Bookmark/Subscription/ApiToken - services: RSS fetcher (feedparser) + Tencent TMT translator with quota + cache + local NLLB fallback - workers: APScheduler + asyncio pipeline (fetch -> dedupe -> insert -> translate) - seed scripts: create_user, seed_sources (5 RSS: Reuters/BBC/Al Jazeera/NHK/DW) - frontend: Vue 3 + Vite + Naive UI + Pinia + vue-router - pages: Login, Feed (24h), ArticleDetail, Sources, Bookmarks, AdminSources - deploy: docker-compose (postgres/redis/api/worker/frontend/caddy) - docs: README, DEPLOY, architecture, acceptance
This commit is contained in:
48
backend/app/models/subscription.py
Normal file
48
backend/app/models/subscription.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""关键词订阅(命中即通知)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
DateTime,
|
||||
Enum,
|
||||
ForeignKey,
|
||||
String,
|
||||
Text,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class SubscriptionMatch(str, enum.Enum):
|
||||
ANY = "any" # 标题或正文
|
||||
TITLE = "title"
|
||||
BODY = "body"
|
||||
|
||||
|
||||
class Subscription(Base):
|
||||
__tablename__ = "subscriptions"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
keyword: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
# 简单关键词,匹配走 ILIKE '%kw%';后续可加 regex/lucene
|
||||
match_in: Mapped[SubscriptionMatch] = mapped_column(
|
||||
Enum(SubscriptionMatch, name="subscription_match"),
|
||||
default=SubscriptionMatch.ANY,
|
||||
nullable=False,
|
||||
)
|
||||
channel: Mapped[str] = mapped_column(String(32), default="telegram", nullable=False)
|
||||
# telegram / email / web
|
||||
target: Mapped[str | None] = mapped_column(Text) # chat_id / email
|
||||
enabled: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||
last_hit_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||||
)
|
||||
Reference in New Issue
Block a user