-
Notifications
You must be signed in to change notification settings - Fork 156
Add files from other repository #167
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
| public ResponseEntity<Integer> getSocks(@RequestParam String color, | ||
| @RequestParam String operation, | ||
| @RequestParam int cottonPart) { | ||
| if (cottonPart < 0 || cottonPart > 100) |
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.
можно в принципе сделать аннотациями
| Sock sock = sockRepository | ||
| .findByColorAndCottonPart(color, sockModel.getCottonPart()) | ||
| .orElseThrow(NotEnoughSocksException::new); | ||
| if (sock.getQuantity() < sockModel.getQuantity()) |
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.
я бы так исключениями не увлекался - это дорого и медленно, а например ситуация когда нет нужного числа носков. -вполне штатная. поэтому тут лучше либо ответ с результатом операции, который маппится в http, либо в сервисе не хранить тяжелую логику, а переложить ее на контроллер.
В целом тут два варианта - либо сервис возвращает сложный формат ответа, включающий ошибки и их описание, либо контроллер у себя логику всю считает - оба валидные
| private final ColorRepository colorRepository; | ||
| private final SockRepository sockRepository; | ||
|
|
||
| public int addSocks(@NotNull SockModel sockModel) { |
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.
тут конечно нужны транзакции
|
|
||
| int quantity = switch (operation) { | ||
| case "moreThan" -> sockRepository | ||
| .findByColorAndCottonPartGreaterThan(color, cottonPart) |
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.
тут ради одной цифры тащить целый объект не оптимально
| package com.example.socks; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; |
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.
С поставленной задачей справился, есть недочеты или спорные моменты - они есть всегда и везде, главное, что решение валидно.
No description provided.