-
Notifications
You must be signed in to change notification settings - Fork 0
Создал ветку: add-item-requests-and-gateway. #3
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
Conversation
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
4) Обновил тесты.
5) Создал новые тесты.
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build"
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build" и Run application
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build" и Run application
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build" и Run application
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build" и Run application
9) Пробую обойти Application Run
1) Добавляем запрос вещи.
2) Реализовал четыре новых эндпоинта:
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.
3) Добавил опцию ответа на запрос.
4) Разделил проект на 2 модуля shareIt-server и shareIt-gateway.
5) Обновил тесты.
6) Создал новые тесты.
7) Обновил основной pom, suppressionsLocation для плагина Maven Checkstyle.
8) Обновил тесты, чтобы пройти "build" и Run application
9) Пробую обойти Application Run
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class BookingStateValidator { |
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.
Класс нигде не используется, стоит его удалить
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.
Удалил не используемый класс BookingStateValidator.
| REJECTED; | ||
|
|
||
| public static Optional<BookingState> from(String stringState) { | ||
| for (BookingState state : values()) { |
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.
Нужно переписать с помощью stream api
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 в классе BookingState с использованием Stream API.
|
|
||
| @ExceptionHandler | ||
| @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| public Map<String, String> handleValidationException(final MethodArgumentNotValidException 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.
Для улучшения читаемости, единообразия обработки ошибок и расширяемости, рекомендуется заменить Map<String, String> на отдельный класс ErrorResponse.
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.
Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse.
|
|
||
| @ExceptionHandler | ||
| @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| public Map<String, String> handleIllegalArgumentException(final IllegalArgumentException 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.
Имя e не отражает суть переменной. Лучше использовать более говорящее имя, например exception
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.
Заменил e на более подходящую exception.
| public class ItemController { | ||
| private final ItemClient itemClient; | ||
| private final ObjectMapper objectMapper; | ||
| private static final String USER_ID_HEADER = "X-Sharer-User-Id"; |
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.
Лучше сделать публичной переменной и вынести в утильный класс, чтобы можно было использовать по всему модулю
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.
Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров.
| if (request.getURI().getPath().matches("/items/\\d+") && "GET".equals(request.getMethod().name())) { | ||
| try { | ||
| Map<String, Object> bodyMap; | ||
| if (body instanceof Map) { |
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.
Нужно избавиться от instanceOf
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.
Избавился от проверки instanceОf.
server/pom.xml
Outdated
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-validation</artifactId> |
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.
Вся валидация переехала в модуль gateway, из модуля server ее нужно удалить вместе с зависимостью
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.
Спасибо) Удалил зависимость на spring-boot-starter-validation из сервера и все аннотации валидации.
| @RequiredArgsConstructor | ||
| public class BookingController { | ||
| private final BookingService bookingService; | ||
| private static final String USER_ID_HEADER = "X-Sharer-User-Id"; |
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.
Нужно вынести в публиную переменную и использовать по всему модулю
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.
Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров.
| @Override | ||
| @Transactional | ||
| public ItemRequestDto create(ItemRequestDto itemRequestDto, Long userId) { | ||
| if (itemRequestDto.getDescription() == null || itemRequestDto.getDescription().isBlank()) { |
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.
Вся валидация dto должна быть в модуле gateway
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.
Удалил валидацию dto из серврной ItemRequestServiceImpl.
1) Удалил не используемый класс BookingStateValidator.
1) Удалил не используемый класс BookingStateValidator. 2) Переписал метод from в классе BookingState с использованием Stream API. 3) Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse. 4) Заменил e на более подходящую exception.
1) Удалил не используемый класс BookingStateValidator. 2) Переписал метод from в классе BookingState с использованием Stream API. 3) Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse. 4) Заменил e на более подходящую exception. 5) Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров.
1) Удалил не используемый класс BookingStateValidator. 2) Переписал метод from в классе BookingState с использованием Stream API. 3) Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse. 4) Заменил e на более подходящую exception. 5) Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров. 6) Избавился от instanceof.
1) Удалил не используемый класс BookingStateValidator. 2) Переписал метод from в классе BookingState с использованием Stream API. 3) Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse. 4) Заменил e на более подходящую exception. 5) Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров. 6) Избавился от instanceof. 7) Удалил валидацию dto из серврной ItemRequestServiceImpl.
1) Удалил не используемый класс BookingStateValidator. 2) Переписал метод from в классе BookingState с использованием Stream API. 3) Заменил Map<String, String> в ErrorHandler на отдельный класс ErrorResponse. 4) Заменил e на более подходящую exception. 5) Вынес USER_ID_HEADER в константу в обоих модулях для всех контроллеров. 6) Избавился от instanceof. 7) Удалил валидацию dto из серврной ItemRequestServiceImpl. 8) Удалил зависимость на spring-boot-starter-validation и все аннотации валидации.
POST /requests, GET /requests, GET /requests/all, GET /requests/{requestId}, GET /requests.