Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Transaction> {
@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<TransactionEntity> 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;
}
Original file line number Diff line number Diff line change
@@ -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<List<Transaction>> {
@Override
public List<Transaction> execute() {
final LinkedList<Transaction> transactions = new LinkedList<Transaction>();

for (final TransactionEntity transactionEntity : transactionRepository.findAll()) {
transactions.addLast(new Transaction(transactionEntity));
}

return transactions;
}

@Autowired
TransactionRepository transactionRepository;
}
Original file line number Diff line number Diff line change
@@ -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<transaction> {
@Transactional
@Override
public transaction execute() {
this.validateProperties();

final Optional<transactionEntity> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/edu/uark/registerapp/models/api/Product.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


package edu.uark.registerapp.models.api;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -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;

Expand All @@ -40,6 +57,8 @@ public Product setCount(final int count) {
return this;
}



private String createdOn;

public String getCreatedOn() {
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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());

Expand All @@ -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();
}
}
}
Loading