Skip to content
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

Merged
merged 35 commits into from
Jul 6, 2023
Merged

Develop #3

merged 35 commits into from
Jul 6, 2023

Conversation

Petrovich-A
Copy link
Owner

@Petrovich-A Petrovich-A commented Jul 6, 2023

Посмотрите пожалуйста.

Вопросов как всегда больше, чем ответов.
Отдельное внимание уделите CustomUserDetail. Хочу узнать ваше мнение по поводу такой реализации

Petrovich-A and others added 30 commits June 22, 2023 13:24
# 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();
Copy link
Collaborator

@tmspavel tmspavel Jul 6, 2023

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;

Copy link
Collaborator

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) нужно ставить.

Copy link
Collaborator

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")
Copy link
Collaborator

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() {
Copy link
Collaborator

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")
Copy link
Collaborator

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"})
Copy link
Collaborator

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) {
Copy link
Collaborator

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();
Copy link
Collaborator

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 г.
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Throwable) errors врятли это отработает. BindingResult это не Throwable! проверьте

Copy link
Collaborator

@tmspavel tmspavel left a 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<>();
Copy link
Collaborator

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 г.
Copy link
Collaborator

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() {
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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<>())
Copy link
Collaborator

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();
Copy link
Collaborator

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();

@tmspavel
Copy link
Collaborator

tmspavel commented Jul 6, 2023

Посмотрите пожалуйста.

Вопросов как всегда больше, чем ответов. Отдельное внимание уделите CustomUserDetail. Хочу узнать ваше мнение по поводу такой реализации

ваш CustomUserDetail - рабочее решение. но мне больше по душе вот эта реализация, меньше кода.
https://github.com/RameshMF/registration-login-springboot-security-thymeleaf/blob/master/src/main/java/com/example/registrationlogindemo/security/CustomUserDetailsService.java

@tmspavel tmspavel merged commit 45fd663 into master Jul 6, 2023
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.

2 participants