-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat-new-readme
- Loading branch information
Showing
21 changed files
with
158 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/diatliuk/bookstore/repository/cart/CartItemRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package org.diatliuk.bookstore.repository.cart; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.diatliuk.bookstore.model.CartItem; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface CartItemRepository extends JpaRepository<CartItem, Long> { | ||
@Query("FROM CartItem ci LEFT JOIN FETCH ci.book " | ||
+ "LEFT JOIN FETCH ci.shoppingCart WHERE ci.id = :id") | ||
Optional<CartItem> findById(Long id); | ||
|
||
@Query("FROM CartItem ci LEFT JOIN FETCH ci.book " | ||
+ "LEFT JOIN FETCH ci.shoppingCart WHERE ci.shoppingCart.id = :id") | ||
List<CartItem> findAllByShoppingCartId(Long id); | ||
|
||
boolean existsByIdAndShoppingCartId(Long id, Long shoppingCartId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/diatliuk/bookstore/service/OrderItemService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.diatliuk.bookstore.service; | ||
|
||
import java.util.List; | ||
import org.diatliuk.bookstore.dto.order.item.OrderItemDto; | ||
|
||
public interface OrderItemService { | ||
List<OrderItemDto> getItemsByOrderId(Long id); | ||
|
||
OrderItemDto getItemInOrderById(Long orderId, Long id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/diatliuk/bookstore/service/impl/OrderItemServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.diatliuk.bookstore.service.impl; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.diatliuk.bookstore.dto.order.item.OrderItemDto; | ||
import org.diatliuk.bookstore.exception.EntityNotFoundException; | ||
import org.diatliuk.bookstore.mapper.OrderItemMapper; | ||
import org.diatliuk.bookstore.model.OrderItem; | ||
import org.diatliuk.bookstore.repository.order.OrderItemRepository; | ||
import org.diatliuk.bookstore.service.OrderItemService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class OrderItemServiceImpl implements OrderItemService { | ||
private final OrderItemRepository orderItemRepository; | ||
private final OrderItemMapper orderItemMapper; | ||
|
||
@Override | ||
public List<OrderItemDto> getItemsByOrderId(Long id) { | ||
return orderItemRepository.getOrderItemsByOrder_Id(id) | ||
.stream() | ||
.map(orderItemMapper::toDto) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public OrderItemDto getItemInOrderById(Long orderId, Long id) { | ||
OrderItem item = orderItemRepository.getOrderItemsByOrder_Id(orderId) | ||
.stream().filter(orderItem -> orderItem.getId().equals(id)) | ||
.findAny() | ||
.orElseThrow(() -> new EntityNotFoundException("Can't find an orderItem with id: " | ||
+ id + " in the order with id: " + orderId)); | ||
return orderItemMapper.toDto(item); | ||
} | ||
} |
Oops, something went wrong.