OrderProductView.java

package cz.vsb.crm.dto;

import cz.vsb.crm.model.OrderProduct;

import java.math.BigDecimal;

public record OrderProductView(
        Long id,
        Long orderId,
        Long productId,
        String productName,
        Integer quantity,
        BigDecimal unitPrice,
        BigDecimal subtotal) {

    public static OrderProductView from(OrderProduct orderProduct) {
        return new OrderProductView(
                orderProduct.getId(),
                orderProduct.getOrder().getId(),
                orderProduct.getProduct().getId(),
                orderProduct.getProduct().getName(),
                orderProduct.getQuantity(),
                orderProduct.getUnitPrice(),
                orderProduct.getSubtotal());
    }
}