fixed some issues in method checkOffers
This commit is contained in:
@@ -11,19 +11,20 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class OfferReviewer {
|
||||
|
||||
/**
|
||||
* OfferReviewer.
|
||||
* Check all Offers and compare them with the API.
|
||||
* @return list of all items that need to be changed
|
||||
*/
|
||||
public List<Offer> checkOffers(/*OfferReader/retriever for database? */) {
|
||||
public List<Offer> checkOffer(/*OfferReader/retriever for database? */) {
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<Product> changedProducts = new ArrayList<>();
|
||||
List<Offer> changedOffers = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// Establish the database connection
|
||||
@@ -33,28 +34,27 @@ public class OfferReviewer {
|
||||
statement = connection.createStatement();
|
||||
|
||||
// Execute the query to retrieve the entries
|
||||
String query = "SELECT dataOrigin, productId, currentPrice FROM table";
|
||||
String query = "SELECT sourceProduct, saleProduct, creationDate, upDate, "
|
||||
+ "checkDate, offerId FROM table";
|
||||
resultSet = statement.executeQuery(query);
|
||||
|
||||
// Process the retrieved entries
|
||||
while (resultSet.next()) {
|
||||
String webshop = resultSet.getString("webshop");
|
||||
String dataOrigin = resultSet.getString("data_origin");
|
||||
String productId = resultSet.getString("productId");
|
||||
double currentPrice = resultSet.getDouble("currentPrice");
|
||||
String merchant = resultSet.getString("merchant");
|
||||
double deliveryPrice = resultSet.getDouble("delivery_price");
|
||||
boolean available = resultSet.getBoolean("available");
|
||||
Product sourceProduct = (Product) resultSet.getObject("sourceProduct");
|
||||
Product saleProduct = (Product) resultSet.getObject("saleProduct");
|
||||
java.sql.Date creationDate = resultSet.getDate("creationDate");
|
||||
Date updateDate = resultSet.getDate("upDate");
|
||||
Date checkDate = resultSet.getDate("checkDate");
|
||||
String offerId = resultSet.getString("offerId");
|
||||
|
||||
// Call the API to get the current price
|
||||
double apiPrice = getPriceFromAPI(productId);
|
||||
double apiPrice = getPriceFromAPI(sourceProduct);
|
||||
|
||||
// Compare the prices
|
||||
if (currentPrice != apiPrice) {
|
||||
// Price has changed, create a Product object and add it to the changedProducts list
|
||||
Product product = new Product(webshop, dataOrigin, productId, currentPrice,
|
||||
merchant, deliveryPrice, available);
|
||||
changedProducts.add(product);
|
||||
if (saleProduct.getCurrentPrice() != apiPrice) {
|
||||
// Price has changed, create a Product object and add it to the changedProducts list
|
||||
Offer offer = new Offer();
|
||||
changedOffers.add(offer);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
Reference in New Issue
Block a user