-
Notifications
You must be signed in to change notification settings - Fork 99
Simple Backend homework #166
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
base: main
Are you sure you want to change the base?
Conversation
| @@ -1,19 +1,44 @@ | |||
| from fastapi import FastAPI | |||
| from fastapi import FastAPI, HTTPException | |||
| from task_manager import TaskManager | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше использовать импорт с точкой from .task_manager import TaskManager
| from pydantic import BaseModel | ||
| from typing import Optional, List | ||
|
|
||
| load_dotenv('passwords.env') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хардкод названия файла с секретами это плохо, нужно переделать
| task_data = TaskModel(title=title, description=description, status=status) | ||
| tasks = self._tasks() | ||
| ids = [task['id'] for task in tasks] if tasks else [] | ||
| task_id = max(ids) + 1 if ids else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
один запрос может переписать другой, нужно подумать как избежать это
| if response.status_code == 200: | ||
| return response.json() | ||
| else: | ||
| raise Exception(f"HTTP Error {response.status_code}: {response.text}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше писать специфичные исключения
| try: | ||
| ai_solution = self.ai.generate_solution(f'{task_data.title}. {task_data.description}') | ||
| except Exception as e: | ||
| ai_solution = f'{e}. Не удалось сгенерировать решение' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше логировать и возвращать условный null или как-то иначе обрабатывать, чтобы не писать ошибки в базу
| 'X-Master-Key': self.api_key, | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| super().__init__(base_url, headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super должен быть раньше 10 строки
| task_data = TaskModel(title=title, description=description, status=status) | ||
| tasks = self._tasks() | ||
| ids = [task['id'] for task in tasks] if tasks else [] | ||
| task_id = max(ids) + 1 if ids else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не самый эффективный поиск максимального id
|
|
||
| load_dotenv('passwords.env') | ||
|
|
||
| class TaskModel(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
дублирование кода с main.py
| if task['id'] == task_id: | ||
| for k, v in valid_updates.items(): | ||
| if v is not None: | ||
| task[k] = v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужна валидация
| timeout=self.timeout, | ||
| **kwargs | ||
| ) | ||
| if response.status_code == 200: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше raise_for_status()
No description provided.