Compare commits
No commits in common. "update-1742751451" and "main" have entirely different histories.
update-174
...
main
@ -1,8 +1,8 @@
|
||||
import sqlalchemy.orm as _orm
|
||||
import app.api.db.database as _database
|
||||
from sqlalchemy.orm import Session
|
||||
from app.api.db.database import SessionLocal
|
||||
|
||||
def get_db() -> _orm.Session:
|
||||
db = _database.SessionLocal()
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
|
@ -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 to {request.url.path} took {process_time:.4f} seconds")
|
||||
logger.info(f"Request processed in {process_time:.4f} seconds")
|
||||
return response
|
@ -8,12 +8,14 @@ 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}, content="{self.content[:20]}...")'
|
||||
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}")'
|
@ -1,3 +1,6 @@
|
||||
# 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
|
||||
@ -6,11 +9,11 @@ class Tags(Base):
|
||||
__tablename__ = 'tags'
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
tag_name = Column(String(50), nullable=False, unique=True)
|
||||
name = Column(String, nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
# Additional columns and relationships as needed
|
||||
post_id = Column(Integer, ForeignKey('posts.id'), nullable=False)
|
||||
|
||||
posts = relationship('Post', back_populates='tags', secondary='post_tags')
|
||||
post = relationship('Post', back_populates='tags')
|
||||
|
||||
def __repr__(self):
|
||||
return f'Tag(id={self.id}, tag_name="{self.tag_name}")'
|
||||
return f'Tag(id={self.id}, name={self.name}, description={self.description})'
|
@ -1,4 +1,3 @@
|
||||
from typing import Optional
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.api.db.database import Base
|
||||
@ -10,13 +9,10 @@ class User(Base):
|
||||
username = Column(String, unique=True, nullable=False)
|
||||
email = Column(String, unique=True, nullable=False)
|
||||
password_hash = Column(String, nullable=False)
|
||||
bio = Column(Text, nullable=True)
|
||||
is_active = Column(Integer, default=1)
|
||||
is_admin = Column(Integer, default=0)
|
||||
bio = Column(Text, nullable=True)
|
||||
|
||||
# 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}')"
|
@ -1,14 +1,10 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class CommentsBase(BaseModel):
|
||||
body: str
|
||||
post_id: int
|
||||
user_id: int
|
||||
pass
|
||||
|
||||
class Comments(CommentsBase):
|
||||
class Comments(BaseModel):
|
||||
id: int
|
||||
post: dict = None
|
||||
user: dict = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
@ -1,10 +1,15 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
class PostsBase(BaseModel):
|
||||
pass
|
||||
title: str
|
||||
content: str
|
||||
published: bool = True
|
||||
rating: Optional[int] = None
|
||||
|
||||
class Posts(BaseModel):
|
||||
class Posts(PostsBase):
|
||||
id: int
|
||||
owner_id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user