diff --git a/backend/src/main/spoonaccular/models/recipe_information/Recipe.java b/backend/src/main/spoonaccular/models/recipe_information/Recipe.java index 130a869..2f44c34 100644 --- a/backend/src/main/spoonaccular/models/recipe_information/Recipe.java +++ b/backend/src/main/spoonaccular/models/recipe_information/Recipe.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.*; "readyInMinutes", "servings", "image", + "sourceUrl", "spoonacularSourceUrl" }) @Generated("jsonschema2pojo") @@ -44,6 +45,8 @@ public class Recipe { private Integer servings; @JsonProperty("image") private String image; + @JsonProperty("sourceUrl") + private String sourceUrl; @JsonProperty("spoonacularSourceUrl") private String spoonacularSourceUrl; @@ -147,4 +150,14 @@ public class Recipe { this.spoonacularSourceUrl = spoonacularSourceUrl; } + @JsonProperty("sourceUrl") + public String getSourceUrl() { + return sourceUrl; + } + + @JsonProperty("sourceUrl") + public void setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + } + } diff --git a/backend/src/main/whattocook/models/Unit.java b/backend/src/main/whattocook/models/Unit.java index ed37377..0743e0c 100644 --- a/backend/src/main/whattocook/models/Unit.java +++ b/backend/src/main/whattocook/models/Unit.java @@ -1,6 +1,7 @@ package whattocook.models; public enum Unit { - GRAMMS, - MILLILETERS + g, + ml, + units } diff --git a/backend/src/test/java/items/ItemTests.java b/backend/src/test/java/items/ItemTests.java index ff27ce7..a2a9ccf 100644 --- a/backend/src/test/java/items/ItemTests.java +++ b/backend/src/test/java/items/ItemTests.java @@ -29,14 +29,14 @@ final class ItemTests { @Test public void saveTest() { - Item item = new Item("kartoffel", Unit.GRAMMS, 5000); + Item item = new Item("kartoffel", Unit.g, 5000); itemRepository.save(item); assertTrue(itemRepository.existsById(item.getId())); } @Test public void findByIDTest() { - Item item = new Item("tortillias", Unit.GRAMMS, 5000); + Item item = new Item("tortillias", Unit.g, 5000); itemRepository.save(item); assertEquals(item, itemRepository.findById(item.getId()).get()); } @@ -49,7 +49,7 @@ final class ItemTests { @Test public void findByNameTest(){ - Item item = new Item("tortillias", Unit.GRAMMS, 5000); + Item item = new Item("tortillas", Unit.g, 5000); itemRepository.save(item); assertEquals(item, itemRepository.findByName(item.getName()).get()); } @@ -57,11 +57,11 @@ final class ItemTests { @Test public void findAllTest() { List savedItems = new ArrayList(); - savedItems.add( new Item("nachos", Unit.GRAMMS, 5000)); - savedItems.add( new Item("wurst", Unit.GRAMMS, 5000)); - savedItems.add( new Item("schinken", Unit.GRAMMS, 5000)); - savedItems.add( new Item("brokkoli", Unit.GRAMMS, 5000)); - savedItems.add( new Item("eiscreme", Unit.GRAMMS, 5000)); + savedItems.add( new Item("nachos", Unit.g, 5000)); + savedItems.add( new Item("wurst", Unit.g, 5000)); + savedItems.add( new Item("schinken", Unit.g, 5000)); + savedItems.add( new Item("brokkoli", Unit.g, 5000)); + savedItems.add( new Item("eiscreme", Unit.g, 5000)); itemRepository.saveAll(savedItems); @@ -71,7 +71,7 @@ final class ItemTests { @Test public void deleteTest() { - Item item = new Item("elefantenfuß", Unit.GRAMMS, 5000); + Item item = new Item("elefantenfuß", Unit.g, 5000); itemRepository.save(item); assertEquals(item, itemRepository.findById(item.getId()).get()); itemRepository.delete(item); @@ -80,7 +80,7 @@ final class ItemTests { @Test public void updateTest() { - Item item = new Item("schokoküsse", Unit.GRAMMS, 5000); + Item item = new Item("schokoküsse", Unit.g, 5000); itemRepository.save(item); long itemCount = itemRepository.count(); item.setQuantity(4574); diff --git a/frontend/src/components/ItemModel.vue b/frontend/src/components/ItemModel.vue index 9f62c45..13b64e9 100644 --- a/frontend/src/components/ItemModel.vue +++ b/frontend/src/components/ItemModel.vue @@ -94,6 +94,8 @@ + + @@ -138,6 +140,8 @@ const Items = { return { items: [], newItem: '', + newQuantity: 0, + newUnit: '', editedItem: null, loading: true, error: null, @@ -163,29 +167,29 @@ const Items = { return this.activeUser ? this.activeUser.email : '' }, inputPlaceholder: function () { - return this.activeUser ? this.activeUser.given_name + ', what do you want to add?' : 'What needs to be added' + return this.activeUser ? this.activeUser.given_name + ', What do you want to add?' : 'What needs to be added?' } }, methods: { addItem: function () { - var value = this.newItem && this.newItem.trim() - if (!value) { + const addableItem = this.newItem && this.newItem.trim(); + const addableQuantity = parseInt(this.newQuantity); + const addableUnit = this.newUnit; + if (!addableItem) { return } - var components = value.split(' ') - - api.createNew(components[0], - parseInt(components[1].replace(/[^\d.]/g, '')), - components[1].replace(/[0-9]/g, '') === 'ml' ? 'MILLILETERS' : "GRAMMS" + api.createNew(addableItem, + addableQuantity, + addableUnit ).then((response) => { this.$log.debug("New item created:", response); this.items.push({ id: response.data.id, - name: components[0], - quantity: parseInt(components[1].replace(/[^\d.]/g, '')), - unit: components[1].replace(/[0-9]/g, '') === 'MILLILETERS' ? 'ml' : 'g' + name: addableItem, + quantity: addableQuantity, + unit: addableUnit }) }).catch((error) => { this.$log.debug(error); @@ -218,10 +222,6 @@ export default Items - - - -