Skip to content

Feature/delete item#47

Merged
Rus-tem merged 8 commits into
mainfrom
feature/delete_Item
Jun 13, 2026
Merged

Feature/delete item#47
Rus-tem merged 8 commits into
mainfrom
feature/delete_Item

Conversation

@Rus-tem

@Rus-tem Rus-tem commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Добавлена функциональность удаление товара

@Rus-tem Rus-tem requested a review from Andrey-Potokin June 10, 2026 15:46

@ii-reviewer ii-reviewer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно пофиксить конфликты

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

В одном из прошлых ПР был коммент от Андрея, что "не приветствуется импорт со *. Мол может подгрузиться много лишнего". Не блокер, конечно, но надо нам разобраться в команде, как лучше делать, чтобы было в едином стиле. То же самое в классе ItemServiceImplTest. А так, по-моему, всё супер

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Сейчас есть правило в конфигурации checkstyle для этого, так что это нужно исправить для прохождения пайплайна. Перед пушем можно локально выполнить в терминале make checkstyle и подстветятся рекомендации для исправления

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Исправлено

@ResponseStatus(HttpStatus.NO_CONTENT)
@PreAuthorize("hasRole('ADMIN')")
public void deleteItem(@PathVariable Long itemId) {
itemService.deleteItem(itemId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

В ТЗ метод называется "softDelete". Как понимаю подразумевает не удаление, а скрытие товара

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Исправлено

PageResponse<ItemResponse> getItems(String sort, String order, String category, String search, int page, int size);

/**
* Удаляет товар по указанному идентификатору.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Может заменить на "Скрывает" или "Скрывает из выдачи"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Исправлено

}

return item;
public void deleteItem(Long itemId) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

По ТЗ: "ItemService.softDelete(id) — ставит is_active = false". Получается мы не удаляем товар, а скрываем его из выдачи. То есть товар у нас в системе остается и его Stock тоже. Поправь меня, если не прав.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Там двояко получается, думаю админ имеет право удалять товар.
В общем логику переделал, сейчас находит товар и деактивирует его.


return item;
public void deleteItem(Long itemId) {
itemRepository.findById(itemId).orElseThrow(() -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

И соответственно при повторном удалении (проверке на isActive = false) пробрасываем EntityNotFoundException

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

исправлено


/**
* Удаляет товар по указанному идентификатору.
* Перед удалением товара удаляются связанные записи об остатках на складе.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ну и если мы оставляем существовать остатки, то строка не актуальна

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Исправлено

@Andrey-Potokin Andrey-Potokin linked an issue Jun 11, 2026 that may be closed by this pull request
4 tasks
public void deleteItem(Long itemId) {
itemRepository.findById(itemId).orElseThrow(() -> {
log.warn("Item с id={} не найден", itemId);
return new EntityNotFoundException("Item с таким id = " + itemId + " не найден");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Можно использовать EntityNotFoundException.forId("Item", itemId).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Заменил

Rus-tem added 3 commits June 12, 2026 15:36
# Conflicts:
#	src/main/java/com/warehouse/controller/ItemController.java
#	src/main/java/com/warehouse/repository/ItemRepository.java
#	src/main/java/com/warehouse/repository/StockRepository.java
#	src/main/java/com/warehouse/service/item/ItemService.java
#	src/main/java/com/warehouse/service/item/ItemServiceImpl.java
#	src/test/java/com/warehouse/service/ItemServiceImplTest.java

@Andrey-Potokin Andrey-Potokin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Только по удаленному методу вопрос

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Удалил метод "getItem()"? В main ветке он есть

@Andrey-Potokin Andrey-Potokin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

вроде все

@Rus-tem Rus-tem merged commit d738fc5 into main Jun 13, 2026
1 check passed
@Andrey-Potokin Andrey-Potokin deleted the feature/delete_Item branch June 14, 2026 08:47
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.

Удаление товара

5 participants