aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItem.java10
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItemController.java11
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItemRepository.java4
-rw-r--r--src/test/java/dev/submelon/pantry/ItemRepositoryTests.java8
4 files changed, 14 insertions, 19 deletions
diff --git a/src/main/java/dev/submelon/pantry/PantryItem.java b/src/main/java/dev/submelon/pantry/PantryItem.java
index 36850bf..459c3b7 100644
--- a/src/main/java/dev/submelon/pantry/PantryItem.java
+++ b/src/main/java/dev/submelon/pantry/PantryItem.java
@@ -24,17 +24,17 @@ public class PantryItem {
private String description;
- @Column(unique=true, nullable=false)
- private String shortid;
-
@Column(nullable=false)
private double quantity;
+
+ @Column(nullable=false)
+ private String quantityUnitType;
- public PantryItem(String name, String description, String shortid, double quantity) {
+ public PantryItem(String name, String description, double quantity, String quantityUnitType) {
this.name = name;
this.description = description;
- this.shortid = shortid;
this.quantity = quantity;
+ this.quantityUnitType = quantityUnitType;
}
}
diff --git a/src/main/java/dev/submelon/pantry/PantryItemController.java b/src/main/java/dev/submelon/pantry/PantryItemController.java
index 37a71e9..1968139 100644
--- a/src/main/java/dev/submelon/pantry/PantryItemController.java
+++ b/src/main/java/dev/submelon/pantry/PantryItemController.java
@@ -3,7 +3,6 @@ package dev.submelon.pantry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -17,12 +16,12 @@ public class PantryItemController {
@PostMapping(path="/add")
@ResponseBody
- Integer addNewItem(@RequestParam String name, @RequestParam String description, @RequestParam String shortid, @RequestParam double quantity) {
+ Integer addNewItem(@RequestParam String name, @RequestParam String description, @RequestParam double quantity, @RequestParam String quantityUnitType) {
PantryItem item = new PantryItem();
item.setName(name);
item.setDescription(description);
- item.setShortid(shortid);
item.setQuantity(quantity);
+ item.setQuantityUnitType(quantityUnitType);
PantryItem updatedItem = itemRepository.save(item);
return updatedItem.getId();
@@ -34,10 +33,4 @@ public class PantryItemController {
return itemRepository.findAll();
}
- @GetMapping(path="/{shortid}")
- @ResponseBody
- PantryItem getByShortid(@PathVariable String shortid) {
- return itemRepository.findByShortid(shortid).get();
- }
-
}
diff --git a/src/main/java/dev/submelon/pantry/PantryItemRepository.java b/src/main/java/dev/submelon/pantry/PantryItemRepository.java
index 7808186..24b4bee 100644
--- a/src/main/java/dev/submelon/pantry/PantryItemRepository.java
+++ b/src/main/java/dev/submelon/pantry/PantryItemRepository.java
@@ -5,5 +5,7 @@ import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
public interface PantryItemRepository extends CrudRepository<PantryItem, Integer> {
- Optional<PantryItem> findByShortid(String shortid);
+
+ Optional<PantryItem> findByName(String name);
+
}
diff --git a/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java b/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java
index f2f16ce..1f890d8 100644
--- a/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java
+++ b/src/test/java/dev/submelon/pantry/ItemRepositoryTests.java
@@ -19,9 +19,9 @@ public class ItemRepositoryTests {
@BeforeAll
public void before() throws Exception {
- PantryItem pb = new PantryItem("Peanut Butter", "Crunchy", "crunchy-pb", 14.0);
- PantryItem jelly = new PantryItem("Strawberry Preserves", "The best", "sb-preserves", 12.8);
- PantryItem bread = new PantryItem("Oatnut Bread", "Relatively healthy, right?", "oatnut-bread", 10);
+ PantryItem pb = new PantryItem("Peanut Butter", "Crunchy", 14.0, "oz");
+ PantryItem jelly = new PantryItem("Strawberry Preserves", "The best", 12.8, "oz");
+ PantryItem bread = new PantryItem("Oatnut Bread", "Relatively healthy, right?", 10, "slices");
assertNull(pb.getId());
assertNull(jelly.getId());
assertNull(bread.getId());
@@ -35,7 +35,7 @@ public class ItemRepositoryTests {
@Test
public void testFetchData() {
- PantryItem pb = itemRepository.findByShortid("crunchy-pb").get();
+ PantryItem pb = itemRepository.findByName("Peanut Butter").get();
assertNotNull(pb);
assertEquals(14.0, pb.getQuantity());
Iterable<PantryItem> items = itemRepository.findAll();