feat: Implement backend core functionality for news-engine-console
Phase 1 Backend Implementation: - ✅ MongoDB data models (Keyword, Pipeline, User, Application) - ✅ Pydantic schemas for all models with validation - ✅ KeywordService: Full CRUD, filtering, pagination, stats, toggle status - ✅ PipelineService: Full CRUD, start/stop/restart, logs, config management - ✅ Keywords API: 8 endpoints with complete functionality - ✅ Pipelines API: 11 endpoints with complete functionality - ✅ Updated TODO.md to reflect completion Key Features: - Async MongoDB operations with Motor - Comprehensive filtering and pagination support - Pipeline logging system - Statistics tracking for keywords and pipelines - Proper error handling with HTTP status codes - Type-safe request/response models Files Added: - models/: 4 data models with PyObjectId support - schemas/: 4 schema modules with Create/Update/Response patterns - services/: KeywordService (234 lines) + PipelineService (332 lines) Files Modified: - api/keywords.py: 40 → 212 lines (complete implementation) - api/pipelines.py: 25 → 300 lines (complete implementation) - TODO.md: Updated checklist with completed items Next Steps: - UserService with authentication - ApplicationService for OAuth2 - MonitoringService - Redis integration - Frontend implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
56
services/news-engine-console/backend/app/schemas/keyword.py
Normal file
56
services/news-engine-console/backend/app/schemas/keyword.py
Normal file
@ -0,0 +1,56 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, Any, List
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class KeywordBase(BaseModel):
|
||||
"""Base keyword schema"""
|
||||
keyword: str = Field(..., min_length=1, max_length=200)
|
||||
category: str = Field(..., description="Category: people, topics, companies")
|
||||
pipeline_type: str = Field(default="all", description="Pipeline type: rss, translation, all")
|
||||
priority: int = Field(default=5, ge=1, le=10)
|
||||
metadata: Dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class KeywordCreate(KeywordBase):
|
||||
"""Schema for creating a new keyword"""
|
||||
pass
|
||||
|
||||
|
||||
class KeywordUpdate(BaseModel):
|
||||
"""Schema for updating a keyword (all fields optional)"""
|
||||
keyword: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
category: Optional[str] = None
|
||||
status: Optional[str] = Field(None, description="Status: active, inactive")
|
||||
pipeline_type: Optional[str] = None
|
||||
priority: Optional[int] = Field(None, ge=1, le=10)
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class KeywordResponse(KeywordBase):
|
||||
"""Schema for keyword response"""
|
||||
id: str = Field(..., alias="_id")
|
||||
status: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
created_by: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
populate_by_name = True
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class KeywordStats(BaseModel):
|
||||
"""Keyword statistics"""
|
||||
total_articles: int = 0
|
||||
articles_last_24h: int = 0
|
||||
articles_last_7d: int = 0
|
||||
last_article_date: Optional[datetime] = None
|
||||
|
||||
|
||||
class KeywordListResponse(BaseModel):
|
||||
"""Schema for keyword list response"""
|
||||
keywords: List[KeywordResponse]
|
||||
total: int
|
||||
page: int = 1
|
||||
page_size: int = 50
|
||||
Reference in New Issue
Block a user