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
Empty file modified mvnw
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,22 @@ public ResponseEntity<String> deleteBidsBeforeDate(@PathVariable String date) {
throw new RuntimeException("Error deleting bids: " + e.getMessage());
}
}

/**
* Update bids placed before the given date to the specified status.
* @param date ISO-8601 date-time string for cutoff
* @param status new status to apply to matching bids
* @return indication of how many bids were updated
*/
@PutMapping("/update/{date}/{status}")
public ResponseEntity<String> updateBidsBeforeDate(@PathVariable String date,
@PathVariable Bid.BidStatus status) {
try {
LocalDateTime cutoff = LocalDateTime.parse(date);
int updated = bidService.updateBidsBefore(cutoff, status);
return ResponseEntity.ok(updated + " bids updated successfully");
} catch (Exception e) {
throw new RuntimeException("Error updating bids: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import com.marketplace.onlinemarketplace.entity.Bid;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.time.LocalDateTime;
import java.util.List;

public interface BidRepo extends JpaRepository<Bid, Long> {
List<Bid> findByProjectId(Long projectId);
List<Bid> findByProjectIdAndStatus(Long projectId, Bid.BidStatus status);

void deleteByBidDateBefore(LocalDateTime date);

@Modifying
@Transactional
@Query("update Bid b set b.status = :status where b.bidDate < :date")
int updateStatusByBidDateBefore(@Param("status") Bid.BidStatus status, @Param("date") LocalDateTime date);


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.marketplace.onlinemarketplace.repository.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -105,5 +106,15 @@ public List<Bid> getAllBids() {
public void deleteBidsBefore(LocalDateTime date) {
bidRepo.deleteByBidDateBefore(date);
}
}

/**
* Update the status of bids placed before the given date.
* @param date cutoff date; bids before this date will be updated
* @param status new status to set for matching bids
* @return the number of bids updated
*/
@Transactional
public int updateBidsBefore(LocalDateTime date, Bid.BidStatus status) {
return bidRepo.updateStatusByBidDateBefore(status, date);
}
}