Optimized method which returns list of shopping list items
@@ -2,8 +2,10 @@ package greencity.service;
import greencity.client.RestClient;
import greencity.constant.ErrorMessage;
-import static greencity.constant.ErrorMessage.CUSTOM_SHOPPING_LIST_ITEM_NOT_FOUND_BY_ID;
-import greencity.dto.shoppinglistitem.*;
+import greencity.dto.shoppinglistitem.BulkSaveCustomShoppingListItemDto;
+import greencity.dto.shoppinglistitem.CustomShoppingListItemResponseDto;
+import greencity.dto.shoppinglistitem.CustomShoppingListItemSaveRequestDto;
+import greencity.dto.shoppinglistitem.ShoppingListItemDto;
import greencity.dto.user.UserVO;
import greencity.entity.CustomShoppingListItem;
import greencity.entity.Habit;
@@ -24,6 +26,8 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import static greencity.constant.ErrorMessage.CUSTOM_SHOPPING_LIST_ITEM_NOT_FOUND_BY_ID;
+
/**
* The class provides implementation of the
* {@code CustomShoppingListItemService}.
@@ -203,11 +207,9 @@ public class CustomShoppingListItemServiceImpl implements CustomShoppingListItem
@Override
public List<ShoppingListItemDto> findByActiveByUserIdAndLanguageCode(Long userId, String code) {
- List<ShoppingListItemDto> shoppingListItems = new ArrayList<>();
- customShoppingListItemRepo.findByActiveByUserIdAndLanguageCode(userId, code)
- .forEach(x -> shoppingListItems.add(modelMapper.map(
- x, ShoppingListItemDto.class)));
- return shoppingListItems;
+ return customShoppingListItemRepo.findByActiveByUserIdAndLanguageCode(userId, code)
+ .stream().map(x -> modelMapper.map(x, ShoppingListItemDto.class))
+ .collect(Collectors.toList());
}
/**
