Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 63985cc

Browse files
committed
adding additional fields to OrderShippingInfo
1 parent 5497993 commit 63985cc

9 files changed

Lines changed: 99 additions & 7 deletions

File tree

src/main/java/com/zenfulcode/commercify/commercify/api/requests/orders/CreateOrderRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.zenfulcode.commercify.commercify.api.requests.orders;
22

33
import com.zenfulcode.commercify.commercify.dto.AddressDTO;
4+
import com.zenfulcode.commercify.commercify.dto.CustomerDetailsDTO;
45

56
import java.util.List;
67

78
public record CreateOrderRequest(
89
String currency,
10+
CustomerDetailsDTO customerDetails,
911
List<CreateOrderLineRequest> orderLines,
1012
AddressDTO shippingAddress,
1113
AddressDTO billingAddress
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.zenfulcode.commercify.commercify.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
7+
@Builder
8+
@Data
9+
@AllArgsConstructor
10+
public class CustomerDetailsDTO {
11+
private String firstName;
12+
private String lastName;
13+
private String email;
14+
private String phone;
15+
}

src/main/java/com/zenfulcode/commercify/commercify/dto/OrderDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
public class OrderDTO {
1414
private Long id;
1515
private Long userId;
16-
private OrderStatus orderStatus;
1716
private String currency;
1817
private Double totalAmount;
18+
private OrderStatus orderStatus;
1919
private Instant createdAt;
2020
private Instant updatedAt;
2121
}

src/main/java/com/zenfulcode/commercify/commercify/dto/OrderDetailsDTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
public class OrderDetailsDTO {
1313
private OrderDTO order;
1414
private List<OrderLineDTO> orderLines;
15+
private CustomerDetailsDTO customerDetails;
16+
private AddressDTO shippingAddress;
17+
private AddressDTO billingAddress;
1518
}

src/main/java/com/zenfulcode/commercify/commercify/dto/mapper/OrderMapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ public OrderDTO apply(OrderEntity order) {
2323
.totalAmount(order.getTotalAmount())
2424
.build();
2525
}
26-
2726
}

src/main/java/com/zenfulcode/commercify/commercify/entity/OrderShippingInfo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public class OrderShippingInfo {
1717
@Column(name = "id", nullable = false)
1818
private Long id;
1919

20+
@Column(name = "customer_first_name", nullable = false)
21+
private String customerFirstName;
22+
@Column(name = "customer_last_name", nullable = false)
23+
private String customerLastName;
24+
@Column(name = "customer_email", nullable = false)
25+
private String customerEmail;
26+
@Column(name = "customer_phone", nullable = false)
27+
private String customerPhone;
28+
2029
@Column(name = "shipping_street", nullable = false)
2130
private String shippingStreet;
2231
@Column(name = "shipping_city", nullable = false)

src/main/java/com/zenfulcode/commercify/commercify/service/order/OrderService.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import com.zenfulcode.commercify.commercify.OrderStatus;
44
import com.zenfulcode.commercify.commercify.api.requests.orders.CreateOrderLineRequest;
55
import com.zenfulcode.commercify.commercify.api.requests.orders.CreateOrderRequest;
6-
import com.zenfulcode.commercify.commercify.dto.AddressDTO;
7-
import com.zenfulcode.commercify.commercify.dto.OrderDTO;
8-
import com.zenfulcode.commercify.commercify.dto.OrderDetailsDTO;
9-
import com.zenfulcode.commercify.commercify.dto.OrderLineDTO;
6+
import com.zenfulcode.commercify.commercify.dto.*;
7+
import com.zenfulcode.commercify.commercify.dto.mapper.AddressMapper;
108
import com.zenfulcode.commercify.commercify.dto.mapper.OrderMapper;
119
import com.zenfulcode.commercify.commercify.dto.mapper.ProductMapper;
1210
import com.zenfulcode.commercify.commercify.dto.mapper.ProductVariantMapper;
@@ -43,6 +41,7 @@ public class OrderService {
4341
private final ProductVariantRepository variantRepository;
4442
private final ProductVariantMapper productVariantMapper;
4543
private final OrderShippingInfoRepository orderShippingInfoRepository;
44+
private final AddressMapper addressMapper;
4645

4746
@Transactional
4847
public OrderDTO createOrder(Long userId, CreateOrderRequest request) {
@@ -250,6 +249,34 @@ private OrderDetailsDTO buildOrderDetailsDTO(OrderEntity order) {
250249
})
251250
.collect(Collectors.toList());
252251

253-
return new OrderDetailsDTO(orderMapper.apply(order), orderLines);
252+
OrderDTO orderDTO = orderMapper.apply(order);
253+
254+
OrderShippingInfo shippingInfo = order.getOrderShippingInfo();
255+
256+
System.out.println("shippingInfo = " + shippingInfo);
257+
258+
CustomerDetailsDTO customerDetails = CustomerDetailsDTO.builder()
259+
.email(shippingInfo.getCustomerEmail())
260+
.firstName(shippingInfo.getCustomerFirstName())
261+
.lastName(shippingInfo.getCustomerLastName())
262+
.build();
263+
264+
AddressDTO shippingAddress = AddressDTO.builder()
265+
.city(shippingInfo.getShippingCity())
266+
.country(shippingInfo.getShippingCountry())
267+
.state(shippingInfo.getShippingState())
268+
.street(shippingInfo.getShippingStreet())
269+
.zipCode(shippingInfo.getShippingZip())
270+
.build();
271+
272+
AddressDTO billingAddress = AddressDTO.builder()
273+
.city(shippingInfo.getBillingCity())
274+
.country(shippingInfo.getBillingCountry())
275+
.state(shippingInfo.getBillingState())
276+
.street(shippingInfo.getBillingStreet())
277+
.zipCode(shippingInfo.getBillingZip())
278+
.build();
279+
280+
return new OrderDetailsDTO(orderDTO, orderLines, customerDetails, shippingAddress, billingAddress);
254281
}
255282
}

src/main/resources/db/changelog/db.changelog-master.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
<include file="db/changelog/migrations/241127144629-changelog.xml"/>
1313
<include file="db/changelog/migrations/241201215506-changelog.xml"/>
1414
<include file="db/changelog/migrations/241223151914-changelog.xml"/>
15+
<include file="db/changelog/migrations/241228215224-changelog.xml"/>
16+
<!-- <include file="db/changelog/migrations/241228214702-additional-fields-to-order-info-changelog.xml"/>-->
1517
</databaseChangeLog>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
6+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd"
7+
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
8+
<changeSet id="1735419144093-1" author="gkhaavik">
9+
<addColumn tableName="order_shipping_info">
10+
<column name="customer_email" type="VARCHAR(255)"/>
11+
<column name="customer_first_name" type="VARCHAR(255)"/>
12+
<column name="customer_last_name" type="VARCHAR(255)"/>
13+
<column name="customer_phone" type="VARCHAR(255)"/>
14+
</addColumn>
15+
</changeSet>
16+
<changeSet id="1735419144093-2" author="gkhaavik">
17+
<addNotNullConstraint columnDataType="VARCHAR(255)" columnName="customer_email" tableName="order_shipping_info"
18+
defaultNullValue="NIL"/>
19+
</changeSet>
20+
<changeSet id="1735419144093-4" author="gkhaavik">
21+
<addNotNullConstraint columnDataType="VARCHAR(255)" columnName="customer_first_name"
22+
tableName="order_shipping_info"
23+
defaultNullValue="NIL"/>
24+
</changeSet>
25+
<changeSet id="1735419144093-6" author="gkhaavik">
26+
<addNotNullConstraint columnDataType="VARCHAR(255)" columnName="customer_last_name"
27+
tableName="order_shipping_info"
28+
defaultNullValue="NIL"/>
29+
</changeSet>
30+
<changeSet id="1735419144093-8" author="gkhaavik">
31+
<addNotNullConstraint columnDataType="VARCHAR(255)" columnName="customer_phone" tableName="order_shipping_info"
32+
defaultNullValue="NIL"/>
33+
</changeSet>
34+
35+
</databaseChangeLog>

0 commit comments

Comments
 (0)