Skip to content

Sprint 9 solution http api#7

Open
n20va wants to merge 10 commits intomainfrom
sprint_9-solution-http-api
Open

Sprint 9 solution http api#7
n20va wants to merge 10 commits intomainfrom
sprint_9-solution-http-api

Conversation

@n20va
Copy link
Copy Markdown
Owner

@n20va n20va commented Jul 29, 2025

No description provided.

public EpicsHandler(TaskManager manager) {
this.manager = manager;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

еще нужно добавить обработку POST запросов

Comment thread src/manager/EpicsHandler.java Outdated
sendNotFound(exchange);
}
} catch (Exception e) {
e.printStackTrace();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно сообщение об ошибке хотя бы в консоль вывести и закрыть HttpExchange через метод close()

sendNotFound(exchange);
}
} catch (Exception e) {
sendInternalError(exchange);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно сообщение об ошибке хотя бы в консоль вывести и закрыть HttpExchange через метод close()

sendNotFound(exchange);
}
} catch (Exception e) {
sendInternalError(exchange);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

и тут

Comment thread src/manager/SubtasksHandler.java Outdated

try {
if (subtask.getId() == 0) {
manager.addSubtask(subtask);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

после создания новой сущности, в ответе нужно сообщить присвоенное ей id, по-другому "на том конце провода" его никак не узнают

if (subtask.getId() == 0) {
manager.addSubtask(subtask);
} else {
manager.updateSubtask(subtask);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

при обновлении подзадачи еще нужно обработать ошибки с Cannot change epicId of subtask и полном отсутствии связанного эпика, а так же отсутствии самой подзадачи

Comment thread src/manager/SubtasksHandler.java Outdated
sendNotFound(exchange);
}
} catch (Exception e) {
e.printStackTrace();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно сообщение об ошибке хотя бы в консоль вывести и закрыть HttpExchange через метод close()

Comment thread src/manager/TasksHandler.java Outdated

try {
if (task.getId() == 0) {
manager.addTask(task);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

после создания новой сущности, в ответе нужно сообщить присвоенное ей id

Comment thread src/manager/TasksHandler.java Outdated
if (task.getId() == 0) {
manager.addTask(task);
} else {
manager.updateTask(task);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно еще обработать ошибку отсутствия обновляемой задачи

Comment thread src/manager/TasksHandler.java Outdated
sendNotFound(exchange);
}
} catch (Exception e) {
e.printStackTrace();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно сообщение об ошибке хотя бы в консоль вывести и закрыть HttpExchange через метод close()

Comment thread src/manager/EpicsHandler.java Outdated
String method = exchange.getRequestMethod();
String query = exchange.getRequestURI().getQuery();
switch (method) {
case "GET" -> sendText(exchange, gson.toJson(manager.getAllEpics()), 200);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а почему обработка GET-запроса стала такой? а где получение эпика по id и получение подзадач эпика?

Comment thread src/manager/SubtasksHandler.java Outdated
String method = exchange.getRequestMethod();
String query = exchange.getRequestURI().getQuery();
switch (method) {
case "GET" -> sendText(exchange, gson.toJson(manager.getAllSubtasks()), 200);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

аналогично

Comment thread src/manager/SubtasksHandler.java Outdated
try {
if (subtask.getId() == 0) {
if (manager.getEpicById(subtask.getEpicId()) == null) {
sendNotFound(exchange);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

пользователь пытается создать подзадачу, а в ответ приходит Not Found. Это сообщение будет вводить в заблуждение. Нужно добавить, что именно связанный эпик не найден

Comment thread src/manager/SubtasksHandler.java Outdated
sendNotFound(exchange);
return;
}
manager.addSubtask(subtask);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужна обработка ошибки на пересечения по времени

Comment thread src/manager/SubtasksHandler.java Outdated
Subtask old = manager.getSubtaskById(subtask.getId());
if (old == null) {
sendNotFound(exchange);
} else if (old.getEpicId() != subtask.getEpicId()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а причем здесь пересечение по времени? Здесь попытка сменить связь подзадача-эпик

Comment thread src/manager/TasksHandler.java Outdated
if ("GET".equalsIgnoreCase(method)) {
if (query == null) {
switch (method) {
case "GET" -> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

аналогично про получение задачи по id

Comment thread src/manager/TasksHandler.java Outdated
case "POST" -> {
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
Task task = gson.fromJson(body, Task.class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужна еще обработка ситуации с пересечениями

@irek-valiev
Copy link
Copy Markdown

Для обработки ситуаций с исключениями, нужно вызываемый метод обернуть в try/catch и ловить бросаемые исключения. В сообщении исключения будет нужный комментарий, который можно отдать в ответе

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