Compare commits

...

1 Commits

Author SHA1 Message Date
Backend IM Bot
09af172fa5 Update generated backend for blog_app with entities: posts, comments, tags, user 2025-03-23 18:37:27 +01:00
7 changed files with 26 additions and 28 deletions

View File

@ -1,8 +1,8 @@
from sqlalchemy.orm import Session
from app.api.db.database import SessionLocal
import sqlalchemy.orm as _orm
import app.api.db.database as _database
def get_db():
db = SessionLocal()
def get_db() -> _orm.Session:
db = _database.SessionLocal()
try:
yield db
finally:

View File

@ -9,5 +9,5 @@ class ActivityTrackerMiddleware(BaseHTTPMiddleware):
start_time = time.time()
response: Response = await call_next(request)
process_time = time.time() - start_time
logger.info(f"Request processed in {process_time:.4f} seconds")
logger.info(f"Request to {request.url.path} took {process_time:.4f} seconds")
return response

View File

@ -8,14 +8,12 @@ class Comments(Base):
__tablename__ = 'comments'
id = Column(Integer, primary_key=True, index=True)
content = Column(Text)
post_id = Column(Integer, ForeignKey('posts.id'))
user_id = Column(Integer, ForeignKey('users.id'))
content = Column(Text)
created_at = Column(String)
updated_at = Column(String, nullable=True)
post = relationship('Post', back_populates='comments')
user = relationship('User', back_populates='comments')
def __repr__(self):
return f'Comment(id={self.id}, post_id={self.post_id}, user_id={self.user_id}, content="{self.content[:20]}...", created_at="{self.created_at}", updated_at="{self.updated_at}")'
return f'Comment(id={self.id}, content="{self.content[:20]}...")'

View File

@ -1,6 +1,3 @@
# app/api/v1/models/tags.py
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from app.api.db.database import Base
@ -9,11 +6,11 @@ class Tags(Base):
__tablename__ = 'tags'
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
tag_name = Column(String(50), nullable=False, unique=True)
description = Column(Text, nullable=True)
post_id = Column(Integer, ForeignKey('posts.id'), nullable=False)
# Additional columns and relationships as needed
post = relationship('Post', back_populates='tags')
posts = relationship('Post', back_populates='tags', secondary='post_tags')
def __repr__(self):
return f'Tag(id={self.id}, name={self.name}, description={self.description})'
return f'Tag(id={self.id}, tag_name="{self.tag_name}")'

View File

@ -1,3 +1,4 @@
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from app.api.db.database import Base
@ -9,10 +10,13 @@ class User(Base):
username = Column(String, unique=True, nullable=False)
email = Column(String, unique=True, nullable=False)
password_hash = Column(String, nullable=False)
is_active = Column(Integer, default=1)
bio = Column(Text, nullable=True)
is_active = Column(Integer, default=1)
is_admin = Column(Integer, default=0)
# Relationships
posts = relationship("Post", back_populates="author")
comments = relationship("Comment", back_populates="author")
def __repr__(self):
return f"User(id={self.id}, username='{self.username}', email='{self.email}')"

View File

@ -1,10 +1,14 @@
from pydantic import BaseModel
class CommentsBase(BaseModel):
pass
body: str
post_id: int
user_id: int
class Comments(BaseModel):
class Comments(CommentsBase):
id: int
post: dict = None
user: dict = None
class Config:
orm_mode = True
orm_mode = True

View File

@ -1,15 +1,10 @@
from pydantic import BaseModel
from typing import Optional
class PostsBase(BaseModel):
title: str
content: str
published: bool = True
rating: Optional[int] = None
pass
class Posts(PostsBase):
class Posts(BaseModel):
id: int
owner_id: int
class Config:
orm_mode = True
orm_mode = True