Skip to content

Conversation

@Vladimir-koven
Copy link

No description provided.

@@ -1,19 +1,44 @@
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from task_manager import TaskManager

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

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

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

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}. Не удалось сгенерировать решение'

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)

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

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

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

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:

Choose a reason for hiding this comment

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

лучше raise_for_status()

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