Merge branch 'fix-item-input' into add-recipe-page

This commit is contained in:
Karthik Vempati
2022-07-22 21:39:45 +02:00
6 changed files with 49 additions and 33 deletions

View File

@@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.*;
"readyInMinutes", "readyInMinutes",
"servings", "servings",
"image", "image",
"sourceUrl",
"spoonacularSourceUrl" "spoonacularSourceUrl"
}) })
@Generated("jsonschema2pojo") @Generated("jsonschema2pojo")
@@ -44,6 +45,8 @@ public class Recipe {
private Integer servings; private Integer servings;
@JsonProperty("image") @JsonProperty("image")
private String image; private String image;
@JsonProperty("sourceUrl")
private String sourceUrl;
@JsonProperty("spoonacularSourceUrl") @JsonProperty("spoonacularSourceUrl")
private String spoonacularSourceUrl; private String spoonacularSourceUrl;
@@ -147,4 +150,14 @@ public class Recipe {
this.spoonacularSourceUrl = spoonacularSourceUrl; this.spoonacularSourceUrl = spoonacularSourceUrl;
} }
@JsonProperty("sourceUrl")
public String getSourceUrl() {
return sourceUrl;
}
@JsonProperty("sourceUrl")
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
} }

View File

@@ -1,6 +1,7 @@
package whattocook.models; package whattocook.models;
public enum Unit { public enum Unit {
GRAMMS, g,
MILLILETERS ml,
units
} }

View File

@@ -29,14 +29,14 @@ final class ItemTests {
@Test @Test
public void saveTest() { public void saveTest() {
Item item = new Item("kartoffel", Unit.GRAMMS, 5000); Item item = new Item("kartoffel", Unit.g, 5000);
itemRepository.save(item); itemRepository.save(item);
assertTrue(itemRepository.existsById(item.getId())); assertTrue(itemRepository.existsById(item.getId()));
} }
@Test @Test
public void findByIDTest() { public void findByIDTest() {
Item item = new Item("tortillias", Unit.GRAMMS, 5000); Item item = new Item("tortillias", Unit.g, 5000);
itemRepository.save(item); itemRepository.save(item);
assertEquals(item, itemRepository.findById(item.getId()).get()); assertEquals(item, itemRepository.findById(item.getId()).get());
} }
@@ -49,7 +49,7 @@ final class ItemTests {
@Test @Test
public void findByNameTest(){ public void findByNameTest(){
Item item = new Item("tortillias", Unit.GRAMMS, 5000); Item item = new Item("tortillas", Unit.g, 5000);
itemRepository.save(item); itemRepository.save(item);
assertEquals(item, itemRepository.findByName(item.getName()).get()); assertEquals(item, itemRepository.findByName(item.getName()).get());
} }
@@ -57,11 +57,11 @@ final class ItemTests {
@Test @Test
public void findAllTest() { public void findAllTest() {
List<Item> savedItems = new ArrayList(); List<Item> savedItems = new ArrayList();
savedItems.add( new Item("nachos", Unit.GRAMMS, 5000)); savedItems.add( new Item("nachos", Unit.g, 5000));
savedItems.add( new Item("wurst", Unit.GRAMMS, 5000)); savedItems.add( new Item("wurst", Unit.g, 5000));
savedItems.add( new Item("schinken", Unit.GRAMMS, 5000)); savedItems.add( new Item("schinken", Unit.g, 5000));
savedItems.add( new Item("brokkoli", Unit.GRAMMS, 5000)); savedItems.add( new Item("brokkoli", Unit.g, 5000));
savedItems.add( new Item("eiscreme", Unit.GRAMMS, 5000)); savedItems.add( new Item("eiscreme", Unit.g, 5000));
itemRepository.saveAll(savedItems); itemRepository.saveAll(savedItems);
@@ -71,7 +71,7 @@ final class ItemTests {
@Test @Test
public void deleteTest() { public void deleteTest() {
Item item = new Item("elefantenfuß", Unit.GRAMMS, 5000); Item item = new Item("elefantenfuß", Unit.g, 5000);
itemRepository.save(item); itemRepository.save(item);
assertEquals(item, itemRepository.findById(item.getId()).get()); assertEquals(item, itemRepository.findById(item.getId()).get());
itemRepository.delete(item); itemRepository.delete(item);
@@ -80,7 +80,7 @@ final class ItemTests {
@Test @Test
public void updateTest() { public void updateTest() {
Item item = new Item("schokoküsse", Unit.GRAMMS, 5000); Item item = new Item("schokoküsse", Unit.g, 5000);
itemRepository.save(item); itemRepository.save(item);
long itemCount = itemRepository.count(); long itemCount = itemRepository.count();
item.setQuantity(4574); item.setQuantity(4574);

View File

@@ -95,6 +95,8 @@
</v-row> </v-row>
</div> </div>
<!-- response element --> <!-- response element -->
<div class="item-section" v-show="items.length" v-cloak> <div class="item-section" v-show="items.length" v-cloak>
@@ -138,6 +140,8 @@ const Items = {
return { return {
items: [], items: [],
newItem: '', newItem: '',
newQuantity: 0,
newUnit: '',
editedItem: null, editedItem: null,
loading: true, loading: true,
error: null, error: null,
@@ -163,29 +167,29 @@ const Items = {
return this.activeUser ? this.activeUser.email : '' return this.activeUser ? this.activeUser.email : ''
}, },
inputPlaceholder: function () { 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: { methods: {
addItem: function () { addItem: function () {
var value = this.newItem && this.newItem.trim() const addableItem = this.newItem && this.newItem.trim();
if (!value) { const addableQuantity = parseInt(this.newQuantity);
const addableUnit = this.newUnit;
if (!addableItem) {
return return
} }
var components = value.split(' ') api.createNew(addableItem,
addableQuantity,
api.createNew(components[0], addableUnit
parseInt(components[1].replace(/[^\d.]/g, '')),
components[1].replace(/[0-9]/g, '') === 'ml' ? 'MILLILETERS' : "GRAMMS"
).then((response) => { ).then((response) => {
this.$log.debug("New item created:", response); this.$log.debug("New item created:", response);
this.items.push({ this.items.push({
id: response.data.id, id: response.data.id,
name: components[0], name: addableItem,
quantity: parseInt(components[1].replace(/[^\d.]/g, '')), quantity: addableQuantity,
unit: components[1].replace(/[0-9]/g, '') === 'MILLILETERS' ? 'ml' : 'g' unit: addableUnit
}) })
}).catch((error) => { }).catch((error) => {
this.$log.debug(error); this.$log.debug(error);
@@ -218,10 +222,6 @@ export default Items
</script> </script>
<style lang="scss"> <style lang="scss">
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200&display=swap');
@@ -284,7 +284,7 @@ body{
position: relative; position: relative;
z-index: 5; z-index: 5;
width: 20vh; width: 20vh;
height: 3vh; height: 2vh;
} }
.newItemName { .newItemName {

View File

@@ -316,11 +316,11 @@ body{
/* Workaround for below WQHD resolution */ /* Workaround for below WQHD resolution */
@media screen and (max-height: 1400px) { //@media screen and (max-height: 1400px) {
.formLabel{ // .formLabel{
opacity: 0; // opacity: 0;
} // }
} //}
/* item section */ /* item section */

View File

@@ -36,6 +36,7 @@
.menu-icon { .menu-icon {
position: relative; position: relative;
padding: 0.5vh 0.5vh; padding: 0.5vh 0.5vh;
top: 2vh;
cursor: pointer; cursor: pointer;
z-index: 1; z-index: 1;
display: none; display: none;
@@ -75,6 +76,7 @@
.logo{ .logo{
position: relative; position: relative;
padding: 0.5vh 0.5vh; padding: 0.5vh 0.5vh;
top: 2vh;
} }
.logo:hover { .logo:hover {