fix(back-end): forse risolviamo il problema
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.printcalculator.controller;
|
package com.printcalculator.controller;
|
||||||
|
|
||||||
|
import com.printcalculator.dto.*;
|
||||||
import com.printcalculator.entity.*;
|
import com.printcalculator.entity.*;
|
||||||
import com.printcalculator.repository.*;
|
import com.printcalculator.repository.*;
|
||||||
import com.printcalculator.service.InvoicePdfRenderingService;
|
import com.printcalculator.service.InvoicePdfRenderingService;
|
||||||
@@ -56,7 +57,7 @@ public class OrderController {
|
|||||||
// 1. Create Order from Quote
|
// 1. Create Order from Quote
|
||||||
@PostMapping("/from-quote/{quoteSessionId}")
|
@PostMapping("/from-quote/{quoteSessionId}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<Order> createOrderFromQuote(
|
public ResponseEntity<OrderDto> createOrderFromQuote(
|
||||||
@PathVariable UUID quoteSessionId,
|
@PathVariable UUID quoteSessionId,
|
||||||
@RequestBody com.printcalculator.dto.CreateOrderRequest request
|
@RequestBody com.printcalculator.dto.CreateOrderRequest request
|
||||||
) {
|
) {
|
||||||
@@ -194,7 +195,10 @@ public class OrderController {
|
|||||||
session.setStatus("CONVERTED");
|
session.setStatus("CONVERTED");
|
||||||
quoteSessionRepo.save(session);
|
quoteSessionRepo.save(session);
|
||||||
|
|
||||||
return ResponseEntity.ok(orderRepo.save(order));
|
order = orderRepo.save(order);
|
||||||
|
List<OrderItem> finalItems = orderItemRepo.findByOrder_Id(order.getId());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(convertToDto(order, finalItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/{orderId}/items/{orderItemId}/file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/{orderId}/items/{orderItemId}/file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
@@ -230,9 +234,12 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{orderId}")
|
@GetMapping("/{orderId}")
|
||||||
public ResponseEntity<Order> getOrder(@PathVariable UUID orderId) {
|
public ResponseEntity<OrderDto> getOrder(@PathVariable UUID orderId) {
|
||||||
return orderRepo.findById(orderId)
|
return orderRepo.findById(orderId)
|
||||||
.map(ResponseEntity::ok)
|
.map(o -> {
|
||||||
|
List<OrderItem> items = orderItemRepo.findByOrder_Id(o.getId());
|
||||||
|
return ResponseEntity.ok(convertToDto(o, items));
|
||||||
|
})
|
||||||
.orElse(ResponseEntity.notFound().build());
|
.orElse(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,9 +276,6 @@ public class OrderController {
|
|||||||
return line;
|
return line;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
// Add Setup and Shipping as line items too? Or separate in template?
|
|
||||||
// Template has invoiceLineItems loop. Let's add them there for simplicity or separate.
|
|
||||||
// Let's add them to the list.
|
|
||||||
Map<String, Object> setupLine = new HashMap<>();
|
Map<String, Object> setupLine = new HashMap<>();
|
||||||
setupLine.put("description", "Costo Setup");
|
setupLine.put("description", "Costo Setup");
|
||||||
setupLine.put("quantity", 1);
|
setupLine.put("quantity", 1);
|
||||||
@@ -308,4 +312,64 @@ public class OrderController {
|
|||||||
return "stl";
|
return "stl";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OrderDto convertToDto(Order order, List<OrderItem> items) {
|
||||||
|
OrderDto dto = new OrderDto();
|
||||||
|
dto.setId(order.getId());
|
||||||
|
dto.setStatus(order.getStatus());
|
||||||
|
dto.setCustomerEmail(order.getCustomerEmail());
|
||||||
|
dto.setCustomerPhone(order.getCustomerPhone());
|
||||||
|
dto.setBillingCustomerType(order.getBillingCustomerType());
|
||||||
|
dto.setCurrency(order.getCurrency());
|
||||||
|
dto.setSetupCostChf(order.getSetupCostChf());
|
||||||
|
dto.setShippingCostChf(order.getShippingCostChf());
|
||||||
|
dto.setDiscountChf(order.getDiscountChf());
|
||||||
|
dto.setSubtotalChf(order.getSubtotalChf());
|
||||||
|
dto.setTotalChf(order.getTotalChf());
|
||||||
|
dto.setCreatedAt(order.getCreatedAt());
|
||||||
|
dto.setShippingSameAsBilling(order.getShippingSameAsBilling());
|
||||||
|
|
||||||
|
AddressDto billing = new AddressDto();
|
||||||
|
billing.setFirstName(order.getBillingFirstName());
|
||||||
|
billing.setLastName(order.getBillingLastName());
|
||||||
|
billing.setCompanyName(order.getBillingCompanyName());
|
||||||
|
billing.setContactPerson(order.getBillingContactPerson());
|
||||||
|
billing.setAddressLine1(order.getBillingAddressLine1());
|
||||||
|
billing.setAddressLine2(order.getBillingAddressLine2());
|
||||||
|
billing.setZip(order.getBillingZip());
|
||||||
|
billing.setCity(order.getBillingCity());
|
||||||
|
billing.setCountryCode(order.getBillingCountryCode());
|
||||||
|
dto.setBillingAddress(billing);
|
||||||
|
|
||||||
|
if (!order.getShippingSameAsBilling()) {
|
||||||
|
AddressDto shipping = new AddressDto();
|
||||||
|
shipping.setFirstName(order.getShippingFirstName());
|
||||||
|
shipping.setLastName(order.getShippingLastName());
|
||||||
|
shipping.setCompanyName(order.getShippingCompanyName());
|
||||||
|
shipping.setContactPerson(order.getShippingContactPerson());
|
||||||
|
shipping.setAddressLine1(order.getShippingAddressLine1());
|
||||||
|
shipping.setAddressLine2(order.getShippingAddressLine2());
|
||||||
|
shipping.setZip(order.getShippingZip());
|
||||||
|
shipping.setCity(order.getShippingCity());
|
||||||
|
shipping.setCountryCode(order.getShippingCountryCode());
|
||||||
|
dto.setShippingAddress(shipping);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<OrderItemDto> itemDtos = items.stream().map(i -> {
|
||||||
|
OrderItemDto idto = new OrderItemDto();
|
||||||
|
idto.setId(i.getId());
|
||||||
|
idto.setOriginalFilename(i.getOriginalFilename());
|
||||||
|
idto.setMaterialCode(i.getMaterialCode());
|
||||||
|
idto.setColorCode(i.getColorCode());
|
||||||
|
idto.setQuantity(i.getQuantity());
|
||||||
|
idto.setPrintTimeSeconds(i.getPrintTimeSeconds());
|
||||||
|
idto.setMaterialGrams(i.getMaterialGrams());
|
||||||
|
idto.setUnitPriceChf(i.getUnitPriceChf());
|
||||||
|
idto.setLineTotalChf(i.getLineTotalChf());
|
||||||
|
return idto;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
dto.setItems(itemDtos);
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
74
backend/src/main/java/com/printcalculator/dto/OrderDto.java
Normal file
74
backend/src/main/java/com/printcalculator/dto/OrderDto.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OrderDto {
|
||||||
|
private UUID id;
|
||||||
|
private String status;
|
||||||
|
private String customerEmail;
|
||||||
|
private String customerPhone;
|
||||||
|
private String billingCustomerType;
|
||||||
|
private AddressDto billingAddress;
|
||||||
|
private AddressDto shippingAddress;
|
||||||
|
private Boolean shippingSameAsBilling;
|
||||||
|
private String currency;
|
||||||
|
private BigDecimal setupCostChf;
|
||||||
|
private BigDecimal shippingCostChf;
|
||||||
|
private BigDecimal discountChf;
|
||||||
|
private BigDecimal subtotalChf;
|
||||||
|
private BigDecimal totalChf;
|
||||||
|
private OffsetDateTime createdAt;
|
||||||
|
private List<OrderItemDto> items;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public UUID getId() { return id; }
|
||||||
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getStatus() { return status; }
|
||||||
|
public void setStatus(String status) { this.status = status; }
|
||||||
|
|
||||||
|
public String getCustomerEmail() { return customerEmail; }
|
||||||
|
public void setCustomerEmail(String customerEmail) { this.customerEmail = customerEmail; }
|
||||||
|
|
||||||
|
public String getCustomerPhone() { return customerPhone; }
|
||||||
|
public void setCustomerPhone(String customerPhone) { this.customerPhone = customerPhone; }
|
||||||
|
|
||||||
|
public String getBillingCustomerType() { return billingCustomerType; }
|
||||||
|
public void setBillingCustomerType(String billingCustomerType) { this.billingCustomerType = billingCustomerType; }
|
||||||
|
|
||||||
|
public AddressDto getBillingAddress() { return billingAddress; }
|
||||||
|
public void setBillingAddress(AddressDto billingAddress) { this.billingAddress = billingAddress; }
|
||||||
|
|
||||||
|
public AddressDto getShippingAddress() { return shippingAddress; }
|
||||||
|
public void setShippingAddress(AddressDto shippingAddress) { this.shippingAddress = shippingAddress; }
|
||||||
|
|
||||||
|
public Boolean getShippingSameAsBilling() { return shippingSameAsBilling; }
|
||||||
|
public void setShippingSameAsBilling(Boolean shippingSameAsBilling) { this.shippingSameAsBilling = shippingSameAsBilling; }
|
||||||
|
|
||||||
|
public String getCurrency() { return currency; }
|
||||||
|
public void setCurrency(String currency) { this.currency = currency; }
|
||||||
|
|
||||||
|
public BigDecimal getSetupCostChf() { return setupCostChf; }
|
||||||
|
public void setSetupCostChf(BigDecimal setupCostChf) { this.setupCostChf = setupCostChf; }
|
||||||
|
|
||||||
|
public BigDecimal getShippingCostChf() { return shippingCostChf; }
|
||||||
|
public void setShippingCostChf(BigDecimal shippingCostChf) { this.shippingCostChf = shippingCostChf; }
|
||||||
|
|
||||||
|
public BigDecimal getDiscountChf() { return discountChf; }
|
||||||
|
public void setDiscountChf(BigDecimal discountChf) { this.discountChf = discountChf; }
|
||||||
|
|
||||||
|
public BigDecimal getSubtotalChf() { return subtotalChf; }
|
||||||
|
public void setSubtotalChf(BigDecimal subtotalChf) { this.subtotalChf = subtotalChf; }
|
||||||
|
|
||||||
|
public BigDecimal getTotalChf() { return totalChf; }
|
||||||
|
public void setTotalChf(BigDecimal totalChf) { this.totalChf = totalChf; }
|
||||||
|
|
||||||
|
public OffsetDateTime getCreatedAt() { return createdAt; }
|
||||||
|
public void setCreatedAt(OffsetDateTime createdAt) { this.createdAt = createdAt; }
|
||||||
|
|
||||||
|
public List<OrderItemDto> getItems() { return items; }
|
||||||
|
public void setItems(List<OrderItemDto> items) { this.items = items; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.printcalculator.dto;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OrderItemDto {
|
||||||
|
private UUID id;
|
||||||
|
private String originalFilename;
|
||||||
|
private String materialCode;
|
||||||
|
private String colorCode;
|
||||||
|
private Integer quantity;
|
||||||
|
private Integer printTimeSeconds;
|
||||||
|
private BigDecimal materialGrams;
|
||||||
|
private BigDecimal unitPriceChf;
|
||||||
|
private BigDecimal lineTotalChf;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public UUID getId() { return id; }
|
||||||
|
public void setId(UUID id) { this.id = id; }
|
||||||
|
|
||||||
|
public String getOriginalFilename() { return originalFilename; }
|
||||||
|
public void setOriginalFilename(String originalFilename) { this.originalFilename = originalFilename; }
|
||||||
|
|
||||||
|
public String getMaterialCode() { return materialCode; }
|
||||||
|
public void setMaterialCode(String materialCode) { this.materialCode = materialCode; }
|
||||||
|
|
||||||
|
public String getColorCode() { return colorCode; }
|
||||||
|
public void setColorCode(String colorCode) { this.colorCode = colorCode; }
|
||||||
|
|
||||||
|
public Integer getQuantity() { return quantity; }
|
||||||
|
public void setQuantity(Integer quantity) { this.quantity = quantity; }
|
||||||
|
|
||||||
|
public Integer getPrintTimeSeconds() { return printTimeSeconds; }
|
||||||
|
public void setPrintTimeSeconds(Integer printTimeSeconds) { this.printTimeSeconds = printTimeSeconds; }
|
||||||
|
|
||||||
|
public BigDecimal getMaterialGrams() { return materialGrams; }
|
||||||
|
public void setMaterialGrams(BigDecimal materialGrams) { this.materialGrams = materialGrams; }
|
||||||
|
|
||||||
|
public BigDecimal getUnitPriceChf() { return unitPriceChf; }
|
||||||
|
public void setUnitPriceChf(BigDecimal unitPriceChf) { this.unitPriceChf = unitPriceChf; }
|
||||||
|
|
||||||
|
public BigDecimal getLineTotalChf() { return lineTotalChf; }
|
||||||
|
public void setLineTotalChf(BigDecimal lineTotalChf) { this.lineTotalChf = lineTotalChf; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user