From 1b8a1e35de35637dc67c66f52b4ae0d142246161 Mon Sep 17 00:00:00 2001 From: Floyd Brown Date: Mon, 23 Nov 2020 16:18:21 -0600 Subject: [PATCH 1/3] First Commit --- .../uark/registerapp/models/api/Product.java | 25 ++++- .../models/entities/ProductEntity.java | 39 +++++++- .../resources/static/scripts/productDetail.js | 94 ++++++++++++++++++- .../resources/templates/productListing.html | 3 + 4 files changed, 151 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/uark/registerapp/models/api/Product.java b/src/main/java/edu/uark/registerapp/models/api/Product.java index 2a0644d2..0f7fa4db 100644 --- a/src/main/java/edu/uark/registerapp/models/api/Product.java +++ b/src/main/java/edu/uark/registerapp/models/api/Product.java @@ -1,3 +1,5 @@ + + package edu.uark.registerapp.models.api; import java.time.LocalDateTime; @@ -28,6 +30,21 @@ public Product setLookupCode(final String lookupCode) { this.lookupCode = lookupCode; return this; } +//----------------------------------------------------------------------- +// This is what Floyd Brown added 11/22/20 +// This is basically creating a get and set for the cost of what is being purchased +// It is based off of the other getters and setters in the file + private float cost; + + public float getCost() { + return this.cost; + } + + public Product setCost(final float cost) { + this.cost = cost; + return this; + } +//----------------------------------------------------------------------- private int count; @@ -40,6 +57,8 @@ public Product setCount(final int count) { return this; } + + private String createdOn; public String getCreatedOn() { @@ -60,7 +79,10 @@ public Product setCreatedOn(final LocalDateTime createdOn) { public Product() { super(); - +//---------------------------------------- + this.cost = 0; +// The line above is letting our cost equal 0 +//------------------------------------------ this.count = -1; this.id = new UUID(0, 0); this.lookupCode = StringUtils.EMPTY; @@ -74,6 +96,7 @@ public Product(final ProductEntity productEntity) { this.id = productEntity.getId(); this.count = productEntity.getCount(); this.lookupCode = productEntity.getLookupCode(); + this.cost = productEntity.getCost(); this.setCreatedOn(productEntity.getCreatedOn()); } diff --git a/src/main/java/edu/uark/registerapp/models/entities/ProductEntity.java b/src/main/java/edu/uark/registerapp/models/entities/ProductEntity.java index 2810a452..af8444c3 100644 --- a/src/main/java/edu/uark/registerapp/models/entities/ProductEntity.java +++ b/src/main/java/edu/uark/registerapp/models/entities/ProductEntity.java @@ -39,7 +39,21 @@ public ProductEntity setLookupCode(final String lookupCode) { this.lookupCode = lookupCode; return this; } +// ---------------------------------------------------------------- +// This is setting up cost, just like how it was set up for count + @Column(name="cost") + private float cost; + public float getCost() { + return this.cost; + } + + public ProductEntity setCost(final float cost) { + this.cost = cost; + return this; + } + +//---------------------------------------------------------------- @Column(name = "count") private int count; @@ -52,6 +66,8 @@ public ProductEntity setCount(final int count) { return this; } + + @Column(name = "createdon", insertable = false, updatable = false) @Generated(GenerationTime.INSERT) private LocalDateTime createdOn; @@ -63,7 +79,8 @@ public LocalDateTime getCreatedOn() { public Product synchronize(final Product apiProduct) { this.setCount(apiProduct.getCount()); this.setLookupCode(apiProduct.getLookupCode()); - + this.setCost(apiProduct.getCost()); + apiProduct.setId(this.getId()); apiProduct.setCreatedOn(this.getCreatedOn()); @@ -72,19 +89,31 @@ public Product synchronize(final Product apiProduct) { public ProductEntity() { this.count = -1; + this.cost = 0; this.id = new UUID(0, 0); this.lookupCode = StringUtils.EMPTY; } - - public ProductEntity(final String lookupCode, final int count) { +// ----------------------------------------------------------------------------------------- +// This is the part that I changed (Floyd Brown, 11/22/20) +// Within the parameter, I have included cost, and we are basically setting it up +// The same way that count was initially set up in this file + public ProductEntity(final String lookupCode, final int count, final float cost) { +//--------------------------------------------------------------------------- +// This is where we setup cost + this.cost = cost; +//--------------------------------------------------------------------------- this.count = count; this.id = new UUID(0, 0); this.lookupCode = lookupCode; } public ProductEntity(final Product apiProduct) { - this.id = new UUID(0, 0); + this.id = new UUID(0, 0); this.count = apiProduct.getCount(); +//--------------------------------------------------------------------------------------- + this.cost = apiProduct.getCost(); +// Here we are basically setting up cost the same way that count was set up +//---------------------------------------------------------------------------------------- this.lookupCode = apiProduct.getLookupCode(); } -} +} \ No newline at end of file diff --git a/src/main/resources/static/scripts/productDetail.js b/src/main/resources/static/scripts/productDetail.js index 5b7d7280..41b4147b 100644 --- a/src/main/resources/static/scripts/productDetail.js +++ b/src/main/resources/static/scripts/productDetail.js @@ -1,14 +1,20 @@ + + let hideProductSavedAlertTimer = undefined; +let hideProductAddedAlertTimer = undefined; document.addEventListener("DOMContentLoaded", () => { const productLookupCodeElement = getProductLookupCodeElement(); getProductCountElement().addEventListener("keypress", productCountKeypress); + getProductCostElement().addEventListener("keypress", productCostKeypress); productLookupCodeElement.addEventListener("keypress", productLookupCodeKeypress); getSaveActionElement().addEventListener("click", saveActionClick); getDeleteActionElement().addEventListener("click", deleteActionClick); + + if (!productLookupCodeElement.disabled) { productLookupCodeElement.focus(); productLookupCodeElement.select(); @@ -23,6 +29,10 @@ function productLookupCodeKeypress(event) { const productCountElement = getProductCountElement(); productCountElement.focus(); productCountElement.select(); + + const productCostElement = getProductCostElement(); + productCostElement.focus(); + productCostElement.select(); } function productCountKeypress(event) { @@ -32,6 +42,14 @@ function productCountKeypress(event) { saveActionClick(); } +// Added a keypress for cost (Floyd Brown) +function productCostKeypress(event) { + if (event.which !== 13) { // Enter key + return; + } + + saveActionClick(); +} // Save function saveActionClick(event) { @@ -49,6 +67,7 @@ function saveActionClick(event) { const saveProductRequest = { id: productId, count: getProductCount(), + cost: getProductCost(), lookupCode: getProductLookupCode() }; @@ -95,9 +114,20 @@ function validateSave() { displayError("Product count may not be negative."); return false; } +//--------------------------------------------------------------- +// I did for cost what was already done for count(Floyd) + const cost = getProductCost(); + if ((cost == null) || isNaN(cost)) { + displayError("Please provide a valid product cost."); + return false; + } else if (cost < 0) { + displayError("Product cost may not be negative."); + return false; + } return true; } +//------------------------------------------------------------------ function displayProductSavedAlertModal() { if (hideProductSavedAlertTimer) { @@ -118,9 +148,7 @@ function hideProductSavedAlertModal() { getSavedAlertModalElement().style.display = "none"; } -// End save -// Delete function deleteActionClick(event) { const deleteActionElement = event.target; const deleteActionUrl = ("/api/product/" + getProductId()); @@ -135,8 +163,46 @@ function deleteActionClick(event) { } }); }; -// End delete +//------------------------------------------------------------------- +// new function that is based off of saved alert modal (Floyd) +// I think that these can be used to build something better later on, maybe something like a function that is for when the cart +// gets clicked on, and this is part of what happens/ can go inside. I just can not think of a way to do more than this towards that though +function displayProductAddedAlertModal() { + if (hideProductAddedAlertTimer) { + clearTimeout(hideProductAddedAlertTimer); + } + + const addedCartAlertModalElement = getAddedCartAlertModalElement(); + addedCartAlertModalElement.style.display = "none"; + addedCartAlertModalElement.style.display = "block"; + + hideProductAddedAlertTimer = setTimeout(hideProductAddedCartAlertModal, 1200); + } +// this function is based off of hide product saved alert modal + function hideProductAddedCartAlertModal() { + if (hideProductAddedAlertTimer) { + clearTimeout(hideProductAddedAlertTimer); + } + // created this getter below + getAddedCartAlertModalElement().style.display = "none"; + } + +//----------------------------------------------------------------- +function completeSaveAction(callbackResponse) { + if (callbackResponse.data == null) { + return; + } + + if ((callbackResponse.data.redirectUrl != null) + && (callbackResponse.data.redirectUrl !== "")) { + + window.location.replace(callbackResponse.data.redirectUrl); + return; + } +} + +//---------------------------------------------------------- // Getters and setters function getSaveActionElement() { return document.getElementById("saveButton"); @@ -150,6 +216,15 @@ function getDeleteActionElement() { return document.getElementById("deleteButton"); } + +//------------------------------------------------------------------------ +// (added by Floyd Brown) +function getAddedCartAlertModalElement() { + return document.getElementById("productAddedCartAlertModal"); +} +//--------------------------------------- + + function getProductId() { return getProductIdElement().value; } @@ -173,4 +248,15 @@ function getProductCount() { function getProductCountElement() { return document.getElementById("productCount"); } -// End getters and setters +//-------------------------------------------------------- +// Added a getter cost element (Floyd) based off of count element +function getProductCost() { + return Number(getProductCostElement().value); +} +function getProductCostElement() { + return document.getElementById("productCost"); +} +//---------------------------------------------------------------- + + + diff --git a/src/main/resources/templates/productListing.html b/src/main/resources/templates/productListing.html index 6c374f83..9b4ab5fd 100644 --- a/src/main/resources/templates/productListing.html +++ b/src/main/resources/templates/productListing.html @@ -1,3 +1,4 @@ + @@ -33,6 +34,8 @@

lookupCode
  0 + +
  0
  12/31/1999 From 38fa190181003036fc51450a1e6ed1fabc1b63e1 Mon Sep 17 00:00:00 2001 From: rseranllari <59234808+rseranllari@users.noreply.github.com> Date: Mon, 30 Nov 2020 23:06:33 -0600 Subject: [PATCH 2/3] Update EmployeeSignIn.java --- .../java/edu/uark/registerapp/models/api/EmployeeSignIn.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java index e01e4f6c..0da33556 100644 --- a/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java +++ b/src/main/java/edu/uark/registerapp/models/api/EmployeeSignIn.java @@ -11,6 +11,10 @@ public EmployeeSignIn setEmployeeId(final String employeeId) { this.employeeId = employeeId; return this; } + + public EmployeSignIn getEmployeeId(){ + return this.employeeId; + } private String password; public String getPassword() { From 85a9e7069400e0a268ac50ed0d3c1288f10adf51 Mon Sep 17 00:00:00 2001 From: rseranllari <59234808+rseranllari@users.noreply.github.com> Date: Tue, 1 Dec 2020 19:01:39 -0600 Subject: [PATCH 3/3] Add files via upload --- .../TransactionCreateCommand.java | 71 +++++++++++++++++++ .../Transactions/TransactionQuery.java | 30 ++++++++ .../TransactionUpdateCommand.java | 68 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 src/main/java/edu/uark/registerapp/commands/Transactions/TransactionCreateCommand.java create mode 100644 src/main/java/edu/uark/registerapp/commands/Transactions/TransactionQuery.java create mode 100644 src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java diff --git a/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionCreateCommand.java b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionCreateCommand.java new file mode 100644 index 00000000..317963c0 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionCreateCommand.java @@ -0,0 +1,71 @@ +package edu.uark.registerapp.commands.transactions; + +import java.util.Optional; + +import javax.transaction.Transactional; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.exceptions.ConflictException; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; +import edu.uark.registerapp.models.api.Transaction; +import edu.uark.registerapp.models.entities.TransactionEntity; +import edu.uark.registerapp.models.repositories.TransactionRepository; + +@Service +public class TransactionCreateCommand implements ResultCommandInterface { + @Override + public Transaction execute() { + this.validateProperties(); + + final TransactionEntity createdTransactionEntity = this.createTransactionEntity(); + + // Synchronize information generated by the database upon INSERT. + this.apiTransaction.setId(createdTransactionEntity.getId()); + this.apiTransaction.setCreatedOn(createdTransactionEntity.getCreatedOn()); + + return this.apiTransaction; + } + + // Helper methods + private void validateProperties() { + if (StringUtils.isBlank(this.apiTransaction.getLookupCode())) { + throw new UnprocessableEntityException("lookupcode"); + } + } + + @Transactional + private TransactionEntity createTransactionEntity() { + final Optional queriedTransactionEntity = + this.transactionRepository + .findByLookupCode(this.apiTransaction.getLookupCode()); + + if (queriedTransactionEntity.isPresent()) { + // Lookupcode already defined for another transaction. + throw new ConflictException("lookupcode"); + } + + // No ENTITY object was returned from the database, thus the API object's + // lookupcode must be unique. + + // Write, via an INSERT, the new record to the database. + return this.transactionRepository.save( + new TransactionEntity(apiTransaction)); + } + + // Properties + private Transaction apiTransaction; + public Transaction getApiTransaction() { + return this.apiTransaction; + } + public TransactionCreateCommand setApiTransaction(final Transaction apiTransaction) { + this.apiTransaction = apiTransaction; + return this; + } + + @Autowired + private TransactionRepository transactionRepository; +} \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionQuery.java b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionQuery.java new file mode 100644 index 00000000..61411fef --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionQuery.java @@ -0,0 +1,30 @@ + +package edu.uark.registerapp.commands.transactions; + +import java.util.LinkedList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.models.api.Transaction; +import edu.uark.registerapp.models.entities.TransactionEntity; +import edu.uark.registerapp.models.repositories.TransactionRepository; + +@Service +public class TransactionsQuery implements ResultCommandInterface> { + @Override + public List execute() { + final LinkedList transactions = new LinkedList(); + + for (final TransactionEntity transactionEntity : transactionRepository.findAll()) { + transactions.addLast(new Transaction(transactionEntity)); + } + + return transactions; + } + + @Autowired + TransactionRepository transactionRepository; +} \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java new file mode 100644 index 00000000..0394b6eb --- /dev/null +++ b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java @@ -0,0 +1,68 @@ +package edu.uark.registerapp.commands.transactions; + +import java.util.Optional; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import edu.uark.registerapp.commands.ResultCommandInterface; +import edu.uark.registerapp.commands.exceptions.NotFoundException; +import edu.uark.registerapp.commands.exceptions.UnprocessableEntityException; +import edu.uark.registerapp.models.api.transaction; +import edu.uark.registerapp.models.entities.transactionEntity; +import edu.uark.registerapp.models.repositories.transactionRepository; + +@Service +public class transactionUpdateCommand implements ResultCommandInterface { + @Transactional + @Override + public transaction execute() { + this.validateProperties(); + + final Optional transactionEntity = + this.transactionRepository.findById(this.transactionId); + if (!transactionEntity.isPresent()) { // No record with the associated record ID exists in the database. + throw new NotFoundException("transaction"); + } + + // Synchronize any incoming changes for UPDATE to the database. + this.apitransaction = transactionEntity.get().synchronize(this.apitransaction); + + // Write, via an UPDATE, any changes to the database. + this.transactionRepository.save(transactionEntity.get()); + + return this.apitransaction; + } + + // Helper methods + private void validateProperties() { + if (StringUtils.isBlank(this.apitransaction.getLookupCode())) { + throw new UnprocessableEntityException("lookupcode"); + } + } + + // Properties + private UUID transactionId; + public UUID gettransactionId() { + return this.transactionId; + } + public transactionUpdateCommand settransactionId(final UUID transactionId) { + this.transactionId = transactionId; + return this; + } + + private transaction apitransaction; + public transaction getApitransaction() { + return this.apitransaction; + } + public transactionUpdateCommand setApitransaction(final transaction apitransaction) { + this.apitransaction = apitransaction; + return this; + } + + @Autowired + private transactionRepository transactionRepository; +} \ No newline at end of file