#75 Added transaction logic
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package de.rwu.easydrop.service.processing;
|
||||
|
||||
import de.rwu.easydrop.api.dto.TransactionDTO;
|
||||
import de.rwu.easydrop.data.connector.TransactionPersistenceInterface;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.Transaction;
|
||||
import de.rwu.easydrop.service.mapping.TransactionMapper;
|
||||
import de.rwu.easydrop.util.Timestamp;
|
||||
|
||||
/**
|
||||
* Handles transactions.
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public class TransactionHandler {
|
||||
/**
|
||||
* Transaction persistence.
|
||||
*/
|
||||
private TransactionPersistenceInterface txPersistence;
|
||||
|
||||
/**
|
||||
* Creates new transaction handler.
|
||||
*
|
||||
* @param txdb transaction persistence
|
||||
*/
|
||||
public TransactionHandler(final TransactionPersistenceInterface txdb) {
|
||||
this.txPersistence = txdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates transaction from offer.
|
||||
*
|
||||
* @param offer Offer
|
||||
*/
|
||||
public void turnOfferToTransaction(final Offer offer) {
|
||||
Transaction tx = new Transaction();
|
||||
tx.setOfferId(offer.getOfferId());
|
||||
tx.setVolume(offer.getTargetProduct().getCurrentPrice());
|
||||
tx.setEarnings(offer.getTargetProduct().getCurrentPrice()
|
||||
- offer.getSourceProduct().getCurrentPrice());
|
||||
tx.setTransactionTime(Timestamp.now());
|
||||
|
||||
// Write transaction to persistence
|
||||
TransactionDTO txDTO = TransactionMapper.mapTXToDTO(tx);
|
||||
txPersistence.writeTX(txDTO);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user