Conversation
|
Добавил 4-ю лабораторную |
|
Добавил 5-ю лабораторную |
|
test |
|
|
||
| @app.get("/students/", response_model=List[StudentResponse]) | ||
| async def get_students(session: Session = Depends(get_session)): | ||
| result = await session.execute(select(Student)) |
There was a problem hiding this comment.
Лучше стараться разделять слои в приложения в соотвествии с чистой архитектурой. Сейчас работа с бд и апи находятся в одном месте, не самая лучшая практика
| group_a = await session.get(Group, group_a_id) | ||
| group_b = await session.get(Group, group_b_id) | ||
| if not student or not group_a or not group_b: | ||
| raise HTTPException(status_code=404, detail="Student or Group not found") |
There was a problem hiding this comment.
Для http статусов лучше использовать библиотеку HTTPStatus
| - "8000:8000" | ||
| environment: | ||
| - DB_HOST=db | ||
| - DB_PORT=5432 |
There was a problem hiding this comment.
PORT и HOST лучше тоже брать из .env переменных
| class RefreshTokenRequest(BaseModel): | ||
| refresh_token: str | ||
|
|
||
| class UpdateUserRequest(BaseModel): |
There was a problem hiding this comment.
Вынеси pydantic схемы в отдельный файл, не очень хорошо все в один файл сваливать
| @app.post("/logout") | ||
| def logout(current_user: User = Depends(get_current_user)): | ||
| redis_client.delete(current_user.email) | ||
| return {"message": "Logged out successfully"} No newline at end of file |
There was a problem hiding this comment.
В целом надо поработать над стурктурой проект и разделить файл main.py на несколько файлов
| # Просмотр истории входов | ||
| @app.get("/user/history") | ||
| def get_login_history(current_user: User = Depends(get_current_user), db: Session = Depends(get_db)): | ||
| history = db.query(LoginHistory).filter(LoginHistory.user_id == current_user.id).all() |
There was a problem hiding this comment.
Для чистоты кода лучше придерживаться чистой архитектуры. Попробуй использовать паттерн Repository для работы с БД
|
|
||
| COPY . . | ||
|
|
||
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] No newline at end of file |
There was a problem hiding this comment.
Лучше вычитывать HOST и PORT из .env переменных, чтобы все из одного места брать
| @@ -0,0 +1,64 @@ | |||
| from fastapi import FastAPI, HTTPException | |||
| @@ -0,0 +1,76 @@ | |||
| from fastapi import FastAPI, HTTPException, Depends | |||
There was a problem hiding this comment.
Разгрузи файл, раздели по отдельным файлам
| @@ -0,0 +1,100 @@ | |||
| import os | |||
There was a problem hiding this comment.
Нужно разделить по отдельным файлам.
В идеале, если писать чистый код, можно сделать абстрактные классы Extractor, Loader, Transformer. От них унаследовать PGExtractor, ESLoader. ETL процесс работает с абстрактными классами Extractor, Loader, Transformer, не зная про детали реализации. Но можешь просто разделить на отдельные файл, так делать не обязательно)
Лабораторная 3
Поднимаю контейнер через docker compose up.
Перейдя на http://localhost:8000/docs# все запросы проходят верно.