diff --git a/src/main/java/org/saranghaengbok/models/soap_service.sql b/src/main/java/org/saranghaengbok/models/soap_service.sql index 430a1488f5c2b61f66acf344b0b8c9f6cecc7548..41ef3df905f5671d9b617a7f7902e71d007f1588 100644 --- a/src/main/java/org/saranghaengbok/models/soap_service.sql +++ b/src/main/java/org/saranghaengbok/models/soap_service.sql @@ -14,15 +14,7 @@ CREATE TABLE IF NOT EXISTS `saranghaengbok_soap`.`transaction`( `transaction_id` INT NOT NULL AUTO_INCREMENT, `buyer_username` VARCHAR(45) NOT NULL, `seller_username` VARCHAR(45) NOT NULL, - PRIMARY KEY (`transaction_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - -CREATE TABLE IF NOT EXISTS `saranghaengbok_soap`.`transaction_items`( - `transaction_id` INT NOT NULL, `item_id` INT NOT NULL, `quantity` INT NOT NULL, - CONSTRAINT `fk_transaction` - FOREIGN KEY (`transaction_id`) - REFERENCES `saranghaengbok_soap`.`transaction` (`transaction_id`) - ON UPDATE CASCADE -)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + PRIMARY KEY (`transaction_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/src/main/java/org/saranghaengbok/service/Transaction.java b/src/main/java/org/saranghaengbok/service/Transaction.java index 45f2ccb87f78f4016f1518ea25338c6a6e65345c..2c14537f8255ba499b61e5eee8e0c3c0a21694a8 100644 --- a/src/main/java/org/saranghaengbok/service/Transaction.java +++ b/src/main/java/org/saranghaengbok/service/Transaction.java @@ -13,7 +13,7 @@ public interface Transaction { @WebMethod public String createTransaction( @WebParam(name = "buyer_username", targetNamespace = "http://service.saranghaengbok.org/") String buyer_username, - @WebParam(name = "seller_username", targetNamespace = "http://service.saranghaengbok.org/") String seller_username, + @WebParam(name = "seller_username", targetNamespace = "http://service.saranghaengbok.org/") String seller_usernames, @WebParam(name = "item_id", targetNamespace = "http://service.saranghaengbok.org/") String list_item_id, @WebParam(name = "quantity", targetNamespace = "http://service.saranghaengbok.org/") String list_quantity ); diff --git a/src/main/java/org/saranghaengbok/service/TransactionImpl.java b/src/main/java/org/saranghaengbok/service/TransactionImpl.java index 156b899bb4ca5711bc4dcdafea16c3fad6085594..683893b4e5094c6c3f2d0c95404837053b531123 100644 --- a/src/main/java/org/saranghaengbok/service/TransactionImpl.java +++ b/src/main/java/org/saranghaengbok/service/TransactionImpl.java @@ -79,26 +79,21 @@ public class TransactionImpl implements Transaction{ System.out.println(seller_username); System.out.println(list_item_id); System.out.println(list_quantity); - if ((list_item_id.isEmpty() || Objects.isNull(list_item_id)) && - list_quantity.isEmpty() || Objects.isNull(list_quantity)){ + if (list_item_id.isEmpty() || Objects.isNull(list_item_id) || list_item_id.equals(" ") || + list_quantity.isEmpty() || Objects.isNull(list_quantity) || list_quantity.equals(" ") || + buyer_username.isEmpty() || Objects.isNull(buyer_username) || buyer_username.equals(" ") || + seller_username.isEmpty() || Objects.isNull(seller_username) || seller_username.equals(" ")){ return "No item checked out"; } else { try { Statement statement = connection.createStatement(); String[] list_item = list_item_id.split(","); String[] quantities = list_quantity.split(","); - String query = "INSERT INTO transaction (buyer_username, seller_username) VALUES ('"+ buyer_username + "', '" + seller_username +"')"; - statement.executeUpdate(query); - String query1 = "SELECT transaction_id FROM transaction ORDER BY transaction_id DESC LIMIT 1"; - ResultSet result = statement.executeQuery(query1); - int transaction_id = -1; - while (result.next()){ - transaction_id = result.getInt("transaction_id"); - } + String[] list_seller = seller_username.split(","); for (int i = 0; i < list_item.length; i++) { - String query2 = "INSERT INTO transaction_items (transaction_id, item_id, quantity) VALUES ("+ transaction_id +","+ list_item[i]+","+ quantities[i] +")"; - statement.executeUpdate(query2); - System.out.printf("transaction_item: %d, item_id: %s, quantity: %s",transaction_id,list_item[i], quantities[i]); + String query = "INSERT INTO transaction (buyer_username, seller_username, item_id, quantity) VALUES ('"+ buyer_username +"','"+ list_seller[i] +"',"+ list_item[i]+","+ quantities[i] +")"; + statement.executeUpdate(query); + System.out.printf("buyer_username: %s, seller_username:%s, item_id: %s, quantity: %s\n",buyer_username, seller_username, list_item[i], quantities[i]); } statement.close(); connection.close();