diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..dfe0770
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c35a6bb
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ BootCamp2018
+ Juan
+ 1.0-SNAPSHOT
+
+
+
+ mysql
+ mysql-connector-java
+ 8.0.11
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
+
+
+ javax.servlet.jsp
+ javax.servlet.jsp-api
+ 2.3.1
+
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
+
+ commons-logging
+ commons-logging
+ 1.2
+
+
+
+ org.springframework
+ spring-webmvc
+ 5.0.6.RELEASE
+
+
+ org.springframework
+ spring-tx
+ 5.0.6.RELEASE
+
+
+ org.springframework
+ spring-orm
+ 5.0.6.RELEASE
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+
+
+
+
+ 1.8
+ 1.8
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/bootcamp2018/Main.java b/src/main/java/com/bootcamp2018/Main.java
new file mode 100644
index 0000000..895eda0
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/Main.java
@@ -0,0 +1,357 @@
+package com.bootcamp2018;
+
+import com.bootcamp2018.dao.*;
+
+import com.bootcamp2018.model.*;
+import com.bootcamp2018.service.DiscountService;
+import com.bootcamp2018.service.ItemService;
+import com.bootcamp2018.util.Utility;
+
+
+import java.util.ArrayList;
+import java.util.Scanner;
+
+
+public class Main {
+
+ public static void main(String[] Arg) {
+ int op = 0;
+ boolean ban = false;
+ String menu;
+ ItemDAO itemDAO = new ItemDAO();
+ Scanner scanner = new Scanner(System.in);
+ ArrayList- listOfItems;
+ ItemService is;
+ try {
+ while (op != 3) {
+ System.out.println("Menu");
+ System.out.println("1.Enter as Admin");
+ System.out.println("2.Enter as Client");
+ System.out.println("3.Exit");
+ ban = false;
+ menu = scanner.next();
+ if (Utility.isInt(menu)) {
+ op = Integer.parseInt(menu);
+ switch (op) {
+ case 1:
+ op = 0;
+ while (op != 5) {
+ System.out.println("Admin Menu");
+ System.out.println("1.Item Menu");
+ System.out.println("2.Discount Menu");
+ System.out.println("3.Payment Menu");
+ System.out.println("4.Clients Menu");
+ System.out.println("5.Exit");
+ menu = scanner.next();
+ if (Utility.isInt(menu)) {
+ op = Integer.parseInt(menu);
+ switch (op) {
+ case 1:
+ op = 0;
+ while (op != 5) {
+ System.out.println("Item Menu");
+ System.out.println("1.Create Item");
+ System.out.println("2.Retrieve Items");
+ System.out.println("3.Update Item");
+ System.out.println("4.Delete Item");
+ System.out.println("5.Exit");
+ menu = scanner.next();
+ if (Utility.isInt(menu)) {
+ op = Integer.parseInt(menu);
+ switch (op) {
+ case 1:
+ while (!ban) {
+ System.out.println("Enter item name: ");
+ String name = scanner.next();
+ if (name != null) {
+ while (!ban) {
+ System.out.println("Enter item price: ");
+ String prices = scanner.next();
+ if (Utility.isDouble(prices)) {
+ double price = Double.parseDouble(prices);
+ is = new ItemService();
+ Item created = is.create(new Item(name, price));
+ if (created == null) {
+ System.out.println("Error");
+ }
+ ban = true;
+
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ break;
+ case 2:
+ System.out.println("List of Items: ");
+ is = new ItemService();
+ listOfItems = is.getList(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ scanner.next();
+ break;
+ case 3:
+ ban = false;
+ while (!ban) {
+ System.out.println("List of Items: ");
+ listOfItems = itemDAO.retriveItems(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ System.out.println("Enter Item Code to modify: ");
+ String code = scanner.next();
+ if (Utility.isInt(code) && listOfItems.contains(new Item(Integer.parseInt(code), "", 0))) {
+ while (!ban) {
+ Item updateItem = listOfItems.get(listOfItems.indexOf(new Item(Integer.parseInt(code), "", 0)));
+ System.out.println("Item current name is: " + updateItem.getName() + ", enter new name: ");
+ String name = scanner.next();
+ if (name != null) {
+ updateItem.setName(name);
+ while (!ban) {
+ System.out.println("Enter item price: ");
+ String prices = scanner.next();
+ if (Utility.isDouble(prices)) {
+
+ updateItem.setPrice(Double.parseDouble(prices));
+ is = new ItemService();
+ is.update(updateItem);
+
+ if (!ban) {
+ System.out.println("Error");
+ ban = true;
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+
+ }
+ }
+ }
+ break;
+ case 4:
+ System.out.println("List of Items: ");
+ is = new ItemService();
+ listOfItems = is.getList(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ System.out.println("Enter the code of the item you want to delete: ");
+ String code = scanner.next();
+ if (Utility.isInt(code)) {
+ is = new ItemService();
+ is.delete(new Item(Integer.parseInt(code), "", 0));
+ }
+ break;
+ case 5:
+ break;
+ default:
+ System.out.println("Number must be between 1 and 5");
+ break;
+ }
+ }
+ }
+ break;
+ case 2:
+ op = 0;
+ while (op != 5) {
+ System.out.println("Discount Menu");
+ System.out.println("1.Create Discount");
+ System.out.println("2.Retrieve Discount");
+ System.out.println("3.Update Discount");
+ System.out.println("4.Delete Discount");
+ System.out.println("5.Exit");
+ menu = scanner.next();
+ if (Utility.isInt(menu)) {
+ op = Integer.parseInt(menu);
+ switch (op) {
+ case 1:
+ while (!ban) {
+ System.out.println("List of Items: ");
+ is = new ItemService();
+ listOfItems = is.getList(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ System.out.println("Enter code of the item for the discount: ");
+ String code = scanner.next();
+ if (Utility.isInt(code) && listOfItems.contains(new Item(Integer.parseInt(code), "", 0))) {
+ Item discountItem = listOfItems.get(listOfItems.indexOf(new Item(Integer.parseInt(code), "", 0)));
+ while (!ban) {
+ System.out.println("Enter the price for each " + discountItem.getName() + ": ");
+ String prices = scanner.next();
+ if (Utility.isDouble(prices)) {
+ double price = Double.parseDouble(prices);
+ while (!ban) {
+ System.out.println("Enter the quantity of " + discountItem.getName() + ": ");
+ String quantities = scanner.next();
+ if (Utility.isInt(quantities)) {
+ int quantity = Integer.parseInt(quantities);
+ DiscountService ds = new DiscountService();
+ Discount discount = ds.create(new Discount(discountItem, quantity, price));
+ if (discount.getId() == 0) {
+ System.out.println("error");
+
+ }
+ ban = true;
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ break;
+ case 2:
+ System.out.println("List of Items: ");
+ is = new ItemService();
+ listOfItems = is.getList(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ scanner.next();
+ break;
+ case 3:
+ ban = false;
+ while (!ban) {
+ System.out.println("List of Items: ");
+ listOfItems = itemDAO.retriveItems(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ System.out.println("Enter Item Code to modify: ");
+ String code = scanner.next();
+ if (Utility.isInt(code) && listOfItems.contains(new Item(Integer.parseInt(code), "", 0))) {
+ while (!ban) {
+ Item updateItem = listOfItems.get(listOfItems.indexOf(new Item(Integer.parseInt(code), "", 0)));
+ System.out.println("Item current name is: " + updateItem.getName() + ", enter new name: ");
+ String name = scanner.next();
+ if (name != null) {
+ updateItem.setName(name);
+ while (!ban) {
+ System.out.println("Enter item price: ");
+ String prices = scanner.next();
+ if (Utility.isDouble(prices)) {
+
+ updateItem.setPrice(Double.parseDouble(prices));
+ is = new ItemService();
+ is.update(updateItem);
+
+ if (!ban) {
+ System.out.println("Error");
+ ban = true;
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+ }
+ } else {
+ System.out.println("Please enter a valid value.");
+ }
+
+ }
+ }
+ }
+ break;
+ case 4:
+ System.out.println("List of Items: ");
+ is = new ItemService();
+ listOfItems = is.getList(new Item());
+ for (Item i : listOfItems
+ ) {
+ System.out.println(i.toString());
+ }
+ System.out.println("Enter the code of the item you want to delete: ");
+ String code = scanner.next();
+ if (Utility.isInt(code)) {
+ is = new ItemService();
+ is.delete(new Item(Integer.parseInt(code), "", 0));
+ }
+ break;
+ case 5:
+ break;
+ default:
+ System.out.println("Number must be between 1 and 5");
+ break;
+ }
+ }
+ }
+ break;
+ case 3:
+ break;
+ case 4:
+ break;
+ case 5:
+ break;
+ default:
+ System.out.println("Number must be between 1 and 5");
+ break;
+ }
+ }
+ }
+ break;
+ case 2:
+
+ break;
+ case 3:
+ break;
+ default:
+ System.out.println("Number must be between 1 and 3 ");
+ break;
+ }
+
+ }
+
+
+ }
+
+ } catch (Exception e) {
+
+ }
+
+
+ }
+
+ private static boolean isInt(String s) {
+ try {
+ Integer.parseInt(s);
+ } catch (NumberFormatException e) {
+ return false;
+ } catch (NullPointerException e) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean isDouble(String s) {
+ try {
+ Double.parseDouble(s);
+ } catch (NumberFormatException e) {
+ return false;
+ } catch (NullPointerException e) {
+ return false;
+ }
+ return true;
+ }
+
+
+}
diff --git a/src/main/java/com/bootcamp2018/control/ClientControl.java b/src/main/java/com/bootcamp2018/control/ClientControl.java
new file mode 100644
index 0000000..8cd6a6e
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/ClientControl.java
@@ -0,0 +1,36 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.model.Client;
+
+import java.util.ArrayList;
+
+
+
+public class ClientControl {
+
+
+
+ public Client create(Client Object) {
+ return null;
+ }
+
+
+ public Client get(Client Object) {
+ return null;
+ }
+
+
+ public ArrayList getList(Client Objact) {
+ return null;
+ }
+
+ public Client update(Client Object) {
+ return null;
+ }
+
+
+ public void delete(Client Object) {
+
+ }
+ //DTO class ver patron
+}
diff --git a/src/main/java/com/bootcamp2018/control/DiscountControl.java b/src/main/java/com/bootcamp2018/control/DiscountControl.java
new file mode 100644
index 0000000..0ecaf2c
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/DiscountControl.java
@@ -0,0 +1,34 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.dao.DiscountDAO;
+import com.bootcamp2018.model.Discount;
+
+import java.util.ArrayList;
+
+public class DiscountControl {
+
+ public Discount create(Discount object) {
+ DiscountDAO dDAO = new DiscountDAO();
+ return dDAO.createDiscount(object);
+ }
+
+
+ public Discount get(Discount object) {
+ return null;
+ }
+
+
+ public ArrayList getList(Discount object) {
+ return null;
+ }
+
+
+ public Discount update(Discount object) {
+ return null;
+ }
+
+
+ public void delete(Discount object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/control/ItemControl.java b/src/main/java/com/bootcamp2018/control/ItemControl.java
new file mode 100644
index 0000000..7104a29
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/ItemControl.java
@@ -0,0 +1,53 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.dao.ItemDAO;
+import com.bootcamp2018.model.Item;
+import com.sun.org.glassfish.gmbal.ParameterNames;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.PostConstruct;
+import java.lang.reflect.Parameter;
+import java.util.ArrayList;
+
+@Controller
+@RequestMapping("/item")
+public class ItemControl {
+
+
+ @RequestMapping
+ public Item create(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.createItem(object);
+ }
+
+ @RequestMapping(value="/")
+ public ResponseEntity
- get(@RequestBody Item item) {
+ ItemDAO itemDAO = new ItemDAO();
+ item = itemDAO.retriveItem(item.getId());
+ return new ResponseEntity
- (item,HttpStatus.OK);
+ }
+
+ public ArrayList
- getList(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.retriveItems(object);
+ }
+
+
+ public Item update(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.updateItem(object);
+ }
+
+
+ public void delete(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ itemDAO.deleteItem(object);
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/control/OrderControl.java b/src/main/java/com/bootcamp2018/control/OrderControl.java
new file mode 100644
index 0000000..9cc3888
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/OrderControl.java
@@ -0,0 +1,33 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.dto.OrderDTO;
+
+import java.util.ArrayList;
+
+
+public class OrderControl {
+
+ public OrderDTO create(OrderDTO Object) {
+ return null;
+ }
+
+
+ public OrderDTO get(OrderDTO Object) {
+ return null;
+ }
+
+
+ public ArrayList getList(OrderDTO Object) {
+ return null;
+ }
+
+
+ public OrderDTO update(OrderDTO Object) {
+ return null;
+ }
+
+
+ public void delete(OrderDTO Object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/control/OrderDetailControl.java b/src/main/java/com/bootcamp2018/control/OrderDetailControl.java
new file mode 100644
index 0000000..14445c7
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/OrderDetailControl.java
@@ -0,0 +1,32 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.dto.OrderDetailDTO;
+
+import java.util.ArrayList;
+
+public class OrderDetailControl {
+
+ public OrderDetailDTO create(OrderDetailDTO Object) {
+
+ return Object;
+ }
+
+
+ public OrderDetailDTO get(OrderDetailDTO Object) {
+ return null;
+ }
+
+
+ public ArrayList getList(OrderDetailDTO Object) {
+ return null;
+ }
+
+
+ public OrderDetailDTO update(OrderDetailDTO Object) {
+ return null;
+ }
+
+
+ public void delete(OrderDetailDTO Object) {
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/control/PaymentControl.java b/src/main/java/com/bootcamp2018/control/PaymentControl.java
new file mode 100644
index 0000000..eba41fa
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/control/PaymentControl.java
@@ -0,0 +1,39 @@
+package com.bootcamp2018.control;
+
+import com.bootcamp2018.dto.PaymentDTO;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+
+import java.util.ArrayList;
+@Controller
+@RequestMapping("/")
+public class PaymentControl {
+
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public PaymentDTO create(PaymentDTO Object) {
+ return Object;
+ }
+
+
+ public PaymentDTO get(PaymentDTO Object) {
+ return null;
+ }
+
+
+ public ArrayList getList(PaymentDTO Object) {
+ return null;
+ }
+
+
+ public PaymentDTO update(PaymentDTO Object) {
+ return null;
+ }
+
+ public void delete(PaymentDTO Object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dao/ClientDAO.java b/src/main/java/com/bootcamp2018/dao/ClientDAO.java
new file mode 100644
index 0000000..bc03155
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/ClientDAO.java
@@ -0,0 +1,105 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.model.*;
+
+import java.sql.*;
+import java.util.ArrayList;
+
+public class ClientDAO {
+
+ public Client createClient(Client client) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("INSERT INTO client (name,lastName, description) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setString(1, client.getName());
+ pstmt.setString(2, client.getLastName());
+ pstmt.setString(3, client.getDescription());
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (rs.next()) {
+ client.setId(rs.getInt(1));
+ } else {
+ client.setId(-1);
+ }
+ pstmt.close();
+ } catch (Exception e) {
+ }
+ return new Client();
+ }
+
+ public ArrayList getClients() throws SQLException {
+ ArrayList list = new ArrayList<>();
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("SELECT idClient, name, lastName, description FROM client");
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ list.add(ClientCreator.mapClient(rs));
+ }
+ } catch (Exception e) {
+ }
+ return list;
+ }
+
+ public Client getClient(Client cli) throws SQLException {
+ Client client = new Client();
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("SELECT idClient, name, lastName, description FROM client WHERE idClient=?");
+ pstmt.setString(1, cli.getName());
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ client = ClientCreator.mapClient(rs);
+ }
+ } catch (Exception e) {
+ }
+ return client;
+ }
+
+
+ public Client deleteItem(Client client) {
+
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("DELETE FROM client WHERE idClient = ?");
+ pstmt.setInt(1, client.getId());
+ int resp = pstmt.executeUpdate();
+ if (resp == 0) client = new Client();
+
+ } catch (Exception e) {
+ client = new Client();
+ }
+ return client;
+ }
+
+ public Client updateItem(Client client) throws SQLException {
+
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("UPDATE client SET name = ?, lastName = ?, description = ? WHERE idClient= ?");
+ pstmt.setString(1, client.getName());
+ pstmt.setString(2, client.getLastName());
+ pstmt.setString(3, client.getDescription());
+ pstmt.setInt(4, client.getId());
+
+ int resp = pstmt.executeUpdate();
+ if (resp == 0) client = new Client();
+
+ } catch (Exception e) {
+ client = new Client();
+ }
+ return client;
+ }
+
+
+ static class ClientCreator {
+
+ private static Client mapClient(ResultSet resultSet) throws SQLException {
+ Client client;
+ client = new Client(resultSet.getInt(1), resultSet.getString(2), resultSet.getNString(3), resultSet.getNString(4));
+ return client;
+ }
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dao/DiscountDAO.java b/src/main/java/com/bootcamp2018/dao/DiscountDAO.java
new file mode 100644
index 0000000..f677e28
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/DiscountDAO.java
@@ -0,0 +1,38 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.model.Discount;
+import com.bootcamp2018.model.Item;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class DiscountDAO {
+
+
+ public Discount createDiscount(Discount discount) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("INSERT INTO discount (idItem, quantity, price) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setInt(1, discount.getItem().getId());
+ pstmt.setInt(2, discount.getQuantity());
+ pstmt.setDouble(3, discount.getPrice());
+
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (rs.next()) {
+ discount.setId(rs.getInt(1));
+ } else {
+ discount = new Discount();
+ }
+ pstmt.close();
+ } catch (Exception e) {
+
+ }
+
+ return discount;
+ }
+
+}
diff --git a/src/main/java/com/bootcamp2018/dao/ItemDAO.java b/src/main/java/com/bootcamp2018/dao/ItemDAO.java
new file mode 100644
index 0000000..ecce0ed
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/ItemDAO.java
@@ -0,0 +1,96 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.model.Item;
+
+import java.sql.*;
+import java.util.ArrayList;
+
+
+public class ItemDAO {
+
+
+ public Item createItem(Item item) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("INSERT INTO item (Name,Price) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setString(1, item.getName());
+ pstmt.setDouble(2, item.getPrice());
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (rs.next()) {
+ item.setId(rs.getInt(1));
+ } else {
+ item = new Item();
+ }
+ pstmt.close();
+ } catch (Exception e) {
+
+ }
+
+ return item;
+ }
+
+ public ArrayList
- retriveItems(Item objects) {
+ ArrayList
- list = new ArrayList<>();
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("SELECT idItem, name, price FROM item");
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ list.add(new Item(rs.getInt(1), rs.getString(2), rs.getDouble(3)));
+ }
+ } catch (Exception e) {
+ }
+
+ return list;
+
+ }
+
+ public Item retriveItem(int id) {
+ Item list = new Item();
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("SELECT idItem, name, price FROM item");
+
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ list = new Item(rs.getInt(1), rs.getString(2), rs.getDouble(3));
+ }
+ } catch (Exception e) {
+ }
+ return list;
+ }
+
+
+ public void deleteItem(Item item) {
+
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("DELETE FROM item WHERE idItem = ?");
+ pstmt.setInt(1, item.getId());
+ pstmt.executeUpdate();
+ } catch (Exception e) {
+
+ }
+ }
+
+ public Item updateItem(Item item) {
+
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("UPDATE item SET name = ?, price= ? WHERE idItem= ?");
+ pstmt.setString(1, item.getName());
+ pstmt.setDouble(2, item.getPrice());
+ pstmt.setInt(3, item.getId());
+
+ int resp = pstmt.executeUpdate();
+ if (resp == 0) item = new Item();
+
+ } catch (Exception e) {
+ item = new Item();
+ }
+ return item;
+ }
+// CRear clase que con ReturnSet me de el objeto que yo toque o la lista de objetos que yo toque;
+}
diff --git a/src/main/java/com/bootcamp2018/dao/OrderDAO.java b/src/main/java/com/bootcamp2018/dao/OrderDAO.java
new file mode 100644
index 0000000..f7a18ea
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/OrderDAO.java
@@ -0,0 +1,41 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.dto.OrderDTO;
+
+import com.bootcamp2018.dto.OrderDetailDTO;
+import com.bootcamp2018.model.Order;
+import com.bootcamp2018.model.OrderDetail;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class OrderDAO {
+ public Order createOrder(OrderDTO order) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+
+ PreparedStatement pstmt;
+
+ pstmt = con.prepareStatement("INSERT INTO Order (idPayment) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setInt(1, order.getIdPayment());
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (rs.next()) {
+ order.getOrder().setId(rs.getInt(1));
+ for (OrderDetail od : order.getOrder().getOrderDetails()
+ ) {
+ OrderDetailDAO odd = new OrderDetailDAO();
+ od = odd.createOrderDetail(new OrderDetailDTO(order.getOrder().getId(), od));
+ }
+ } else {
+ order.setOrder(new Order());
+ }
+ pstmt.close();
+ } catch (Exception e) {
+ order.setOrder(new Order());
+ }
+ return order.getOrder();
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dao/OrderDetailDAO.java b/src/main/java/com/bootcamp2018/dao/OrderDetailDAO.java
new file mode 100644
index 0000000..0179022
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/OrderDetailDAO.java
@@ -0,0 +1,37 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.dto.OrderDetailDTO;
+import com.bootcamp2018.dto.PaymentDTO;
+import com.bootcamp2018.model.OrderDetail;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class OrderDetailDAO {
+
+ public OrderDetail createOrderDetail(OrderDetailDTO orderDetail) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+
+ PreparedStatement pstmt;
+
+ pstmt = con.prepareStatement("INSERT INTO OrderDetail (idItem,idOrder,quantity, price) VALUES (?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setInt(1, orderDetail.getOrderDetail().getItem().getId());
+ pstmt.setInt(2, orderDetail.getIdOrder());
+ pstmt.setInt(2, orderDetail.getOrderDetail().getQuantity());
+ pstmt.setDouble(2, orderDetail.getOrderDetail().getPrice());
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (!rs.next()) {
+ orderDetail.setOrderDetail(new OrderDetail());
+ }
+ pstmt.close();
+ } catch (Exception e) {
+ orderDetail.setOrderDetail(new OrderDetail());
+ }
+ return orderDetail.getOrderDetail();
+ }
+
+}
diff --git a/src/main/java/com/bootcamp2018/dao/PaymentDAO.java b/src/main/java/com/bootcamp2018/dao/PaymentDAO.java
new file mode 100644
index 0000000..18068e5
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dao/PaymentDAO.java
@@ -0,0 +1,35 @@
+package com.bootcamp2018.dao;
+
+import com.bootcamp2018.db.DBConnection;
+import com.bootcamp2018.dto.OrderDTO;
+import com.bootcamp2018.dto.PaymentDTO;
+
+import com.bootcamp2018.model.Payment;
+
+import java.sql.*;
+
+
+public class PaymentDAO {
+
+ public Payment createPayment(PaymentDTO payment) {
+ try (Connection con = DBConnection.getInstance().getDataSource().getConnection()) {
+ PreparedStatement pstmt;
+ pstmt = con.prepareStatement("INSERT INTO payment (idClient, amount) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
+ pstmt.setInt(1, payment.getIdClient());
+ pstmt.setDouble(2, payment.getPayment().getAmount());
+ pstmt.executeUpdate();
+ ResultSet rs = pstmt.getGeneratedKeys();
+ if (rs.next()) {
+ payment.getPayment().setId(rs.getInt(1));
+ OrderDAO od = new OrderDAO();
+ od.createOrder(new OrderDTO(payment.getPayment().getId(), payment.getPayment().getOrder()));
+ } else {
+ payment = new PaymentDTO();
+ }
+ pstmt.close();
+ } catch (Exception e) {
+ payment = new PaymentDTO();
+ }
+ return payment.getPayment();
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/db/DBConnection.java b/src/main/java/com/bootcamp2018/db/DBConnection.java
new file mode 100644
index 0000000..0f7078d
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/db/DBConnection.java
@@ -0,0 +1,40 @@
+package com.bootcamp2018.db;
+
+import com.mysql.cj.jdbc.MysqlDataSource;
+import org.graalvm.compiler.serviceprovider.ServiceProvider;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DBConnection {
+ @Autowired
+ private static DBConnection ourInstance = null;
+ @Autowired
+ private static MysqlDataSource ds = new MysqlDataSource();
+
+ public static DBConnection getInstance() {
+ if (ourInstance == null) {
+ ourInstance = new DBConnection();
+ }
+ return ourInstance;
+ }
+
+ private DBConnection() {
+ try {
+ ds = new MysqlDataSource();
+ ds.setServerName("localhost");
+ ds.setDatabaseName("boot2018");
+ ds.setPortNumber(3306);
+ ds.setUser("root");
+ ds.setPassword("Meteora218!");
+
+ } catch (Exception e) {
+ System.out.println("fail");
+ }
+ }
+
+
+ public static MysqlDataSource getDataSource() {
+ return ds;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dto/OrderDTO.java b/src/main/java/com/bootcamp2018/dto/OrderDTO.java
new file mode 100644
index 0000000..98d7777
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dto/OrderDTO.java
@@ -0,0 +1,30 @@
+package com.bootcamp2018.dto;
+
+
+import com.bootcamp2018.model.Order;
+
+public class OrderDTO {
+ private int idPayment;
+ private Order order;
+
+ public OrderDTO(int idPayment, Order order) {
+ this.idPayment = idPayment;
+ this.order = order;
+ }
+
+ public int getIdPayment() {
+ return idPayment;
+ }
+
+ public void setIdPayment(int idPayment) {
+ this.idPayment = idPayment;
+ }
+
+ public Order getOrder() {
+ return order;
+ }
+
+ public void setOrder(Order order) {
+ this.order = order;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dto/OrderDetailDTO.java b/src/main/java/com/bootcamp2018/dto/OrderDetailDTO.java
new file mode 100644
index 0000000..4f3f675
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dto/OrderDetailDTO.java
@@ -0,0 +1,29 @@
+package com.bootcamp2018.dto;
+
+import com.bootcamp2018.model.OrderDetail;
+
+public class OrderDetailDTO {
+ private int idOrder;
+ private OrderDetail orderDetail;
+
+ public OrderDetailDTO(int idOrder, OrderDetail orderDetail) {
+ this.idOrder = idOrder;
+ this.orderDetail = orderDetail;
+ }
+
+ public int getIdOrder() {
+ return idOrder;
+ }
+
+ public void setIdOrder(int idOrder) {
+ this.idOrder = idOrder;
+ }
+
+ public OrderDetail getOrderDetail() {
+ return orderDetail;
+ }
+
+ public void setOrderDetail(OrderDetail orderDetail) {
+ this.orderDetail = orderDetail;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/dto/PaymentDTO.java b/src/main/java/com/bootcamp2018/dto/PaymentDTO.java
new file mode 100644
index 0000000..b590b80
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/dto/PaymentDTO.java
@@ -0,0 +1,34 @@
+package com.bootcamp2018.dto;
+
+import com.bootcamp2018.model.Payment;
+
+public class PaymentDTO {
+ private Payment payment;
+ private int idClient;
+
+ public PaymentDTO() {
+ payment = new Payment();
+
+ }
+
+ public PaymentDTO(Payment payment, int idClient) {
+ this.payment = payment;
+ this.idClient = idClient;
+ }
+
+ public Payment getPayment() {
+ return payment;
+ }
+
+ public void setPayment(Payment payment) {
+ this.payment = payment;
+ }
+
+ public int getIdClient() {
+ return idClient;
+ }
+
+ public void setIdClient(int idClient) {
+ this.idClient = idClient;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/model/Client.java b/src/main/java/com/bootcamp2018/model/Client.java
new file mode 100644
index 0000000..512006b
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/Client.java
@@ -0,0 +1,113 @@
+package com.bootcamp2018.model;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+@Component
+public class Client {
+ private int id;
+ private String name;
+ private String lastName;
+ private String description;
+ @Autowired
+ private ArrayList Payments;
+
+ public Client(int id) {
+ this.id = id;
+ this.name = "";
+ this.lastName = "";
+ this.description = "";
+ this.Payments = new ArrayList<>();
+ }
+
+ public Client() {
+ this.id = 0;
+ this.name = "";
+ this.lastName = "";
+ this.description = "";
+ this.Payments = new ArrayList<>();
+ }
+
+ public Client(int id, String name, String lastName, String description) {
+ this.id = id;
+ this.name = name;
+ this.lastName = lastName;
+ this.description = description;
+ Payments = new ArrayList<>();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public ArrayList getPayments() {
+ return Payments;
+ }
+
+ public void setPayments(ArrayList payments) {
+ Payments = payments;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!Client.class.isAssignableFrom(obj.getClass())) {
+ return false;
+ }
+ final Client other = (Client) obj;
+
+ if (this.getId() != other.getId()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ String str;
+ str = "Name: " + getName() + ". Last name: " + getLastName();
+ str += "\nDescription: " + getDescription();
+ if (getPayments().size() > 0) {
+ for (Payment p : getPayments()
+ ) {
+ str += "\n" + p.toString();
+ }
+ } else {
+ str += "\nNo payments";
+ }
+ return str;
+
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/model/Discount.java b/src/main/java/com/bootcamp2018/model/Discount.java
new file mode 100644
index 0000000..0ebb927
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/Discount.java
@@ -0,0 +1,69 @@
+package com.bootcamp2018.model;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class Discount {
+ private Item item;
+ private int quantity;
+ private double price;
+ private int id;
+
+ public Discount() {
+
+ this.item = new Item();
+ this.quantity = 0;
+ this.price = 0;
+ this.id = 0;
+ }
+
+ public Discount(Item item, int quantity, double price) {
+ this.item = item;
+ this.quantity = quantity;
+ this.price = price;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int idDiscount) {
+ this.id = idDiscount;
+ }
+
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean ban = false;
+ if (obj != null) {
+ if (Discount.class.isAssignableFrom(obj.getClass())) {
+ final Discount other = (Discount) obj;
+ ban = this.item.equals(other) && this.quantity == other.quantity;
+ }
+ }
+ return ban;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/model/Item.java b/src/main/java/com/bootcamp2018/model/Item.java
new file mode 100644
index 0000000..529b2a7
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/Item.java
@@ -0,0 +1,69 @@
+package com.bootcamp2018.model;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class Item {
+ private int Id;
+ private String name;
+ private double price;
+
+ public Item() {
+ Id = 0;
+ this.name = "";
+ this.price = 0;
+ }
+
+ public Item(String name, double price) {
+ Id = 0;
+ this.name = name;
+ this.price = price;
+ }
+
+ public Item(int id, String name, double price) {
+ Id = id;
+ this.name = name;
+ this.price = price;
+ }
+
+ public int getId() {
+ return Id;
+ }
+
+ public void setId(int id) {
+ Id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean ban = false;
+ if (obj != null) {
+ if (Item.class.isAssignableFrom(obj.getClass())) {
+ final Item other = (Item) obj;
+ ban = this.getId() == other.getId();
+ }
+ }
+ return ban;
+ }
+
+ @Override
+ public String toString() {
+ return "Code: " + getId() + ", Name: " + getName() + ", Price: $" + getPrice();
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/model/Order.java b/src/main/java/com/bootcamp2018/model/Order.java
new file mode 100644
index 0000000..a8def4b
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/Order.java
@@ -0,0 +1,83 @@
+package com.bootcamp2018.model;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+@Component
+public class Order {
+ private int Id;
+ @Autowired
+ private ArrayList orderDetails;
+
+ public Order() {
+ }
+
+ public Order(int id) {
+ Id = id;
+ }
+
+ public Order(int id, ArrayList orderDetails) {
+ Id = id;
+ this.orderDetails = orderDetails;
+ }
+
+ public int getId() {
+ return Id;
+ }
+
+ public void setId(int id) {
+ Id = id;
+ }
+
+ public ArrayList getOrderDetails() {
+ return orderDetails;
+ }
+
+ public void setOrderDetails(ArrayList orderDetails) {
+ this.orderDetails = orderDetails;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean ban = false;
+ if (obj != null) {
+ if (Order.class.isAssignableFrom(obj.getClass())) {
+ final Order other = (Order) obj;
+ ban = this.getId() == other.getId();
+ }
+ }
+ return ban;
+ }
+
+ @Override
+ public String toString() {
+ String str = "No Items in the order.";
+ if (orderDetails.size() > 0) {
+ str = "Order details: ";
+ for (int i = 0; i < orderDetails.size(); i++) {
+ str += "\n" + i + " " + orderDetails.get(i).toString();
+ }
+ }
+ return str;
+ }
+
+ public void addOrderDetail(OrderDetail orderDetail) {
+ if (orderDetails.size() > 0) {
+ boolean ban = false;
+ for (OrderDetail od : orderDetails
+ ) {
+ if (od.equals(orderDetail)) {
+ od.setQuantity(od.getQuantity() + orderDetail.getQuantity());
+ ban = true;
+ }
+
+ }
+ if (!ban) {
+ orderDetails.add(orderDetail);
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/bootcamp2018/model/OrderDetail.java b/src/main/java/com/bootcamp2018/model/OrderDetail.java
new file mode 100644
index 0000000..c919eb4
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/OrderDetail.java
@@ -0,0 +1,71 @@
+package com.bootcamp2018.model;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OrderDetail {
+ @Autowired
+ private Item item;
+ private int quantity;
+ private double price;
+
+ public OrderDetail() {
+ this.item = new Item();
+ this.quantity = 0;
+ this.price = 0;
+ }
+
+ public OrderDetail(Item item, int quantity) {
+ this.item = item;
+ this.quantity = quantity;
+ this.price = item.getPrice();
+ }
+
+ public Item getItem() {
+ return item;
+ }
+
+ public void setItem(Item item) {
+ this.item = item;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean ban = false;
+ if (obj != null) {
+ if (OrderDetail.class.isAssignableFrom(obj.getClass())) {
+ final OrderDetail other = (OrderDetail) obj;
+ if (this.getItem().equals(other.getItem())) {
+ ban = true;
+ }
+ }
+ }
+ return ban;
+ }
+
+ @Override
+ public String toString() {
+ return "Item: " + this.item.getName() + ", quantity: " + this.quantity + ", unit price: $" + this.price;
+ }
+
+ public double getSubTotal() {
+ return this.price * this.quantity;
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/model/Payment.java b/src/main/java/com/bootcamp2018/model/Payment.java
new file mode 100644
index 0000000..3c1afd6
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/model/Payment.java
@@ -0,0 +1,76 @@
+package com.bootcamp2018.model;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+
+@Component
+public class Payment {
+ private int Id;
+ @Autowired
+ private Order order;
+ private double amount;
+
+ public int getId() {
+ return Id;
+ }
+
+ public void setId(int id) {
+ Id = id;
+ }
+
+ public Order getOrder() {
+ return order;
+ }
+
+ public void setOrder(Order order) {
+ this.order = order;
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ public Payment(int id) {
+ Id = id;
+ }
+
+
+ public Payment(int id, Order order, double amount) {
+ this.Id = id;
+ this.order = order;
+ this.amount = amount;
+ }
+
+ public Payment() {
+ this.Id = 0;
+ this.order = new Order();
+ this.amount = 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!Payment.class.isAssignableFrom(obj.getClass())) {
+ return false;
+ }
+ final Payment other = (Payment) obj;
+
+ if (this.getId() != other.getId()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Payment Id: " + getId() + ", \n" + getOrder().toString() + "\nAmount: $" + getAmount();
+ }
+
+}
diff --git a/src/main/java/com/bootcamp2018/service/ClientService.java b/src/main/java/com/bootcamp2018/service/ClientService.java
new file mode 100644
index 0000000..0ac711b
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/ClientService.java
@@ -0,0 +1,33 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.model.Client;
+
+import java.util.ArrayList;
+
+public class ClientService implements Service {
+ @Override
+ public Client create(Client Object) {
+ return null;
+ }
+
+ @Override
+ public Client get(Client Object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList getList(Client Objact) {
+ return null;
+ }
+
+ @Override
+ public Client update(Client Object) {
+ return null;
+ }
+
+ @Override
+ public void delete(Client Object) {
+
+ }
+ //DTO class ver patron
+}
diff --git a/src/main/java/com/bootcamp2018/service/DiscountService.java b/src/main/java/com/bootcamp2018/service/DiscountService.java
new file mode 100644
index 0000000..f4d4608
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/DiscountService.java
@@ -0,0 +1,34 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.dao.DiscountDAO;
+import com.bootcamp2018.model.Discount;
+
+import java.util.ArrayList;
+
+public class DiscountService implements Service {
+ @Override
+ public Discount create(Discount object) {
+ DiscountDAO dDAO = new DiscountDAO();
+ return dDAO.createDiscount(object);
+ }
+
+ @Override
+ public Discount get(Discount object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList getList(Discount object) {
+ return null;
+ }
+
+ @Override
+ public Discount update(Discount object) {
+ return null;
+ }
+
+ @Override
+ public void delete(Discount object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/service/ItemService.java b/src/main/java/com/bootcamp2018/service/ItemService.java
new file mode 100644
index 0000000..aa80c6d
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/ItemService.java
@@ -0,0 +1,40 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.dao.ItemDAO;
+import com.bootcamp2018.model.Item;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+public class ItemService implements Service
- {
+
+ @Override
+ public Item create(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.createItem(object);
+ }
+
+ @Override
+ public Item get(Item Object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList
- getList(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.retriveItems(object);
+ }
+
+ @Override
+ public Item update(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ return itemDAO.updateItem(object);
+ }
+
+ @Override
+ public void delete(Item object) {
+ ItemDAO itemDAO = new ItemDAO();
+ itemDAO.deleteItem(object);
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/service/OrderDetailService.java b/src/main/java/com/bootcamp2018/service/OrderDetailService.java
new file mode 100644
index 0000000..de65d49
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/OrderDetailService.java
@@ -0,0 +1,32 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.dto.OrderDetailDTO;
+
+import java.util.ArrayList;
+
+public class OrderDetailService implements Service {
+ @Override
+ public OrderDetailDTO create(OrderDetailDTO Object) {
+
+ return Object;
+ }
+
+ @Override
+ public OrderDetailDTO get(OrderDetailDTO Object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList getList(OrderDetailDTO Object) {
+ return null;
+ }
+
+ @Override
+ public OrderDetailDTO update(OrderDetailDTO Object) {
+ return null;
+ }
+
+ @Override
+ public void delete(OrderDetailDTO Object) {
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/service/OrderService.java b/src/main/java/com/bootcamp2018/service/OrderService.java
new file mode 100644
index 0000000..46737bd
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/OrderService.java
@@ -0,0 +1,32 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.dto.OrderDTO;
+
+import java.util.ArrayList;
+
+public class OrderService implements Service {
+ @Override
+ public OrderDTO create(OrderDTO Object) {
+ return null;
+ }
+
+ @Override
+ public OrderDTO get(OrderDTO Object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList getList(OrderDTO Object) {
+ return null;
+ }
+
+ @Override
+ public OrderDTO update(OrderDTO Object) {
+ return null;
+ }
+
+ @Override
+ public void delete(OrderDTO Object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/service/PaymentService.java b/src/main/java/com/bootcamp2018/service/PaymentService.java
new file mode 100644
index 0000000..1ea10fc
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/PaymentService.java
@@ -0,0 +1,33 @@
+package com.bootcamp2018.service;
+
+import com.bootcamp2018.dto.PaymentDTO;
+
+import java.util.ArrayList;
+
+public class PaymentService implements Service {
+ @Override
+ public PaymentDTO create(PaymentDTO Object) {
+
+ return Object;
+ }
+
+ @Override
+ public PaymentDTO get(PaymentDTO Object) {
+ return null;
+ }
+
+ @Override
+ public ArrayList getList(PaymentDTO Object) {
+ return null;
+ }
+
+ @Override
+ public PaymentDTO update(PaymentDTO Object) {
+ return null;
+ }
+
+ @Override
+ public void delete(PaymentDTO Object) {
+
+ }
+}
diff --git a/src/main/java/com/bootcamp2018/service/Service.java b/src/main/java/com/bootcamp2018/service/Service.java
new file mode 100644
index 0000000..83a2fe4
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/service/Service.java
@@ -0,0 +1,15 @@
+package com.bootcamp2018.service;
+
+import java.util.ArrayList;
+
+public interface Service {
+ T create(T object);
+
+ T get(T object);
+
+ ArrayList getList(T object);
+
+ T update(T object);
+
+ void delete(T object);
+}
diff --git a/src/main/java/com/bootcamp2018/util/Utility.java b/src/main/java/com/bootcamp2018/util/Utility.java
new file mode 100644
index 0000000..563be9b
--- /dev/null
+++ b/src/main/java/com/bootcamp2018/util/Utility.java
@@ -0,0 +1,25 @@
+package com.bootcamp2018.util;
+
+public class Utility {
+ public static boolean isInt(String s) {
+ try {
+ Integer.parseInt(s);
+ } catch (NumberFormatException e) {
+ return false;
+ } catch (NullPointerException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public static boolean isDouble(String s) {
+ try {
+ Double.parseDouble(s);
+ } catch (NumberFormatException e) {
+ return false;
+ } catch (NullPointerException e) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/src/main/webapp/META-INF/context.xml b/src/main/webapp/META-INF/context.xml
new file mode 100644
index 0000000..d123dd3
--- /dev/null
+++ b/src/main/webapp/META-INF/context.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/src/main/webapp/WEB-INF/beans.xml b/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..08160bf
--- /dev/null
+++ b/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..a0328fc
--- /dev/null
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,22 @@
+
+
+
+ spring-mvc-demo
+
+
+ MyDispatcher
+ org.springframework.web.servlet.DispatcherServlet
+
+ contextConfigLocation
+ /WEB-INF/spring-mvc-demo-servlet.xml
+
+ 1
+
+
+ MyDispatcher
+ /
+
+