-
Notifications
You must be signed in to change notification settings - Fork 2
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
Develop #3
Conversation
…ry Authentication; refactoring
…ry Authentication; refactoring
# Conflicts: # src/main/resources/db/migration/V2__Populate_Eshop_tables.sql
# Conflicts: # src/main/resources/static/img/DB_structure.png
public static void main(String[] args) { | ||
SpringApplication.run(EShopApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public ModelMapper modelMapper() { | ||
ModelMapper modelMapper = new ModelMapper(); | ||
return modelMapper; | ||
return new ModelMapper(); |
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.
не нужно так делать.
сделайте отдельный класс в пакете config и туда выносите создание ваших бинов. это входная точка тут только майн и анатации. @RestController тут вам зачем? - лишний
@Configuration
public class ConfigBeans {
@@ -0,0 +1,16 @@ | |||
package by.petrovich.eshop; | |||
|
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.
[@UtilityClass](https://projectlombok.org/features/experimental/UtilityClass)
нужно ставить.
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.
и нужно в пакет utils это перенести. это константы
|
||
@Configuration | ||
@EnableWebSecurity | ||
@ComponentScan(basePackages = "by") |
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.
не нужна
} | ||
|
||
@ModelAttribute("user") | ||
public User initializeUserSessionObject() { |
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.
зачем это тут? нигде не юзаете
return new User(); | ||
} | ||
|
||
@ModelAttribute("cartDto") |
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.
зачем это тут? нигде не юзаете
import static by.petrovich.eshop.PageName.PROFILE_PAGE; | ||
import static by.petrovich.eshop.PageName.REGISTRATION_PAGE; | ||
|
||
@SessionAttributes({"user", "cartDto"}) |
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.
врятли это тут нужно
private final UserService userService; | ||
|
||
@Autowired | ||
public GoToController(CategoryService categoryService, UserService userService) { |
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.
@RequiredArgsConstructor почему бы не юзать?
и убрать констуктор?
@@ -33,27 +33,27 @@ public User User() { | |||
} | |||
|
|||
@GetMapping("/read-history/{userId}") | |||
public ModelAndView showOrdersHistory(@PathVariable("userId") String userId) { | |||
public ModelAndView showOrdersHistory(@PathVariable String userId) { | |||
ModelMap modelParams = new ModelMap(); |
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.
ModelMap modelParams = new ModelMap();
if (userId != null) {
Integer id = Integer.parseInt(userId);
modelParams.addAttribute("orders", orderService.readOrders(id));
return new ModelAndView(ORDER_HISTORY_PAGE, modelParams);
}
return new ModelAndView(HOME_PAGE, modelParams);
так проще код читать. и есле не надо
ModelAndView model) { | ||
if (errors.hasErrors()) { | ||
throw new ValidationException((Throwable) errors); | ||
// TODO: 3 июл. 2023 г. |
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.
что за коментарий?
BindingResult errors, | ||
ModelAndView model) { | ||
if (errors.hasErrors()) { | ||
throw new ValidationException((Throwable) errors); |
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.
(Throwable) errors врятли это отработает. BindingResult это не Throwable! проверьте
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.
посмотрел
@Builder | ||
public class CartDto { | ||
@NotNull | ||
private List<ProductDto> products = new ArrayList<>(); |
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.
ленивая инициализация должна быть в гетторе. и зачем вам тут @NotNull если вы сделали новый список сразу?
public List<ProductDto> getProducts() {
if(products == null){
products = new ArrayList<>();
}
return products;
}
private String name; | ||
@NotBlank(message = "Password is required") | ||
@Size(min = 2, max = 20, message = "Password id is required") | ||
// TODO: add validator 28 мая 2023 г. |
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.
??
return user.getEmail(); | ||
} | ||
|
||
public String getRole() { |
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.
getRoleName лучше назвать. и эти методы используются гдето?
modelAndView.addObject("userNotFoundException", ex.getMessage()); | ||
logger.error("error", ex); | ||
log.error("error", ex); |
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.
лучше полные тексты писать UserNotFoundException ане error
@@ -17,7 +17,7 @@ public interface ProductRepository extends JpaRepository<Product, Integer> { | |||
@Query("SELECT p FROM Product p WHERE p.category.categoryId =:categoryId") | |||
List<Product> findProductsByCategoryId(Integer categoryId); | |||
|
|||
Set<Product> findProductsByNameContainingIgnoreCase(String searchKey); | |||
Set<Product> findProductsByNameContainingIgnoreCaseOrDescriptionContainingIgnoreCase(String searchKey, String searchKey1); |
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.
searchKey1 не красивое название. сделайте searchKeyName and searchKeyDesc
List<ProductDto> productsDto = cartDto.getProducts(); | ||
productsDto.clear(); | ||
return CartDto.builder() | ||
.products(new ArrayList<>()) |
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.
зачем возвращать новый объект?
return sum; | ||
@Override | ||
public double calculateTotalPrice(List<ProductDto> productsDto) { | ||
return productsDto.stream().mapToDouble(ProductDto::getPrice).sum(); |
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.
оформление стримов вот так должно быть
productsDto.stream()
.mapToDouble(ProductDto::getPrice)
.sum();
ваш CustomUserDetail - рабочее решение. но мне больше по душе вот эта реализация, меньше кода. |
Посмотрите пожалуйста.
Вопросов как всегда больше, чем ответов.
Отдельное внимание уделите CustomUserDetail. Хочу узнать ваше мнение по поводу такой реализации