Automated Action 606cda0912 Implement Blogging API with FastAPI and SQLite
- Create project structure with app organization
- Set up FastAPI application with CORS and health endpoint
- Implement database models with SQLAlchemy (User, Post, Comment)
- Set up Alembic for database migrations
- Implement authentication with JWT tokens
- Create CRUD operations for all models
- Implement REST API endpoints for users, posts, and comments
- Add comprehensive documentation in README.md
2025-06-02 22:34:58 +00:00

18 lines
789 B
Python

from datetime import datetime
from sqlalchemy import Column, String, Text, DateTime, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from app.db.base_class import Base
class Post(Base):
id = Column(String, primary_key=True, index=True)
title = Column(String, index=True, nullable=False)
content = Column(Text, nullable=False)
is_published = Column(Boolean, default=True)
author_id = Column(String, ForeignKey("user.id"), nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
author = relationship("User", back_populates="posts")
comments = relationship("Comment", back_populates="post", cascade="all, delete-orphan")