<commit_before>Mealpler.service('StorageModel', function () {
    let service = this;

    service.addItemToFridgeList = function (item) {
        let list = service.getFridgeList();
        list.push(item);
        service.updateFridgeList(list);
    };

    service.addItemToGroceryList = function (item) {
        let list = service.getGroceryList().concat(item);
        service.updateGroceryList(list);
    };

    service.updateFridgeItem = function (oldItem) {
        let list = service.getFridgeList();
        list.filter(a => a.name === oldItem.name)[0].quantity = oldItem.quantity;
        service.updateFridgeList(list);
    };

    service.updateGroceryItem = function (oldItem) {
        let list = service.getGroceryList();
        list.filter(a => a.name === oldItem.name)[0].quantity = oldItem.quantity;
        service.updateGroceryList(list);
    };

    service.deleteFridgeItem = function (itemToDelete) {
      let list = service.getFridgeList();
      let i = list.findIndex(a => a.name === itemToDelete.name && a.quantity === itemToDelete.quantity);
      list.splice(i, 1);
      service.updateFridgeList(list);
    };

    service.deleteGroceryItem = function (itemToDelete) {
        let list = service.getGroceryList();
        let i = list.findIndex(a => a.name === itemToDelete.name && a.quantity === itemToDelete.quantity);
        list.splice(i, 1);
        service.updateGroceryList(list);
    };

    service.deleteFridge = function () {
        localStorage.removeItem("fridge");
    };

    service.deleteGrocery = function () {
        localStorage.removeItem("grocery");
    };

    service.updateFridgeList = function (newItem) {
        localStorage.setItem("fridge", JSON.stringify(newItem));
    };

    service.updateGroceryList = function (newItem) {
        localStorage.setItem("grocery", JSON.stringify(newItem));
    };

    service.addMenuToStarred = function (menu) {
        localStorage.setItem("starredMenu", JSON.stringify(menu));
    };

    service.getFridgeList = function () {
        let fridgeList = [];
        try {
            fridgeList = JSON.parse(localStorage.getItem("fridge"));
        } catch (error) {
            console.log(error);
        }
        return fridgeList != null ? fridgeList : [];
    };

    service.getGroceryList = function () {
        let groceryList = [];
        try {
            groceryList = JSON.parse(localStorage.getItem("grocery"));
        } catch (error) {
            console.log(error);
        }
        return groceryList != null ? groceryList : [];
    };

    service.getStarredMenu = function () {
        let starredMenu = [];
        try {
            starredMenu = JSON.parse(localStorage.getItem("starredMenu"));
        } catch (error) {
            console.log(error);
        }
        return starredMenu != null ? starredMenu : [];
    }
});<commit_msg>MP-19: refactored Storage Model<commit_after>Mealpler.service('StorageModel', function () {
    let service = this;

    service.addItemToFridgeList = function (item) {
        let list = service.getFridgeList();
        list.push(item);
        service.addFoodToStored("fridge", list);
    };

    service.addItemToGroceryList = function (item) {
        let list = service.getGroceryList().concat(item);
        service.addFoodToStored("grocery", list);
    };

    service.updateFridgeItem = function (oldItem) {
        let list = service.getFridgeList();
        list.filter(a => a.name === oldItem.name)[0].quantity = oldItem.quantity;
        service.addFoodToStored("fridge", list);
    };

    service.updateGroceryItem = function (oldItem) {
        let list = service.getGroceryList();
        list.filter(a => a.name === oldItem.name)[0].quantity = oldItem.quantity;
        service.addFoodToStored("grocery", list);
    };

    service.deleteFridgeItem = function (itemToDelete) {
      let list = service.getFridgeList();
      let i = list.findIndex(a => a.name === itemToDelete.name && a.quantity === itemToDelete.quantity);
      list.splice(i, 1);
        service.addFoodToStored("fridge", list);
    };

    service.deleteGroceryItem = function (itemToDelete) {
        let list = service.getGroceryList();
        let i = list.findIndex(a => a.name === itemToDelete.name && a.quantity === itemToDelete.quantity);
        list.splice(i, 1);
        service.addFoodToStored("grocery", list);
    };

    service.deleteFridge = function () {
        localStorage.removeItem("fridge");
    };

    service.deleteGrocery = function () {
        localStorage.removeItem("grocery");
    };

    service.addFoodToStored = function (name, content) {
        localStorage.setItem(name, JSON.stringify(content));
    };

    service.getFridgeList = function () {
        let fridgeList = [];
        try {
            fridgeList = JSON.parse(localStorage.getItem("fridge"));
        } catch (error) {
            console.log(error);
        }
        return fridgeList != null ? fridgeList : [];
    };

    service.getGroceryList = function () {
        let groceryList = [];
        try {
            groceryList = JSON.parse(localStorage.getItem("grocery"));
        } catch (error) {
            console.log(error);
        }
        return groceryList != null ? groceryList : [];
    };

    service.getStarredMenu = function () {
        let starredMenu = [];
        try {
            starredMenu = JSON.parse(localStorage.getItem("starredMenu"));
        } catch (error) {
            console.log(error);
        }
        return starredMenu != null ? starredMenu : [];
    }
});
{'fraction_non_alphanumeric': 0.1370330459770115, 'fraction_numerical': 0.0017959770114942528, 'mean_word_length': 2.5025157232704403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5514766', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1592, 'n_words': 274}