Commit b0716979 authored by Kutzner's avatar Kutzner 🤸
Browse files

add prod and dev mode

parent e8c0a006
......@@ -31,13 +31,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
-->
<dependency>
<groupId>org.postgresql</groupId>
......
......@@ -63,6 +63,54 @@ public class ShoppingAPI {
return item;
}
@PostMapping(path = "/shoppingItem/{item}/{amount}", produces = "application/json")
public ShoppingItem addShoppingItemJSON(@PathVariable String item, @PathVariable int amount){
ShoppingItem newItem = new ShoppingItem(item);
Iterable<ShoppingItem> iterableItems = shoppingItemRepository.findAll();
Iterator<ShoppingItem> itemTerator = iterableItems.iterator();
while(itemTerator.hasNext()){
ShoppingItem tempItem = itemTerator.next();
if (tempItem.item.equals(item)) {
logger.info("----- ADD Item with Amount-----");
int newAmount = tempItem.amount + amount;
newItem.setId(tempItem.id);
newItem.setAmount(newAmount);
shoppingItemRepository.save(newItem);
logger.info("new id = {}", tempItem.id);
logger.info("new item = {}", tempItem.item);
logger.info("amount = {}", newAmount);
//return "Increased Amount (from " + (tempItem.amount - amount) + " to " + newItem.amount + ") of " + newItem.item + " successfully in shoppingItemRepository";
return newItem;
}
}
newItem.setAmount(amount);
shoppingItemRepository.save(newItem);
logger.info("----- ADD Item with Amount-----");
logger.info("new id = {}", newItem.id);
logger.info("new item = {}", newItem.item);
logger.info("amount = {}", amount);
//return "Added " + newItem.item + " with an Amount of " + amount + " successfully to shoppingItemRepository";
return newItem;
}
@PostMapping("/shoppingItem/{item}")
public String addShoppingItem(@PathVariable String item){
......@@ -120,12 +168,15 @@ public class ShoppingAPI {
logger.info("----- UPDATE Item -----");
logger.info("old id = {}", tempItem.id);
logger.info("old item = {}", tempItem.item);
logger.info("old amount = {}", tempItem.amount);
myNewItem.setId(tempItem.id);
myNewItem.setItem(new_item);
myNewItem.setAmount(tempItem.amount);
logger.info("new id ={}", myNewItem.id);
logger.info("new item ={}", myNewItem.item);
logger.info("new amount ={}", myNewItem.amount);
shoppingItemRepository.save(myNewItem);
......@@ -206,7 +257,7 @@ public class ShoppingAPI {
logger.info("----- DELETE Item-----");
logger.info("delete id = {}", tempItem.id);
logger.info("delete item = {}", tempItem.item);
logger.info("delete amount = {}", tempItem.item);
logger.info("delete amount = {}", tempItem.amount);
shoppingItemRepository.delete(tempItem);
return "Deleted " + tempItem.item + " sucessfully";
......
......@@ -21,6 +21,16 @@ public class ShoppingItem {
item = itemName;
}
public ShoppingItem(String itemName, int itemAmount){
amount = itemAmount;
}
public ShoppingItem(long itemId, String itemName, int itemAmount){
id = itemId;
}
/* ********** *********** ********** */
......
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
\ No newline at end of file
spring.datasource.url=jdbc:postgresql://localhost:5432/kebidgedata
spring.datasource.username=kebidge
spring.datasource.password=password
spring.jpa.show-sql=false
\ No newline at end of file
spring.datasource.url=jdbc:postgresql://localhost:5432/kebidgedata
spring.datasource.username=kebidge
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
server.port = 8181
logging.level.de.kebidge=INFO
\ No newline at end of file
logging.level.de.kebidge=INFO
spring.profiles.active=prod
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment