Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E-64] Update the current state of the web application #104

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ __pycache__/
.vscode
**/__pycache__
**/test*
migration
alembic.ini
test_folder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А для чего нужна эта директория?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_folder там просто файлы для проверки работы некоторых функций или посылок запросов


# Distribution / packaging
.Python
Expand Down Expand Up @@ -36,6 +39,7 @@ MANIFEST
*.manifest
*.spec


# Installer logs
pip-log.txt
pip-delete-this-directory.txt
Expand Down Expand Up @@ -170,3 +174,6 @@ cython_debug/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
/src/edulytica_api/front_end/node_modules/
/src/edulytica_api/models/init_models.py
task.txt
116 changes: 0 additions & 116 deletions alembic.ini

This file was deleted.

1 change: 0 additions & 1 deletion alembic/README

This file was deleted.

78 changes: 0 additions & 78 deletions alembic/env.py

This file was deleted.

26 changes: 0 additions & 26 deletions alembic/script.py.mako

This file was deleted.

16 changes: 16 additions & 0 deletions alembic_helper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
alembic init -t async migration
Прописываем в терминале эту команду и следуем инструкции:
1) В alembic.ini меняем значение sqlalchemy.url на
sqlalchemy.url = postgresql+asyncpg://edulytica:superstrongpassword@localhost:5432/edulytica
2) В migration/env.py:
1) from src.edulytica_api.models.init_models import Base
2) Меняет target_metadate = Base.metadata
В консоли пишем команды:
alembic revision --autogenerate -m "Initial tables without relationships"
alembic upgrade heads

Заходим migration/env.py и меняем
from src.models.models import Base
В консоли пишем команды:
alembic revision --autogenerate -m "Update tables"
alembic upgrade heads
13 changes: 13 additions & 0 deletions docker-compose-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.9"

services:
edulytica_db:
container_name: "EdulyticaDatabase"
image: postgres:16-alpine
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5443:5432"
Binary file modified requirements.txt
Binary file not shown.
6 changes: 1 addition & 5 deletions src/edulytica_api/app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.edulytica_api.database import engine
from src.edulytica_api.models import models
from src.edulytica_api.routers.llm_services import *
from src.edulytica_api.routers.auth import *
from src.edulytica_api.routers.norm_services import normocontrol_router

load_dotenv()
models.Base.metadata.create_all(bind=engine)

app = FastAPI()
origins = [
"http://localhost",
Expand Down
11 changes: 5 additions & 6 deletions src/edulytica_api/auth/auth_bearer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from fastapi import HTTPException, Depends
from jose import JWTError, jwt
from passlib.context import CryptContext
from sqlalchemy.orm import Session
from sqlalchemy.ext.asyncio import AsyncSession
from starlette import status

from src.edulytica_api.crud.user_crud import UserCrud
from src.edulytica_api.database import get_session
from src.edulytica_api.settings import ALGORITHM, JWT_SECRET_KEY, JWT_REFRESH_SECRET_KEY
Expand All @@ -32,23 +31,23 @@ def __init__(self, token_type, secret_key):
self.token_type = token_type
self.secret_key = secret_key

def __call__(self, token: Annotated[str, Depends(oauth2_scheme)], session: Session = Depends(get_session)):
async def __call__(self, token: Annotated[str, Depends(oauth2_scheme)], session: AsyncSession = Depends(get_session)):
try:
payload = jwt.decode(token, self.secret_key, algorithms=[ALGORITHM])
if self.token_type_validate(payload, self.token_type):
user = self.user_check(payload=payload, session=session)
user = await self.user_check(payload=payload, session=session)
return {"user": user,
"payload": payload,
"token": token}
except JWTError as e:
raise credentials_exception

@staticmethod
def user_check(payload, session: Session):
async def user_check(payload, session: AsyncSession):
user_id: str = payload.get("sub")
if user_id is None:
raise credentials_exception
user = UserCrud.get_by_id(session=session, record_id=user_id)
user = await UserCrud.get_by_id(session=session, record_id=user_id)
if user is None:
raise credentials_exception
if user.disabled:
Expand Down
Loading
Loading