From 2028dd94193458ac935bf2ea443141bd2511f296 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 1 Aug 2023 12:15:23 +0300 Subject: [PATCH 1/3] Fixed get_current_user db argument setting --- back/main.py | 2 +- back/utils.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/back/main.py b/back/main.py index c9f994d..772fc43 100644 --- a/back/main.py +++ b/back/main.py @@ -172,7 +172,7 @@ async def login_for_access_token( # async def read_users_me(current_user: Annotated[schemas.User, Depends(get_current_active_user)]): # return current_user #schemas.User(id=current_user.id, email=current_user.email, name=current_user.name, surname=current_user.surname, disabled=current_user.disabled, items=current_user.items) @app.get("/api/users/me/", response_model=schemas.User) # -async def read_users_me(current_user: Annotated[schemas.User, Depends(get_current_active_user)]) -> Any: +async def read_users_me(current_user: Annotated[schemas.User, Depends(get_current_active_user)]): return current_user #schemas.User(id=current_user.id, email=current_user.email, name=current_user.name, surname=current_user.surname, disabled=current_user.disabled, items=current_user.items) diff --git a/back/utils.py b/back/utils.py index 4b70789..64d378e 100644 --- a/back/utils.py +++ b/back/utils.py @@ -12,6 +12,7 @@ from sqlalchemy import select # from .db import Session, database from . import models, schemas +from .db import SessionLocal @@ -22,6 +23,14 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() + + def verify_password(plain_password, hashed_password): return pwd_context.verify(plain_password, hashed_password) @@ -57,7 +66,7 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None return encoded_jwt -async def get_current_user(db: Session, token: Annotated[str, Depends(oauth2_scheme)]): +async def get_current_user(db: Annotated[Session, Depends(get_db)], token: Annotated[str, Depends(oauth2_scheme)]): credentials_exception = HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Could not validate credentials", @@ -88,10 +97,3 @@ async def get_current_active_user( # def get_db(request: Request): # return request.state.db - -# def get_db(): -# db = SessionLocal() -# try: -# yield db -# finally: -# db.close() \ No newline at end of file From a41c684a74a77ac2815cb4c882ad46d84ff2be72 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 1 Aug 2023 13:34:55 +0300 Subject: [PATCH 2/3] Added schema for GET /api/poetry endpoint --- back/schemas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/back/schemas.py b/back/schemas.py index afce18a..0569960 100644 --- a/back/schemas.py +++ b/back/schemas.py @@ -50,5 +50,8 @@ class User(BaseModel): class UserInDB(User): hashed_password: str - +class Poem(BaseModel): + title: str + text: str + author: str From 3e2555084388b8d23113ce4698714b993895142b Mon Sep 17 00:00:00 2001 From: dm1sh Date: Tue, 1 Aug 2023 15:57:43 +0300 Subject: [PATCH 3/3] Added typings for /api/trashbox response and /api/announcement/dispose request --- back/main.py | 4 ++-- back/schemas.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/back/main.py b/back/main.py index 772fc43..b316acf 100644 --- a/back/main.py +++ b/back/main.py @@ -7,7 +7,7 @@ from fastapi.templating import Jinja2Templates from fastapi.requests import Request from pydantic import json -from typing import Any +from typing import List from starlette.staticfiles import StaticFiles import requests @@ -184,7 +184,7 @@ async def read_users_me(current_user: Annotated[schemas.User, Depends(get_curren -@app.get("/api/trashbox") +@app.get("/api/trashbox", response_model=List[schemas.TrashboxResponse]) def get_trashboxes(lat:float, lng:float):#крутая функция для работы с api BASE_URL='https://geointelect2.gate.petersburg.ru'#адрес сайта и мой токин my_token='eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhU1RaZm42bHpTdURYcUttRkg1SzN5UDFhT0FxUkhTNm9OendMUExaTXhFIn0.eyJleHAiOjE3ODM3ODk4NjgsImlhdCI6MTY4OTA5NTQ2OCwianRpIjoiNDUzNjQzZTgtYTkyMi00NTI4LWIzYmMtYWJiYTNmYjkyNTkxIiwiaXNzIjoiaHR0cHM6Ly9rYy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AeUfSpum9s5ZfELequfpLoZMXn6CaYZhePaoK-CxeU3KPBPTPOVPKZZ19s7QY10VdkxLULknqf9opdvLs4j8NMimtwoIiHNBFlgQz10Cr7bhDKWugfvSRsICouniIiBJo76wrj5T92s-ztf1FShJuqnQcKE_QLd2A' diff --git a/back/schemas.py b/back/schemas.py index 0569960..09131de 100644 --- a/back/schemas.py +++ b/back/schemas.py @@ -1,6 +1,7 @@ from pydantic import BaseModel from typing import Annotated, Union from datetime import date +from typing import List class Book(BaseModel): id: int @@ -55,3 +56,18 @@ class Poem(BaseModel): text: str author: str +class TrashboxBase(BaseModel): + Name: str + Lat: float + Lng: float + +class TrashboxResponse(TrashboxBase): + Address: str + Categories: List[str] + +class TrashboxRequest(TrashboxBase): + Category: str + +class DisposeRequest(BaseModel): + ann_id: int + trashbox: TrashboxRequest