-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement Shopping Cart Management with entities ShoppingCart and CartItem... #13
Conversation
…tItem, endpoints for adding, updating, viewing, and deleting cart items, security configurations, Liquibase integration, pagination, sorting, and BookMapper.
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.
Seriously, everything is perfect!
@@ -45,6 +46,7 @@ public BookDto save(CreateBookRequestDto requestDto) { | |||
} | |||
|
|||
@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.
Just interesting, how @Transactional
can be useful in get method?
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.
Not resolved
|
||
CartItem cartItem = new CartItem(); | ||
cartItem.setBook(book); | ||
cartItem.setQuantity(requestDto.getQuantity()); |
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 possible to move such logic into mapper, and Mapstruct
even can automate it.
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.
Not resolved
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.
Nice, left some comments
|
||
@Getter | ||
@Setter | ||
@Entity |
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.
Please add equals and hashCode to your enteties
|
||
CartItem cartItem = new CartItem(); | ||
cartItem.setBook(book); | ||
cartItem.setQuantity(requestDto.getQuantity()); |
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.
Not resolved
@@ -45,6 +46,7 @@ public BookDto save(CreateBookRequestDto requestDto) { | |||
} | |||
|
|||
@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.
Not resolved
itemRepository.delete(cartItem); | ||
} | ||
|
||
private Book getBookOrElseThrow(Long bookId) { |
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 Book getBookOrElseThrow(Long bookId) { | |
private Book getBook(Long bookId) { |
"Unable to proceed: Book not found with id: " + bookId)); | ||
} | ||
|
||
private CartItem getCartItemOrElseThrow(Long itemId) { |
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 CartItem getCartItemOrElseThrow(Long itemId) { | |
private CartItem getCartItem(Long itemId) { |
baseColumnNames: book_id | ||
constraintName: fk_cart_items_book | ||
referencedTableName: books | ||
referencedColumnNames: id |
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.
referencedColumnNames: id | |
referencedColumnNames: id | |
private User user; | ||
|
||
@OneToMany(mappedBy = "shoppingCart") | ||
private Set<CartItem> cartItems = new HashSet<>(); |
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.
OPTIONAL: I makes sence to make cascade it will allow to remove a lot of code and interaction with db
public void remove(Long itemId, ShoppingCart shoppingCart) { | ||
CartItem cartItem = getCartItemOrElseThrow(itemId); | ||
|
||
shoppingCart.getCartItems().remove(cartItem); |
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.
Looks like this part should be in shopping cart service
|
||
@Override | ||
@Transactional | ||
public void remove(Long itemId, ShoppingCart shoppingCart) { |
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 void remove(Long itemId, ShoppingCart shoppingCart) { | |
public void delete(Long itemId) { |
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class CartItemServiceImpl implements CartItemService { |
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.
I suggest to unite cart Item service and shopping cart service, this entity is very tight related, so it will be easier and more convenient to make invitations over them in one service
…ice to prevent code duplication and improve convenience. Fixed LazyInitializationException occurrences.
endpoints for adding, updating, viewing, and deleting cart items, security configurations, Liquibase integration, pagination, sorting, Swagger documentation, and enhanced BookMapper.