Skip to content
Merged
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
Expand Up @@ -1093,7 +1093,13 @@ public ResponseEntity<Object> respondToBid(
String notifyStoreBidNotApproved = String.format(
"Bid %s for product %s was approved by %s not approved yet, please reply to the bid",
bid.getId(), product.getName(), owner.getEmail());
notifyStoreBidNotApproved(storeId, notifyStoreBidNotApproved, bid.getOwnerApprovals());

String message = String.format(
"New bid placed for %s:\n - Price: %.2f\n - Bid ID: %s\n - Product ID: %s",
product.getName(), bid.getBidAmount(), bid.getId(), productId);
messageService.sendMessageToStoreBid(storeId, "System", message, "waiting for approval", bid.getId(),
bid.getOwnerApprovals(), true);
notifyStoreBidNotApproved(storeId, notifyStoreBidNotApproved, bid.getOwnerApprovals());

log.info("Bid {} approved by owner {}, still waiting for other owners",
bidId, owner.getEmail());
Expand All @@ -1108,7 +1114,7 @@ public ResponseEntity<Object> respondToBid(
"Bid for %s rejected by %s\n- Bid ID: %s\n- Product ID: %s",
product.getName(), owner.getEmail(), bid.getId(), product.getId());
messageService.sendMessageToStoreBid(storeId, "System", message, "cancel", bid.getId(),
bid.getOwnerApprovals());
bid.getOwnerApprovals(),false);
log.info("Bid {} rejected by owner {}", bidId, owner.getEmail());
store.removePendingBid(productId, bidId); // remove the old bid
storeService.save(store);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ public ResponseEntity<Object> respondToBidOffer(
log.info("Counter offer accepted for product {} with id {} by user {}, awaiting approval from store managers",
product.getName(), b.getProductID(), member.getEmail());
if(messageService.sendMessageToStoreBid(storeId, member.getEmail(), message, "waiting for approval",
bidId, b.getOwnerApprovals())) {
bidId, b.getOwnerApprovals(),false)) {
log.info("Counter offer accepted for product {} with id {} by user {}, awaiting approval from store managers",
product.getName(), product.getId(), member.getEmail());
return ResponseEntity.ok("Counter offer sent to store managers for approval");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void finishMsg(String msgID, Member member) {
}

public boolean sendMessageToStoreBid(String storeId, String email, String message, String status, String bidId,
Set<String> ownerApprovals) {
Set<String> ownerApprovals, boolean newOwners) {
List<String> storeManagers = storeRepository.getBidManagersEmails(storeId);
for(String owner: ownerApprovals) {
if(storeManagers.contains(owner)) {
Expand All @@ -191,22 +191,47 @@ public boolean sendMessageToStoreBid(String storeId, String email, String messag
if (manager == null) {
continue; // Manager not found
}
for(DirectMessage dm : manager.getDMs().values()) {
if(!newOwners){
for(DirectMessage dm : manager.getDMs().values()) {
if (dm instanceof PurchaseDirectMessage&&
extractBidIDandComp(dm.getMessage(), bidId)){
dm.setRead(true); // If the message already exists, skip sending it
((PurchaseDirectMessage)dm).setStatus("done"); // Update the message content
}
// If the message already exists, skip sending it

}
// Create a new DirectMessage object and add it to the manager's DMs
PurchaseDirectMessage directMessage = new PurchaseDirectMessage(storeId, managerEmail,storeId, message,
PurchaseDirectMessage directMessage = new PurchaseDirectMessage(storeId, managerEmail,storeId, message,
new Date(System.currentTimeMillis()).toString(), false, UUID.randomUUID().toString(), status, bidId);
manager.addDMs(directMessage); // Add the message to the manager's DMs
userRepository.save(manager); // Save the manager to persist the message

}
else{
boolean oldMessageExists = false;
for(DirectMessage dm : manager.getDMs().values() ) {

if (dm instanceof PurchaseDirectMessage&&
extractBidIDandComp(dm.getMessage(), bidId)&!dm.getMessage().startsWith("Bid for")){
oldMessageExists = true; // If the message already exists, skip sending it
break;
}
}
// If the message already exists, skip sending it
if (!oldMessageExists) {
PurchaseDirectMessage directMessage = new PurchaseDirectMessage(storeId, managerEmail,storeId, message,
new Date(System.currentTimeMillis()).toString(), false, UUID.randomUUID().toString(), status, bidId);
manager.addDMs(directMessage); // Add the message to the manager's DMs
userRepository.save(manager); // Save the manager to persist the message
}
}

// Create a new DirectMessage object and add it to the manager's DMs

}
return true; // Message sent successfully
}

private boolean extractBidIDandComp(String msg, String bidID) {
// Extract the bid ID from the message
// Extract bidId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ private void acceptBid() {
close();

} else {
showError("Error: " + response);
if(response.contains("Approved")){
showSuccess(response);
}
else
showError("Error: " + response);
}
});
});
Expand Down