From 2499ede03d7c16b41b56c00eaedcc24e343040cb Mon Sep 17 00:00:00 2001 From: AlphaThrone <haikalardzi@gmail.com> Date: Wed, 15 Nov 2023 15:27:39 +0700 Subject: [PATCH] feat: createTransaction using soap from php --- .../saranghaengbok/models/soap_service.sql | 12 ++--------- .../saranghaengbok/service/Transaction.java | 2 +- .../service/TransactionImpl.java | 21 +++++++------------ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/saranghaengbok/models/soap_service.sql b/src/main/java/org/saranghaengbok/models/soap_service.sql index 430a148..41ef3df 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 45f2ccb..2c14537 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 156b899..683893b 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(); -- GitLab