This commit is contained in:
Marvin Scham
2023-06-28 04:31:15 +02:00
parent 6fe29e4319
commit f32b7fc1c7
3 changed files with 32 additions and 39 deletions

View File

@@ -33,21 +33,25 @@ public class OfferIdentifier {
for (ProductCatalogue pCat : pCats) {
// Call price finder for all catalogue
ProductPair pair = getHighestMarginProducts(pCat);
Offer possibleOffer = new Offer();
possibleOffer.setLastUpdate(Timestamp.now());
possibleOffer.setSourceProduct(pair.getProduct1());
possibleOffer.setTargetProduct(pair.getProduct2());
identifiedOffers.add(possibleOffer);
try {
ProductPair pair = getHighestMarginProducts(pCat);
Offer possibleOffer = new Offer();
possibleOffer.setLastUpdate(Timestamp.now());
possibleOffer.setSourceProduct(pair.getProduct1());
possibleOffer.setTargetProduct(pair.getProduct2());
identifiedOffers.add(possibleOffer);
double margin = pair.getProduct2().getCurrentPrice()
- pair.getProduct1().getCurrentPrice();
String marginFormatted = FormattingUtil.formatEuro(margin);
LOGGER.info("\n Identified Offer: {} ({} to {}) with margin {} ",
pCat.getProductName(),
pair.getProduct1().getDataOrigin(),
pair.getProduct2().getDataOrigin(),
marginFormatted);
double margin = pair.getProduct2().getCurrentPrice()
- pair.getProduct1().getCurrentPrice();
String marginFormatted = FormattingUtil.formatEuro(margin);
LOGGER.info("\n Identified Offer: {} ({} to {}) with margin {} ",
pCat.getProductName(),
pair.getProduct1().getDataOrigin(),
pair.getProduct2().getDataOrigin(),
marginFormatted);
} catch (InvalidOfferException e) {
// Don't include offer if deemed invalid
}
}
return identifiedOffers;

View File

@@ -10,7 +10,6 @@ import de.rwu.easydrop.api.client.PurchaserFactory;
import de.rwu.easydrop.api.client.SellerFactory;
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
import de.rwu.easydrop.model.Offer;
import de.rwu.easydrop.model.Webshop;
import de.rwu.easydrop.service.mapping.ProductMapper;
import de.rwu.easydrop.service.writer.OfferWriter;
import de.rwu.easydrop.util.FormattingUtil;
@@ -51,15 +50,13 @@ public class OfferProvisioner {
* @param offer
*/
private void toSeller(final Offer offer) throws IllegalArgumentException {
if (offer.getTargetProduct().getDataOrigin() == Webshop.EBAY) {
this.ebaySeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
this.amazonSeller.sellProduct(ProductMapper.mapProductToDTO(offer.getTargetProduct()));
} else {
throw new IllegalArgumentException("Unsupported target plattform");
switch (offer.getTargetProduct().getDataOrigin()) {
case EBAY -> this.ebaySeller.sellProduct(
ProductMapper.mapProductToDTO(offer.getTargetProduct()));
case AMAZON -> this.amazonSeller.sellProduct(
ProductMapper.mapProductToDTO(offer.getTargetProduct()));
default -> throw new IllegalArgumentException("Unsupported source plattform");
}
}
/**
@@ -68,17 +65,13 @@ public class OfferProvisioner {
* @param offer
*/
private void toBuyer(final Offer offer) throws IllegalArgumentException {
if (offer.getSourceProduct().getDataOrigin() == Webshop.EBAY) {
this.ebayPurchaser.purchaseProduct(
switch (offer.getSourceProduct().getDataOrigin()) {
case EBAY -> ebayPurchaser.purchaseProduct(
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
} else if (offer.getTargetProduct().getDataOrigin().equals(Webshop.AMAZON)) {
this.amazonPurchaser.purchaseProduct(
case AMAZON -> amazonPurchaser.purchaseProduct(
ProductMapper.mapProductToDTO(offer.getSourceProduct()));
} else {
throw new IllegalArgumentException("Unsupported target plattform");
default -> throw new IllegalArgumentException("Unsupported target plattform");
}
}
/**

View File

@@ -93,13 +93,9 @@ public class ProductRetriever {
* @return Product from that data source or null if data source not available
*/
public Product getProductFromWebshop(final Webshop shop, final String productIdentifier) {
switch (shop) {
case AMAZON:
return getProductFromAmazon(productIdentifier);
case EBAY:
return getProductFromEbay(productIdentifier);
default:
return null;
}
return switch (shop) {
case AMAZON -> getProductFromAmazon(productIdentifier);
case EBAY -> getProductFromEbay(productIdentifier);
};
}
}