Compare commits
1 Commits
main
...
update-174
Author | SHA1 | Date | |
---|---|---|---|
![]() |
09af172fa5 |
@ -1,8 +1,8 @@
|
|||||||
from sqlalchemy.orm import Session
|
import sqlalchemy.orm as _orm
|
||||||
from app.api.db.database import SessionLocal
|
import app.api.db.database as _database
|
||||||
|
|
||||||
def get_db():
|
def get_db() -> _orm.Session:
|
||||||
db = SessionLocal()
|
db = _database.SessionLocal()
|
||||||
try:
|
try:
|
||||||
yield db
|
yield db
|
||||||
finally:
|
finally:
|
||||||
|
@ -9,5 +9,5 @@ class ActivityTrackerMiddleware(BaseHTTPMiddleware):
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
response: Response = await call_next(request)
|
response: Response = await call_next(request)
|
||||||
process_time = time.time() - start_time
|
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
|
return response
|
@ -8,14 +8,12 @@ class Comments(Base):
|
|||||||
__tablename__ = 'comments'
|
__tablename__ = 'comments'
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
content = Column(Text)
|
||||||
post_id = Column(Integer, ForeignKey('posts.id'))
|
post_id = Column(Integer, ForeignKey('posts.id'))
|
||||||
user_id = Column(Integer, ForeignKey('users.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')
|
post = relationship('Post', back_populates='comments')
|
||||||
user = relationship('User', back_populates='comments')
|
user = relationship('User', back_populates='comments')
|
||||||
|
|
||||||
def __repr__(self):
|
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]}...")'
|
@ -1,6 +1,3 @@
|
|||||||
# app/api/v1/models/tags.py
|
|
||||||
|
|
||||||
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
|
||||||
@ -9,11 +6,11 @@ class Tags(Base):
|
|||||||
__tablename__ = 'tags'
|
__tablename__ = 'tags'
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
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)
|
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):
|
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}")'
|
@ -1,3 +1,4 @@
|
|||||||
|
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
|
||||||
@ -9,10 +10,13 @@ class User(Base):
|
|||||||
username = Column(String, unique=True, nullable=False)
|
username = Column(String, unique=True, nullable=False)
|
||||||
email = Column(String, unique=True, nullable=False)
|
email = Column(String, unique=True, nullable=False)
|
||||||
password_hash = Column(String, nullable=False)
|
password_hash = Column(String, nullable=False)
|
||||||
is_active = Column(Integer, default=1)
|
|
||||||
bio = Column(Text, nullable=True)
|
bio = Column(Text, nullable=True)
|
||||||
|
is_active = Column(Integer, default=1)
|
||||||
|
is_admin = Column(Integer, default=0)
|
||||||
|
|
||||||
|
# Relationships
|
||||||
posts = relationship("Post", back_populates="author")
|
posts = relationship("Post", back_populates="author")
|
||||||
|
comments = relationship("Comment", back_populates="author")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"User(id={self.id}, username='{self.username}', email='{self.email}')"
|
return f"User(id={self.id}, username='{self.username}', email='{self.email}')"
|
@ -1,10 +1,14 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class CommentsBase(BaseModel):
|
class CommentsBase(BaseModel):
|
||||||
pass
|
body: str
|
||||||
|
post_id: int
|
||||||
|
user_id: int
|
||||||
|
|
||||||
class Comments(BaseModel):
|
class Comments(CommentsBase):
|
||||||
id: int
|
id: int
|
||||||
|
post: dict = None
|
||||||
|
user: dict = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
@ -1,15 +1,10 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
class PostsBase(BaseModel):
|
class PostsBase(BaseModel):
|
||||||
title: str
|
pass
|
||||||
content: str
|
|
||||||
published: bool = True
|
|
||||||
rating: Optional[int] = None
|
|
||||||
|
|
||||||
class Posts(PostsBase):
|
class Posts(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
owner_id: int
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user