Update generated backend for blog_app with entities: posts, comments, tags, user

This commit is contained in:
Backend IM Bot 2025-03-22 10:32:40 +01:00
parent e9eb6c3dd5
commit 577e157cd3
15 changed files with 26 additions and 22 deletions

Binary file not shown.

View File

@ -1,3 +1,4 @@
# app/api/core/dependencies/dependencies.py
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from app.api.db.database import SessionLocal from app.api.db.database import SessionLocal

View File

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

View File

@ -1,5 +1,3 @@
# app/api/v1/models/comments.py
from sqlalchemy import Column, ForeignKey, Integer, String, Text from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from app.api.db.database import Base from app.api.db.database import Base
@ -12,7 +10,7 @@ class Comments(Base):
user_id = Column(Integer, ForeignKey('users.id')) user_id = Column(Integer, ForeignKey('users.id'))
comment_text = Column(Text) comment_text = Column(Text)
created_at = Column(String) created_at = Column(String)
updated_at = Column(String, nullable=True) updated_at = Column(String)
post = relationship('Post', back_populates='comments') post = relationship('Post', back_populates='comments')
user = relationship('User', back_populates='comments') user = relationship('User', back_populates='comments')

View File

@ -1,4 +1,3 @@
from typing import Optional
from sqlalchemy import Column, ForeignKey, Integer, String, Text from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from app.api.db.database import Base from app.api.db.database import Base
@ -10,8 +9,10 @@ class Posts(Base):
title = Column(String, nullable=False) title = Column(String, nullable=False)
content = Column(Text, nullable=False) content = Column(Text, nullable=False)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False) user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
category_id = Column(Integer, ForeignKey('categories.id'), nullable=False)
author = relationship('Users', back_populates='posts') user = relationship('User', back_populates='posts')
category = relationship('Category', back_populates='posts')
def __repr__(self): def __repr__(self):
return f'Post(id={self.id}, title={self.title}, content={self.content[:20]}...)' return f'<Post {self.title}>'

View File

@ -9,7 +9,8 @@ class Tags(Base):
name = Column(String, nullable=False, unique=True) name = Column(String, nullable=False, unique=True)
description = Column(Text, nullable=True) description = Column(Text, nullable=True)
posts = relationship("Post", back_populates="tags", secondary="post_tags") # Relationships
posts = relationship('Post', secondary='post_tags', back_populates='tags')
def __repr__(self): def __repr__(self):
return f"Tag(id={self.id}, name='{self.name}', description='{self.description}')" return f'Tag(id={self.id}, name="{self.name}")'

View File

@ -2,20 +2,22 @@ from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from app.api.db.database import Base from app.api.db.database import Base
# Optional imports
# from typing import Optional
class User(Base): class User(Base):
__tablename__ = 'user' __tablename__ = 'user'
id = Column(Integer, primary_key=True, index=True) id = Column(Integer, primary_key=True, index=True)
# Add relevant foreign keys and entity-specific fields here # Add relevant columns based on project context
# For example: # email = Column(String, unique=True, nullable=False)
# email = Column(String, unique=True, index=True, nullable=False) # password = Column(String, nullable=False)
# hashed_password = Column(String, nullable=False)
# full_name = Column(String, nullable=False) # full_name = Column(String, nullable=False)
# bio = Column(Text, nullable=True) # bio = Column(Text, nullable=True)
# Relationships # Add relationships if applicable
# For example:
# posts = relationship("Post", back_populates="author") # posts = relationship("Post", back_populates="author")
def __repr__(self): # Optional __repr__ method
return f"User(id={self.id})" # def __repr__(self):
# return f"User(id={self.id}, email='{self.email}', full_name='{self.full_name}')"

View File

@ -1,14 +1,15 @@
from pydantic import BaseModel from pydantic import BaseModel
from typing import Optional
class CommentsBase(BaseModel): class CommentsBase(BaseModel):
comment_text: str body: str
post_id: int post_id: int
user_id: int user_id: int
class Comments(CommentsBase): class Comments(CommentsBase):
id: int id: int
post: dict post: Optional[dict] = None
user: dict user: Optional[dict] = None
class Config: class Config:
orm_mode = True orm_mode = True

View File

@ -9,7 +9,7 @@ class PostsBase(BaseModel):
class Posts(PostsBase): class Posts(PostsBase):
id: int id: int
owner_id: int user_id: int
class Config: class Config:
orm_mode = True orm_mode = True

View File

@ -6,7 +6,7 @@ class TagsBase(BaseModel):
class Tags(TagsBase): class Tags(TagsBase):
id: int id: int
name: str posts: Optional[list]
class Config: class Config:
orm_mode = True orm_mode = True