Skip to content

Lab_3-4-5 - #3

Open
tremenbez wants to merge 8 commits into
masterfrom
develop
Open

tremenbez wants to merge 8 commits into
masterfrom
develop

Conversation

@tremenbez

@tremenbez tremenbez commented Apr 24, 2025

Copy link
Copy Markdown
Owner

Лабораторная 3
Поднимаю контейнер через docker compose up.
Перейдя на http://localhost:8000/docs# все запросы проходят верно.

Konstantin added 2 commits April 24, 2025 18:44
@tremenbez tremenbez changed the title Lab3 Lab3-4 Apr 26, 2025
@tremenbez

Copy link
Copy Markdown
Owner Author

Добавил 4-ю лабораторную

@tremenbez

Copy link
Copy Markdown
Owner Author

Добавил 5-ю лабораторную

@tremenbez tremenbez changed the title Lab3-4 Lab_3-4-5 May 8, 2025
@tremenbez

Copy link
Copy Markdown
Owner Author

test


@app.get("/students/", response_model=List[StudentResponse])
async def get_students(session: Session = Depends(get_session)):
result = await session.execute(select(Student))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Лучше стараться разделять слои в приложения в соотвествии с чистой архитектурой. Сейчас работа с бд и апи находятся в одном месте, не самая лучшая практика

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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Для http статусов лучше использовать библиотеку HTTPStatus

- "8000:8000"
environment:
- DB_HOST=db
- DB_PORT=5432

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PORT и HOST лучше тоже брать из .env переменных

Comment thread Lab4/jwt/app/main.py
class RefreshTokenRequest(BaseModel):
refresh_token: str

class UpdateUserRequest(BaseModel):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Вынеси pydantic схемы в отдельный файл, не очень хорошо все в один файл сваливать

Comment thread Lab4/jwt/app/main.py
@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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

В целом надо поработать над стурктурой проект и разделить файл main.py на несколько файлов

Comment thread Lab4/jwt/app/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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Для чистоты кода лучше придерживаться чистой архитектуры. Попробуй использовать паттерн Repository для работы с БД


COPY . .

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Лучше вычитывать HOST и PORT из .env переменных, чтобы все из одного места брать

Comment thread Lab5/admin_panel/main.py
@@ -0,0 +1,64 @@
from fastapi import FastAPI, HTTPException

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Нужно разгрузить файл

Comment thread Lab5/pps/main.py
@@ -0,0 +1,76 @@
from fastapi import FastAPI, HTTPException, Depends

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Разгрузи файл, раздели по отдельным файлам

Comment thread Lab5/etl/etl.py
@@ -0,0 +1,100 @@
import os

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Нужно разделить по отдельным файлам.

В идеале, если писать чистый код, можно сделать абстрактные классы Extractor, Loader, Transformer. От них унаследовать PGExtractor, ESLoader. ETL процесс работает с абстрактными классами Extractor, Loader, Transformer, не зная про детали реализации. Но можешь просто разделить на отдельные файл, так делать не обязательно)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants