From 1b8a1e35de35637dc67c66f52b4ae0d142246161 Mon Sep 17 00:00:00 2001 From: Floyd Brown Date: Mon, 23 Nov 2020 16:18:21 -0600 Subject: [PATCH 1/6] 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/6] 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/6] 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 From 1b01f619943463f03d72690688d07c08d55b788b Mon Sep 17 00:00:00 2001 From: Jacob Dedman Date: Thu, 10 Dec 2020 20:26:57 -0600 Subject: [PATCH 4/6] Jacob Dedman final commit --- .../TransactionUpdateCommand.java | 8 +- .../products/ProductUpdateCommand.java | 21 +++++ .../uark/registerapp/models/api/Product.java | 8 ++ .../registerapp/models/api/Transaction.java | 80 +++++++++++++++++++ .../models/entities/TransactionEntity.java | 58 ++++++++++++++ .../repositories/TransactionRepository.java | 17 ++++ 6 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 src/main/java/edu/uark/registerapp/models/api/Transaction.java create mode 100644 src/main/java/edu/uark/registerapp/models/entities/TransactionEntity.java create mode 100644 src/main/java/edu/uark/registerapp/models/repositories/TransactionRepository.java diff --git a/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java index 0394b6eb..cff33d1f 100644 --- a/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/Transactions/TransactionUpdateCommand.java @@ -11,9 +11,9 @@ 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; +import edu.uark.registerapp.models.api.Transaction; //Transaction capitalized by Jacob +import edu.uark.registerapp.models.entities.TransactionEntity; +import edu.uark.registerapp.models.repositories.TransactionRepository; @Service public class transactionUpdateCommand implements ResultCommandInterface { @@ -64,5 +64,5 @@ public transactionUpdateCommand setApitransaction(final transaction apitransacti } @Autowired - private transactionRepository transactionRepository; + private TransactionRepository transactionRepository; //Transaction capitalized by Jacob } \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/commands/products/ProductUpdateCommand.java b/src/main/java/edu/uark/registerapp/commands/products/ProductUpdateCommand.java index a3124613..66fa05bd 100644 --- a/src/main/java/edu/uark/registerapp/commands/products/ProductUpdateCommand.java +++ b/src/main/java/edu/uark/registerapp/commands/products/ProductUpdateCommand.java @@ -22,6 +22,8 @@ public class ProductUpdateCommand implements ResultCommandInterface { public Product execute() { this.validateProperties(); + this.updateProductEntity(); + final Optional productEntity = this.productRepository.findById(this.productId); if (!productEntity.isPresent()) { // No record with the associated record ID exists in the database. @@ -44,6 +46,25 @@ private void validateProperties() { } } + //---------------------------------------------------------------------------- + //Jacob Dedman + //Update product entity for database update + @Transactional + private void updateProductEntity() { + final Optional queriedProductEntity = + this.productRepository.findById(this.productId); + + if (!queriedProductEntity.isPresent()) { + throw new NotFoundException("Product"); // No record with the associated record ID exists in the database. + } + + this.apiProduct = queriedProductEntity.get() + .synchronize(this.apiProduct); // Synchronize any incoming changes for UPDATE to the database. + + this.ProductRepository.save(queriedProductEntity.get()); // Write, via an UPDATE, any changes to the database. + } + //--------------------------------------------------------------------------------------------- + // Properties private UUID productId; public UUID getProductId() { 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 0f7fa4db..fd72a125 100644 --- a/src/main/java/edu/uark/registerapp/models/api/Product.java +++ b/src/main/java/edu/uark/registerapp/models/api/Product.java @@ -57,6 +57,14 @@ public Product setCount(final int count) { return this; } +//----------------------------------------------------------------------- +// Jacob Dedman +// Function to change product count by num + public Product changeCount(final int num) { + this.count = this.count + num; + return this; + } +//----------------------------------------------------------------------- private String createdOn; diff --git a/src/main/java/edu/uark/registerapp/models/api/Transaction.java b/src/main/java/edu/uark/registerapp/models/api/Transaction.java new file mode 100644 index 00000000..e8275c22 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/api/Transaction.java @@ -0,0 +1,80 @@ +//------------------------------------------------------------ +//Jacob Dedman +//Created Transaction.java + +package edu.uark.registerapp.models.api; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.UUID; +import java.util.ArrayList; + +import org.apache.commons.lang3.StringUtils; + +import edu.uark.registerapp.models.api.Product; +import edu.uark.registerapp.models.entities.ProductEntity; + + +//Jacob Dedman +//Created Transaction class so I can add functionality for updating database + +public class Transaction extends ApiResponse { + + //Jacob Dedman + //Cart class to hold items + private class Cart { + //Jacob Dedman + //Array of strings holds lookupcode of products + private ArrayList products = new ArrayList(); + public void addProduct(Product prod) { + products.add(prod.getLookupCode()); + } + + public void remProduct(Product prod) { + for (int i = 0; i < products.size(); i++) { + if (products.get(i) == prod.getLookupCode()) { + products.remove(i); + i--; + } + } + } + } + + + //Jacob Dedman + //Properties + + private Cart productCart; + public Transaction addToCart(Product prod) { + this.productCart.addProduct(prod); + return this; + } + public Transaction remFromCart(Product prod) { + this.productCart.remProduct(prod); + return this; + } + + private String lookupCode; + public String getLookupCode() { + return this.lookupCode; + } + + public Product setLookupCode(final String lookupCode) { + this.lookupCode = lookupCode; + return this; + } + + + public Transaction() { + super(); + this.id = new UUID(0, 0); + this.lookupCode = StringUtils.EMPTY; + } + + public Transaction(final TransactionEntity transactionEntity) { + super(false); + + this.id = transactionEntity.getId(); + this.lookupCode = transactionEntity.getLookupCode(); + } +} \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/models/entities/TransactionEntity.java b/src/main/java/edu/uark/registerapp/models/entities/TransactionEntity.java new file mode 100644 index 00000000..df4a6fff --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/entities/TransactionEntity.java @@ -0,0 +1,58 @@ +//------------------------------------------------------------ +//Jacob Dedman +//Created Transaction.java + +package edu.uark.registerapp.models.entities; + +import java.time.LocalDateTime; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import edu.uark.registerapp.models.api.Transaction; + +@Entity +@Table(name="transaction") +public class TransactionEntity { + @Id + @Column(name="id", updatable = false) + @GeneratedValue(strategy=GenerationType.AUTO) + private final UUID id; + + public UUID getId() { + return this.id; + } + + @Column(name = "lookupcode") + private String lookupCode; + + public String getLookupCode() { + return this.lookupCode; + } + + public ProductEntity setLookupCode(final String lookupCode) { + this.lookupCode = lookupCode; + return this; + } + + public Transaction synchronize(final Transaction apiTransaction) { + this.setLookupCode(apiTransaction.getLookupCode()); + apiTransaction.setId(this.getId()); + return apiTransaction; + } + + public TransactionEntity() { + this.id = new UUID(0, 0); + this.lookupCode = StringUtils.EMPTY; + } + +} \ No newline at end of file diff --git a/src/main/java/edu/uark/registerapp/models/repositories/TransactionRepository.java b/src/main/java/edu/uark/registerapp/models/repositories/TransactionRepository.java new file mode 100644 index 00000000..4d549674 --- /dev/null +++ b/src/main/java/edu/uark/registerapp/models/repositories/TransactionRepository.java @@ -0,0 +1,17 @@ +//------------------------------------------------------------ +//Jacob Dedman +//Created TransactionRepository.java + +package edu.uark.registerapp.models.repositories; + +import java.util.Optional; +import java.util.UUID; + +import org.springframework.data.repository.CrudRepository; + +import edu.uark.registerapp.models.entities.TransactionEntity; + +public interface TransactionRepository extends CrudRepository { + Optional findById(UUID id); + Optional findByLookupCode(String lookupCode); +} \ No newline at end of file From d57d3f40cae1c70a9d696f0618ae53e0a0e2a845 Mon Sep 17 00:00:00 2001 From: geoffreyeu Date: Thu, 10 Dec 2020 22:07:06 -0600 Subject: [PATCH 5/6] Made Cart.html Sample page with random code for Cart.html Will fill out the actual code with another push. --- src/main/resources/templates/Cart.html | 93 ++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/resources/templates/Cart.html diff --git a/src/main/resources/templates/Cart.html b/src/main/resources/templates/Cart.html new file mode 100644 index 00000000..4d8bcd2c --- /dev/null +++ b/src/main/resources/templates/Cart.html @@ -0,0 +1,93 @@ + + + Cart + + + + + +
+

Cart Page

+
+ +
+
+

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Employee ID: + +
First Name: + +
Last Name: + +
Password: + +
Confirm password: + +
Employee type: + +
+
+ +
+
+ + +
+ +
+ +
+
+ +
+ Sign Out +
+ + + + + + + + \ No newline at end of file From e1082aee0d0495a935c94cb02123742c513a98ad Mon Sep 17 00:00:00 2001 From: geoffreyeu Date: Tue, 15 Dec 2020 05:22:03 -0600 Subject: [PATCH 6/6] Pushed Cart.html, Checkout.html, css, and js functions for both files as well Sorry, aparently my github messed up and my previous push on Friday went to a different directory. Here's my push for the sprint. You can see my incremental updates in Trello. I did full page views for the Cart and Checkout pages as well as temporary js functions for both. Both pages are heavily based on templates found online with some changes made for our own situation. --- src/main/resources/templates/Cart.html | 122 ++++++------------ src/main/resources/templates/Checkout.html | 96 ++++++++++++++ .../resources/templates/cartfunctionStyle.css | 33 +++++ src/main/resources/templates/cartfunctions.js | 70 ++++++++++ .../resources/templates/checkoutFunctions.js | 37 ++++++ .../resources/templates/checkoutStyle.css | 84 ++++++++++++ 6 files changed, 360 insertions(+), 82 deletions(-) create mode 100644 src/main/resources/templates/Checkout.html create mode 100644 src/main/resources/templates/cartfunctionStyle.css create mode 100644 src/main/resources/templates/cartfunctions.js create mode 100644 src/main/resources/templates/checkoutFunctions.js create mode 100644 src/main/resources/templates/checkoutStyle.css diff --git a/src/main/resources/templates/Cart.html b/src/main/resources/templates/Cart.html index 4d8bcd2c..4c55b7f0 100644 --- a/src/main/resources/templates/Cart.html +++ b/src/main/resources/templates/Cart.html @@ -1,93 +1,51 @@ - + + - Cart - +Shopping Cart + + + + + + - -
-

Cart Page

-
- -
-
-

-
+ +

Shopping Cart - Ctrl-Alt-Elite

+

Insert items and quantity for your shopping cart. Based on sample template found online.

+
+ +
+ + + + + -
-
Item:Quantity:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
Employee ID: - -
First Name: - -
Last Name: - -
Password: - -
Confirm password: - -
Employee type: - -
+ + + +
-
-
- - +
+

Current Items

+
+

+ +

+ + + -
- -
-
- -
- Sign Out -
- - - - - - - \ No newline at end of file + diff --git a/src/main/resources/templates/Checkout.html b/src/main/resources/templates/Checkout.html new file mode 100644 index 00000000..fdc66b80 --- /dev/null +++ b/src/main/resources/templates/Checkout.html @@ -0,0 +1,96 @@ + + + + + + + + +
+
+
+
+ +
+
+

Checkout - Ctrl-Alt-Elite

+

Billing Address

+ + + + + + + + + +
+
+ + +
+
+ + +
+
+
+ +
+

Payment

+ +
+ + + + +
+ + + + + + + +
+
+ + +
+
+ + +
+
+
+ +
+ + +
+
+
+ + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/cartfunctionStyle.css b/src/main/resources/templates/cartfunctionStyle.css new file mode 100644 index 00000000..df8e7cb9 --- /dev/null +++ b/src/main/resources/templates/cartfunctionStyle.css @@ -0,0 +1,33 @@ +td,th { + font-family: Verdana; + padding: 8px; + background-color: #ffffcc; +} + +label { + vertical-align: top; +} + +#main { + border: 1px dotted blue; + padding: 5px; + background-color: #ffffcc; + margin-right: 50%; +} + +#items_table { + border: 1px dotted blue; + padding: 5px; + margin-top: 12px; + margin-right: 50%; +} + +#items_table h3 { + font-size: 20px; + margin-top: 0px; + font-family: sans-serif; +} + +body { + background-color: #ffffcc; +} \ No newline at end of file diff --git a/src/main/resources/templates/cartfunctions.js b/src/main/resources/templates/cartfunctions.js new file mode 100644 index 00000000..1ccbb257 --- /dev/null +++ b/src/main/resources/templates/cartfunctions.js @@ -0,0 +1,70 @@ +//Based off sample template found online. Using HTML5 local storage temporarily but teamates will transition the functions to database calls. + +//Adds a new item to local storage. Will need to replace with a poll to the database. +function Save() { + + var name = document.forms.ShoppingList.name.value; + var info = document.forms.ShoppingList.data.value; + localStorage.setItem(name, info); + Update(); + +} + + +//Modifies an Existing Item in the database. +function Modify() { + var nameCheck = document.forms.ShoppingList.name.value; + var dataCheck = document.forms.ShoppingList.data.value; + +//Check for duplicates +if (localStorage.getItem(nameCheck) !=null) + { + localStorage.setItem(nameCheck,dataCheck); + document.forms.ShoppingList.data.value = localStorage.getItem(nameCheck); + //getItem will be implemented by another member + } + Update(); +} + +//Remove an Item from the Cart +function Remove() { + var name = document.forms.ShoppingList.name.value; + document.forms.ShoppingList.data.value = localStorage.removeItem(name); + Update(); +} + +//clearing storage, will eventually be another call to the database to delete user cart. +function ClearStorage() { + localStorage.clear(); + Update(); +} + + +//For updating the list after various functions. Heavily based on code found online. +function Update() { + if (browserCheck()) { + var key = ""; + var list = "ItemValue\n"; + var i = 0; + for (i = 0; i <= localStorage.length-1; i++) { + key = localStorage.key(i); + list += "" + key + "\n" + localStorage.getItem(key) + "\n"; + } + //if there's an empty cart + if (list == "ItemValue\n") { + list += "empty\nempty\n"; + } + //sending data to html table. Will eventually be a call for the database here. + document.getElementById('list').innerHTML = list; + } +} + +//Checks browser for HTML compatibility. +function browserCheck() { + if(window.localStorage!==undefined){ + return true; + } + else{ + alert('Please update your browser!'); + return false; + } \ No newline at end of file diff --git a/src/main/resources/templates/checkoutFunctions.js b/src/main/resources/templates/checkoutFunctions.js new file mode 100644 index 00000000..bfa5f6f5 --- /dev/null +++ b/src/main/resources/templates/checkoutFunctions.js @@ -0,0 +1,37 @@ +//Based off sample template found online. Using HTML5 local storage temporarily but teamates will transition the functions to database calls. + + +//Receives info from forms and sends to database. To be filled by team mate. +function CheckOut() { + //send info to database. +} + + +//Pulled code from the Cart section. Will need to update so its just a call for the existing list. +function Update() { + if (browserCheck()) { + var key = ""; + var list = "ItemValue\n"; + var i = 0; + for (i = 0; i <= localStorage.length-1; i++) { + key = localStorage.key(i); + list += "" + key + "\n" + localStorage.getItem(key) + "\n"; + } + //if there's an empty cart + if (list == "ItemValue\n") { + list += "empty\nempty\n"; + } + //sending data to html table. Will eventually be a call for the database here. + document.getElementById('list').innerHTML = list; + } +} + +//Checks browser for HTML compatibility. +function browserCheck() { + if(window.localStorage!==undefined){ + return true; + } + else{ + alert('Please update your browser!'); + return false; + } \ No newline at end of file diff --git a/src/main/resources/templates/checkoutStyle.css b/src/main/resources/templates/checkoutStyle.css new file mode 100644 index 00000000..e632da86 --- /dev/null +++ b/src/main/resources/templates/checkoutStyle.css @@ -0,0 +1,84 @@ +.row { + display: -ms-flexbox; /* IE10 */ + display: flex; + -ms-flex-wrap: wrap; /* IE10 */ + flex-wrap: wrap; + margin: 0 -16px; +} + +.col-25 { + -ms-flex: 25%; /* IE10 */ + flex: 25%; +} + +.col-50 { + -ms-flex: 50%; /* IE10 */ + flex: 50%; +} + +.col-75 { + -ms-flex: 75%; /* IE10 */ + flex: 75%; +} + +.col-25, +.col-50, +.col-75 { + padding: 0 16px; +} + +.container { + background-color: #f2f2f2; + padding: 5px 20px 15px 20px; + border: 1px solid lightgrey; + border-radius: 3px; +} + +input[type=text] { + width: 100%; + margin-bottom: 20px; + padding: 12px; + border: 1px solid #ccc; + border-radius: 3px; +} + +label { + margin-bottom: 10px; + display: block; +} + +.icon-container { + margin-bottom: 20px; + padding: 7px 0; + font-size: 24px; +} + +.btn { + background-color: #4CAF50; + color: white; + padding: 12px; + margin: 10px 0; + border: none; + width: 100%; + border-radius: 3px; + cursor: pointer; + font-size: 17px; +} + +.btn:hover { + background-color: #45a049; +} + +span.price { + float: right; + color: grey; +} + +@media (max-width: 800px) { + .row { + flex-direction: column-reverse; + } + .col-25 { + margin-bottom: 20px; + } +} \ No newline at end of file