-
Notifications
You must be signed in to change notification settings - Fork 0
added a shoppingCart model #11
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
Conversation
Elena-Bruyako
left a comment
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.
see comments
| if (authentication == null || !(authentication.getPrincipal() instanceof User)) { | ||
| throw new EntityNotFoundException("Authentication failed. User not found."); | ||
| } |
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.
| if (authentication == null || !(authentication.getPrincipal() instanceof User)) { | |
| throw new EntityNotFoundException("Authentication failed. User not found."); | |
| } |
|
|
||
| @Data | ||
| public class CartItemRequestDto { | ||
| @NotNull |
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 | |
| @NotNull | |
| @Positive |
| @Min(value = 1, | ||
| message = "Quantity must be at least 1") |
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.
use @Positive
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @OneToOne(fetch = FetchType.LAZY, optional = false) |
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.
use @MapsId
| @Table(name = "shopping_carts") | ||
| public class ShoppingCart { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) |
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.
| @GeneratedValue(strategy = GenerationType.IDENTITY) |
| @Query("SELECT sc FROM ShoppingCart sc LEFT JOIN FETCH sc.cartItems " | ||
| + "WHERE sc.user.id = :userId AND sc.user.isDeleted = false") |
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.
| @Query("SELECT sc FROM ShoppingCart sc LEFT JOIN FETCH sc.cartItems " | |
| + "WHERE sc.user.id = :userId AND sc.user.isDeleted = false") | |
| @EntityGraph(attributePaths = {"cartItems", "cartItems.book"}) |
| } | ||
|
|
||
| @Override | ||
| @Transactional |
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.
replace under the class
| .orElseThrow(() -> new EntityNotFoundException("Default role not found")); | ||
| user.setRoles(Set.of(defaultRole)); | ||
| userRepository.save(user); | ||
|
|
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.
remove redundant empty lines
JJJazl
left a comment
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.
Great! Let's move on, left one minor comment)
| .findFirst(); | ||
|
|
||
| if (existingCartItem.isPresent()) { | ||
| CartItem cartItem = existingCartItem.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.
It is recommended to use orElseThrow() instead of `get()'. You can also see this in the java doc
| CartItem cartItem = existingCartItem.get(); | |
| CartItem cartItem = existingCartItem.orElseThrow(); |
No description provided.