Skip to content

Conversation

@trokhim03
Copy link
Owner

No description provided.

Copy link

@Elena-Bruyako Elena-Bruyako left a comment

Choose a reason for hiding this comment

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

see comments

Comment on lines 79 to 81
if (authentication == null || !(authentication.getPrincipal() instanceof User)) {
throw new EntityNotFoundException("Authentication failed. User not found.");
}

Choose a reason for hiding this comment

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

Suggested change
if (authentication == null || !(authentication.getPrincipal() instanceof User)) {
throw new EntityNotFoundException("Authentication failed. User not found.");
}


@Data
public class CartItemRequestDto {
@NotNull

Choose a reason for hiding this comment

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

Suggested change
@NotNull
@NotNull
@Positive

Comment on lines 12 to 13
@Min(value = 1,
message = "Quantity must be at least 1")

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)

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)

Choose a reason for hiding this comment

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

Suggested change
@GeneratedValue(strategy = GenerationType.IDENTITY)

Comment on lines 9 to 10
@Query("SELECT sc FROM ShoppingCart sc LEFT JOIN FETCH sc.cartItems "
+ "WHERE sc.user.id = :userId AND sc.user.isDeleted = false")

Choose a reason for hiding this comment

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

Suggested change
@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

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

Choose a reason for hiding this comment

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

remove redundant empty lines

Copy link

@JJJazl JJJazl left a 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();
Copy link

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

Suggested change
CartItem cartItem = existingCartItem.get();
CartItem cartItem = existingCartItem.orElseThrow();

@trokhim03 trokhim03 merged commit 40c7c86 into main Mar 4, 2025
2 checks passed
@trokhim03 trokhim03 deleted the pr-11 branch March 4, 2025 09:58
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.

4 participants