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 #4

Merged
merged 14 commits into from
Jul 12, 2023
Merged

Develop #4

merged 14 commits into from
Jul 12, 2023

Conversation

Petrovich-A
Copy link
Owner

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

Поправил с учетом предыдущих замечаний
Добавил картинки и переделал пагинацию
Улучшил UI

public class CategoryController {
private final int NUMBER_ELEMENTS_ON_PAGE = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

статик забыли. только константы называем большими буквами. а это просто не изменяемая переменная этого класса.

public ModelAndView showCategoryPage(
@PathVariable Integer categoryId,
@RequestParam Optional<Integer> categoryId,
@RequestParam("page") Optional<Integer> page,
Copy link
Collaborator

Choose a reason for hiding this comment

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

оптионал можно. но с ним больше кода получается. куда проще юзать defaultValue
@RequestParam(defaultValue = "test")

model.addAttribute("productPage", productPage);
int totalPages = productPage.getTotalPages();
int pageSize = size.orElse(NUMBER_ELEMENTS_ON_PAGE);
int id = categoryId.orElse(categoryId.orElseThrow(() -> new BadCredentialsException("Bad credentials.")));
Copy link
Collaborator

Choose a reason for hiding this comment

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

new BadCredentialsException("Bad credentials.") что это за эксепшен? у вас же айди пришел null. при чем тут плохие креды?
Лучше IllegalArgumentException юзайте

import static by.petrovich.eshop.PageName.LOGIN_PAGE;
import static by.petrovich.eshop.PageName.PROFILE_PAGE;
import static by.petrovich.eshop.PageName.REGISTRATION_PAGE;
import static by.petrovich.eshop.utils.PageName.ADMIN_PAGE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

подключайте статические анализаторы кода. хотябы checkstyle. проходили на уроке. файлы с настройками у меня в репозитории

Copy link
Collaborator

Choose a reason for hiding this comment

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

Подключить файлик tms_code_style.xml в интелиж идею(https://github.com/tmspavel/c18onl2022/tree/main/Lesson29/codestyle)
и переформатируйте этот класс. все статик импорты будут вверху.

@@ -51,6 +53,10 @@ public class Product {
@JsonIgnore
private List<Order> orders = new ArrayList<>();

@OneToOne(cascade = {CascadeType.ALL})
Copy link
Collaborator

Choose a reason for hiding this comment

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

CascadeType.ALL? если продукт удаляете из базы то и картинка удалится. врятли такое поведение нужно. лучше пересмотреть поведение!

public Optional<Category> findById(Integer id) {
return categoryRepository.findById(id);
public User save(Category category) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

почему null? не дописали?

.link("/img/error.png")
.build();
Optional<Image> image = imageRepository.findImageByProductId(id);
Image actual = image.get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Exception in thread "main" java.util.NoSuchElementException: No value present
если не найдете ничего по айди.
assertEquals(true, image.isPresent()); добавьте перед 28 строкой

.build();
Product savedProduct = productRepository.save(product);
Optional<Product> existedProduct = productRepository.findById(savedProduct.getProductId());
assertEquals(savedProduct, existedProduct.get());
Copy link
Collaborator

Choose a reason for hiding this comment

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

тоже самое что и комментарий выше

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.

посмотрел

@tmspavel tmspavel merged commit 91e64a7 into master Jul 12, 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