сумму починил ) готово
This commit is contained in:
parent
8f95825cb0
commit
325faa8791
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -9,6 +9,8 @@ import com.example.demo.order_lines.api.OrderLineDto;
|
||||
import com.example.demo.order_lines.model.OrderLineEntity;
|
||||
import com.example.demo.orders.model.OrderEntity;
|
||||
import com.example.demo.orders.service.OrderService;
|
||||
import com.example.demo.products.model.ProductEntity;
|
||||
import com.example.demo.products.service.ProductService;
|
||||
import com.example.demo.users.service.UserService;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@ -18,10 +20,13 @@ public class OrderController {
|
||||
private final OrderService orderService;
|
||||
private final UserService userService;
|
||||
private final ModelMapper modelMapper;
|
||||
private final ProductService productService;
|
||||
|
||||
public OrderController(OrderService orderService, UserService userService, ModelMapper modelMapper) {
|
||||
public OrderController(OrderService orderService, UserService userService, ModelMapper modelMapper,
|
||||
ProductService productService) {
|
||||
this.orderService = orderService;
|
||||
this.userService = userService;
|
||||
this.productService = productService;
|
||||
this.modelMapper = modelMapper;
|
||||
}
|
||||
|
||||
@ -34,7 +39,9 @@ public class OrderController {
|
||||
OrderLineDto orderLineDto = new OrderLineDto();
|
||||
orderLineDto.setProductId(orderLineEntity.getProduct().getId());
|
||||
orderLineDto.setCount(orderLineEntity.getCount());
|
||||
orderLineDto.setTotalPriceLine(orderLineEntity.getTotalPrice());
|
||||
// Вычисляем общую цену строки заказа
|
||||
Double totalPriceLine = orderLineEntity.getProduct().getPrice() * orderLineEntity.getCount();
|
||||
orderLineDto.setTotalPriceLine(totalPriceLine);
|
||||
dto.addOrderLine(orderLineDto);
|
||||
}
|
||||
return dto;
|
||||
@ -48,6 +55,9 @@ public class OrderController {
|
||||
entity.getLines().clear();
|
||||
for (OrderLineDto lineDto : dto.getLines()) {
|
||||
OrderLineEntity orderLineEntity = modelMapper.map(lineDto, OrderLineEntity.class);
|
||||
// Здесь нужно установить ProductEntity для OrderLineEntity
|
||||
ProductEntity product = productService.get(lineDto.getProductId()); // Получаем продукт по его ID
|
||||
orderLineEntity.setProduct(product); // Устанавливаем продукт для строки заказа
|
||||
entity.addOrderLine(orderLineEntity);
|
||||
}
|
||||
return entity;
|
||||
|
@ -73,6 +73,7 @@ public class OrderEntity extends BaseEntity {
|
||||
}
|
||||
|
||||
public Double calculateTotalOrderPrice() {
|
||||
totalPrice = 0.0;
|
||||
for (OrderLineEntity orderLine : lines) {
|
||||
totalPrice += orderLine.getProduct().getPrice() * orderLine.getCount();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class ProductService {
|
||||
}
|
||||
|
||||
public ProductEntity create(ProductEntity entity) {
|
||||
entity.setPrice(entity.getPrice());
|
||||
return repository.create(entity);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user