|
| 1 | +package com.ndevs.fridge.service.impl; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.springframework.stereotype.Service; |
| 7 | + |
| 8 | +import com.ndevs.fridge.dto.FridgeItem; |
| 9 | +import com.ndevs.fridge.exception.NoItemFoundException; |
| 10 | +import com.ndevs.fridge.service.FridgeService; |
| 11 | + |
| 12 | +/** |
| 13 | + * |
| 14 | + * @author Nishanth Dharmaraju |
| 15 | + * |
| 16 | + */ |
| 17 | +@Service |
| 18 | +public class FridgeServiceImpl implements FridgeService { |
| 19 | + |
| 20 | + private static final int FRUIT = 1; |
| 21 | + private static final int DRINKS = 2; |
| 22 | + private static final int MEAT = 4; |
| 23 | + |
| 24 | + @Override |
| 25 | + public List<FridgeItem> getAllItems() { |
| 26 | + |
| 27 | + FridgeItem fruit = new FridgeItem(); |
| 28 | + fruit.setItemType(FRUIT); |
| 29 | + fruit.setName("Fruit"); |
| 30 | + fruit.setQuantity(10); |
| 31 | + FridgeItem drinks = new FridgeItem(); |
| 32 | + drinks.setItemType(DRINKS); |
| 33 | + drinks.setName("Drinks"); |
| 34 | + drinks.setQuantity(20); |
| 35 | + FridgeItem meat = new FridgeItem(); |
| 36 | + meat.setItemType(MEAT); |
| 37 | + meat.setName("Meat"); |
| 38 | + meat.setQuantity(3); |
| 39 | + |
| 40 | + return Arrays.asList(fruit, drinks, meat); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public FridgeItem getItemByType(Integer itemType) throws NoItemFoundException { |
| 45 | + |
| 46 | + FridgeItem item = null; |
| 47 | + |
| 48 | + if (itemType.equals(FRUIT)) { |
| 49 | + item = new FridgeItem(); |
| 50 | + item.setItemType(FRUIT); |
| 51 | + item.setName("Fruit"); |
| 52 | + item.setQuantity(10); |
| 53 | + } else { |
| 54 | + throw new NoItemFoundException("No such item found"); |
| 55 | + } |
| 56 | + |
| 57 | + return item; |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments