Compare commits
No commits in common. "update-1742551130" and "main" have entirely different histories.
update-174
...
main
@ -1,9 +1,8 @@
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from app.api.db.database import SessionLocal
|
from app.api.db.database import SessionLocal
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
yield db
|
yield db
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
from time import time
|
import time
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import Response
|
from starlette.responses import Response
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
class ActivityTrackerMiddleware(BaseHTTPMiddleware):
|
class ActivityTrackerMiddleware(BaseHTTPMiddleware):
|
||||||
async def dispatch(self, request: Request, call_next):
|
async def dispatch(self, request: Request, call_next):
|
||||||
start_time = time()
|
start_time = time.time()
|
||||||
response: Response = await call_next(request)
|
response = await call_next(request)
|
||||||
process_time = time() - start_time
|
process_time = time.time() - start_time
|
||||||
logger.info(f"Processed {request.method} {request.url} in {process_time:.4f} seconds")
|
logger.info(f'{request.method} {request.url} - Process Time: {process_time:.6f} seconds')
|
||||||
return response
|
return response
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from app.api.db.database import Base
|
from app.api.db.database import Base
|
||||||
|
|
||||||
class Comments(Base):
|
class Comments(Base):
|
||||||
__tablename__ = 'comments'
|
__tablename__ = 'comments'
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
post_id = Column(Integer, ForeignKey('posts.id'))
|
|
||||||
user_id = Column(Integer, ForeignKey('users.id'))
|
|
||||||
comment_text = Column(Text)
|
|
||||||
created_at = Column(Integer)
|
|
||||||
updated_at = Column(Integer)
|
|
||||||
|
|
||||||
post = relationship('Post', back_populates='comments')
|
|
||||||
user = relationship('User', back_populates='comments')
|
|
@ -1,13 +1,7 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from app.api.db.database import Base
|
from app.api.db.database import Base
|
||||||
|
|
||||||
class Posts(Base):
|
class Posts(Base):
|
||||||
__tablename__ = 'posts'
|
__tablename__ = 'posts'
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
title = Column(String)
|
|
||||||
content = Column(Text)
|
|
||||||
user_id = Column(Integer, ForeignKey('users.id'))
|
|
||||||
|
|
||||||
user = relationship('User', back_populates='posts')
|
|
@ -1,12 +1,7 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from app.api.db.database import Base
|
from app.api.db.database import Base
|
||||||
|
|
||||||
class Tags(Base):
|
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, unique=True)
|
|
||||||
description = Column(Text)
|
|
||||||
|
|
||||||
posts = relationship("Post", back_populates="tags", secondary="post_tags")
|
|
@ -1,14 +1,7 @@
|
|||||||
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
from sqlalchemy import Column, ForeignKey, Integer, String, Text
|
||||||
from sqlalchemy.orm import relationship
|
|
||||||
from app.api.db.database import Base
|
from app.api.db.database import Base
|
||||||
|
|
||||||
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)
|
||||||
email = Column(String, unique=True, index=True)
|
|
||||||
hashed_password = Column(String)
|
|
||||||
is_active = Column(Integer, default=1)
|
|
||||||
full_name = Column(String)
|
|
||||||
|
|
||||||
posts = relationship("Post", back_populates="author")
|
|
@ -1,3 +1,2 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
router = APIRouter()
|
||||||
router = APIRouter()
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class CommentsBase(BaseModel):
|
class CommentsBase(BaseModel):
|
||||||
body: str
|
pass
|
||||||
|
|
||||||
class Comments(CommentsBase):
|
class Comments(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
post_id: int
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class PostsBase(BaseModel):
|
class PostsBase(BaseModel):
|
||||||
title: str
|
pass
|
||||||
content: str
|
|
||||||
|
class Posts(BaseModel):
|
||||||
|
id: int
|
||||||
|
|
||||||
class Posts(PostsBase):
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class TagsBase(BaseModel):
|
class TagsBase(BaseModel):
|
||||||
name: str
|
pass
|
||||||
|
|
||||||
class Tags(TagsBase):
|
class Tags(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
name: str
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
email: str
|
pass
|
||||||
|
|
||||||
class User(UserBase):
|
class User(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
is_active: bool
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
10
main.py
10
main.py
@ -2,11 +2,9 @@ from fastapi import FastAPI
|
|||||||
from app.api.db.database import engine, Base
|
from app.api.db.database import engine, Base
|
||||||
from app.api.v1.routes import router
|
from app.api.v1.routes import router
|
||||||
from app.api.core.middleware.activity_tracker import ActivityTrackerMiddleware
|
from app.api.core.middleware.activity_tracker import ActivityTrackerMiddleware
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(ActivityTrackerMiddleware)
|
app.add_middleware(ActivityTrackerMiddleware)
|
||||||
app.include_router(router, prefix="/v1")
|
app.include_router(router, prefix='/v1')
|
||||||
|
@app.on_event('startup')
|
||||||
@app.on_event("startup")
|
def startup():
|
||||||
def startup_event():
|
Base.metadata.create_all(bind=engine)
|
||||||
Base.metadata.create_all(bind=engine)
|
|
||||||
|
@ -1,5 +1 @@
|
|||||||
fastapi
|
# No code generated
|
||||||
uvicorn
|
|
||||||
sqlalchemy
|
|
||||||
pydantic
|
|
||||||
loguru
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user