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
4 changes: 0 additions & 4 deletions backend/sql/sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ UPDATE orders
SET payment_status = 'COMPLETED'
WHERE id = 2;

UPDATE rentals
SET status = 'RETURN_IN_PROGRESS'
WHERE id = 1;

-- Rental table for tracking rentals (because they can be partial)
INSERT INTO rental_returns (return_order_id, returned_at, status)
VALUES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public interface RentalRepository extends JpaRepository<Rental, Integer> {
SELECT r FROM Rental r
WHERE r.user = :user
AND r.status != 'RETURNED'
AND r.status != 'RETURN_IN_PROGRESS'
ORDER BY
CASE r.status
WHEN 'RENTED' THEN 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ public PageResponseDTO<RentalDTO> getUserRentals(Pageable pageable) {

List<RentalDTO> rentalDTOs = rentals.getContent().stream()
.map(rental -> {
int remainingQuantity = rental.getQuantity();
if (rental.getStatus() == RentalStatus.PARTIALLY_RETURNED) {
int returned = rentalReturnItemService.sumReturnedQuantityByRentalId(rental.getId());
remainingQuantity -= returned;
}
rental.setQuantity(remainingQuantity);
return rentalMapper.map(rental);
int totalReturned = rentalReturnItemService.sumReturnedQuantityByRentalId(rental.getId());
int remaining = rental.getQuantity() - totalReturned;

RentalDTO dto = rentalMapper.map(rental);
dto.setQuantity(remaining);
return dto;
})
.toList();

Expand Down