diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml new file mode 100644 index 00000000..a72f58ba --- /dev/null +++ b/.github/workflows/codesee-arch-diagram.yml @@ -0,0 +1,23 @@ +# This workflow was added by CodeSee. Learn more at https://codesee.io/ +# This is v2.0 of this workflow file +on: + push: + branches: + - master + pull_request_target: + types: [opened, synchronize, reopened] + +name: CodeSee + +permissions: read-all + +jobs: + codesee: + runs-on: ubuntu-latest + continue-on-error: true + name: Analyze the repo with CodeSee + steps: + - uses: Codesee-io/codesee-action@v2 + with: + codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} + codesee-url: https://app.codesee.io diff --git a/src/com/shashi/service/impl/OrderServiceImpl.java b/src/com/shashi/service/impl/OrderServiceImpl.java index a82cd4d0..5616be98 100644 --- a/src/com/shashi/service/impl/OrderServiceImpl.java +++ b/src/com/shashi/service/impl/OrderServiceImpl.java @@ -20,56 +20,43 @@ public class OrderServiceImpl implements OrderService { @Override public String paymentSuccess(String userName, double paidAmount) { String status = "Order Placement Failed!"; + List cartItems = new CartServiceImpl().getAllCartItems(userName); - List cartItems = new ArrayList(); - cartItems = new CartServiceImpl().getAllCartItems(userName); - - if (cartItems.size() == 0) + if (cartItems.isEmpty()) { return status; + } TransactionBean transaction = new TransactionBean(userName, paidAmount); - boolean ordered = false; - String transactionId = transaction.getTransactionId(); - - // System.out.println("Transaction: "+transaction.getTransactionId()+" - // "+transaction.getTransAmount()+" "+transaction.getUserName()+" - // "+transaction.getTransDateTime()); + boolean ordered = true; for (CartBean item : cartItems) { - double amount = new ProductServiceImpl().getProductPrice(item.getProdId()) * item.getQuantity(); - OrderBean order = new OrderBean(transactionId, item.getProdId(), item.getQuantity(), amount); - - ordered = addOrder(order); - if (!ordered) + ordered = ordered && processOrder(order, item); + if (!ordered) { break; - else { - ordered = new CartServiceImpl().removeAProduct(item.getUserId(), item.getProdId()); } - - if (!ordered) - break; - else - ordered = new ProductServiceImpl().sellNProduct(item.getProdId(), item.getQuantity()); - - if (!ordered) - break; } + if (ordered && addTransactionAndNotify(transaction, userName)) { + status = "Order Placed Successfully!"; + } + return status; + } - if (ordered) { - ordered = new OrderServiceImpl().addTransaction(transaction); - if (ordered) { - - MailMessage.transactionSuccess(userName, new UserServiceImpl().getFName(userName), - transaction.getTransactionId(), transaction.getTransAmount()); + private boolean processOrder(OrderBean order, CartBean item) { + return addOrder(order) && + new CartServiceImpl().removeAProduct(item.getUserId(), item.getProdId()) && + new ProductServiceImpl().sellNProduct(item.getProdId(), item.getQuantity()); + } - status = "Order Placed Successfully!"; - } + private boolean addTransactionAndNotify(TransactionBean transaction, String userName) { + boolean added = new OrderServiceImpl().addTransaction(transaction); + if (added) { + MailMessage.transactionSuccess(userName, new UserServiceImpl().getFName(userName), + transaction.getTransactionId(), transaction.getTransAmount()); } - - return status; + return added; } @Override