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

Implement Shopping Cart Management with entities ShoppingCart and CartItem... #13

Merged
merged 3 commits into from
May 22, 2024

Conversation

nklimovych
Copy link
Owner

endpoints for adding, updating, viewing, and deleting cart items, security configurations, Liquibase integration, pagination, sorting, Swagger documentation, and enhanced BookMapper.

…tItem, endpoints for adding, updating, viewing, and deleting cart items, security configurations, Liquibase integration, pagination, sorting, and BookMapper.
Copy link

@oksana-miazina oksana-miazina left a 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

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?

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

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.

Choose a reason for hiding this comment

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

Not resolved

Copy link

@andrii-hoienko andrii-hoienko left a 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

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

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

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) {

Choose a reason for hiding this comment

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

Suggested change
private Book getBookOrElseThrow(Long bookId) {
private Book getBook(Long bookId) {

"Unable to proceed: Book not found with id: " + bookId));
}

private CartItem getCartItemOrElseThrow(Long itemId) {

Choose a reason for hiding this comment

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

Suggested change
private CartItem getCartItemOrElseThrow(Long itemId) {
private CartItem getCartItem(Long itemId) {

baseColumnNames: book_id
constraintName: fk_cart_items_book
referencedTableName: books
referencedColumnNames: id

Choose a reason for hiding this comment

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

Suggested change
referencedColumnNames: id
referencedColumnNames: id

private User user;

@OneToMany(mappedBy = "shoppingCart")
private Set<CartItem> cartItems = new HashSet<>();

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

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) {

Choose a reason for hiding this comment

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

Suggested change
public void remove(Long itemId, ShoppingCart shoppingCart) {
public void delete(Long itemId) {


@RequiredArgsConstructor
@Service
public class CartItemServiceImpl implements CartItemService {

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.
@nklimovych nklimovych merged commit 56913c9 into main May 22, 2024
2 checks passed
@nklimovych nklimovych deleted the shopping-cart branch May 22, 2024 12:14
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.

3 participants