Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1 задание
1.1. В таблицу users и
orders добавил поле
address varchar(255),
1.2. В классе User, Order добавил поле
1.3. В index.html добавил форму и кнопку для ввода адреса
1.4. В index.js добавил функцию (заменил createOrder с get)
$scope.createOrder= function (){
$http({
url:contextPath + '/api/v1/orders/create',
method: 'POST',
params:{
address: $scope.order ? $scope.order.address : null,
},
}).then(function successCallback(response) {
$scope.order.address = null;
$scope.showMyOrders();
$scope.showCart();
},function errorCallback(response) {
window.alert("Error!");
})
}
1.5. В OrderController создал метод
1.6. В OrderService изменил метод, добавив поле String address
public Order createFromUserCart(User user, String address) {
Order order = new Order(cart, user);
order.setAddress(address);
order = orderRepository.save(order);
cart.clear();
return order;
1.7. В конструкторе Order добавил проверку, что корзина не пуста, чтобы не оформлять заказ с нулевой стоимостью
2. Пользователь создается в первый раз, после запуска сессии, потом север почему-то не отвечает на создание нового пользователя
2.1 js, html
2.2 Сделал метод в AuthController (Dto пока убрал)
}
2.3 Метод в UserDetailsService
Заинжектил securityConfig и пришлось ставить аннотацию @lazy над классом JwtRequestFilter, иначе дедлок.
private final SecurityConfig securityConfig;
public User saveUser(User userDto){
Optional userFromDB = userRepository.findByUsername(userDto.getUsername());
if (!userFromDB.isEmpty()) {
throw new ResourceNotFoundException("User find!");
}
userDto.setRoles(Collections.singleton(new Role(1L,"ROLE_USER")));
userDto.setPassword(securityConfig.passwordEncoder().encode(userDto.getPassword()));
userDto.setEmail("default@mail.ru");
return userRepository.save(userDto);
}