-
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 #4
Conversation
public class CategoryController { | ||
private final int NUMBER_ELEMENTS_ON_PAGE = 3; |
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.
статик забыли. только константы называем большими буквами. а это просто не изменяемая переменная этого класса.
public ModelAndView showCategoryPage( | ||
@PathVariable Integer categoryId, | ||
@RequestParam Optional<Integer> categoryId, | ||
@RequestParam("page") Optional<Integer> page, |
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.
оптионал можно. но с ним больше кода получается. куда проще юзать 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."))); |
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.
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; |
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.
подключайте статические анализаторы кода. хотябы checkstyle. проходили на уроке. файлы с настройками у меня в репозитории
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.
Подключить файлик 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}) |
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.
CascadeType.ALL? если продукт удаляете из базы то и картинка удалится. врятли такое поведение нужно. лучше пересмотреть поведение!
public Optional<Category> findById(Integer id) { | ||
return categoryRepository.findById(id); | ||
public User save(Category category) { | ||
return null; |
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.
почему null? не дописали?
.link("/img/error.png") | ||
.build(); | ||
Optional<Image> image = imageRepository.findImageByProductId(id); | ||
Image actual = image.get(); |
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.
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()); |
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.
посмотрел
Поправил с учетом предыдущих замечаний
Добавил картинки и переделал пагинацию
Улучшил UI