Search in sources :

Example 1 with ProductDto

use of com.faltenreich.diaguard.feature.food.networking.dto.ProductDto in project Diaguard by Faltenreich.

the class FoodDao method createOrUpdate.

public List<Food> createOrUpdate(@NonNull SearchResponseDto dto) {
    String languageCode = Helper.getLanguageCode();
    List<Food> foodList = new ArrayList<>();
    Collections.reverse(dto.products);
    for (ProductDto productDto : dto.products) {
        // Workaround: API returns products in other languages even though defined otherwise through GET parameters
        boolean isSameLanguage = languageCode.equals(productDto.languageCode);
        if (isSameLanguage && productDto.isValid()) {
            Food food = parseFromDto(productDto);
            if (food != null) {
                foodList.add(0, food);
            }
        }
    }
    FoodDao.getInstance().bulkCreateOrUpdate(foodList);
    return foodList;
}
Also used : ArrayList(java.util.ArrayList) ProductDto(com.faltenreich.diaguard.feature.food.networking.dto.ProductDto) Food(com.faltenreich.diaguard.shared.data.database.entity.Food)

Aggregations

ProductDto (com.faltenreich.diaguard.feature.food.networking.dto.ProductDto)1 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)1 ArrayList (java.util.ArrayList)1