mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-20 18:24:15 +00:00
docs: data transfer object + refactor
This commit is contained in:
+1
-8
@@ -33,11 +33,4 @@ import lombok.RequiredArgsConstructor;
|
||||
*
|
||||
* <p>Dto will not have any business logic in it.
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerDto {
|
||||
private final String id;
|
||||
private final String firstName;
|
||||
private final String lastName;
|
||||
|
||||
}
|
||||
public record CustomerDto(String id, String firstName, String lastName) {}
|
||||
|
||||
+4
-15
@@ -25,25 +25,14 @@
|
||||
package com.iluwatar.datatransfer.customer;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* The resource class which serves customer information. This class act as server in the demo. Which
|
||||
* has all customer details.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerResource {
|
||||
private final List<CustomerDto> customers;
|
||||
|
||||
/**
|
||||
* Get all customers.
|
||||
*
|
||||
* @return : all customers in list.
|
||||
*/
|
||||
public List<CustomerDto> getAllCustomers() {
|
||||
return customers;
|
||||
}
|
||||
|
||||
public record CustomerResource(List<CustomerDto> customers) {
|
||||
/**
|
||||
* Save new customer.
|
||||
*
|
||||
@@ -59,6 +48,6 @@ public class CustomerResource {
|
||||
* @param customerId delete customer with id {@code customerId}
|
||||
*/
|
||||
public void delete(String customerId) {
|
||||
customers.removeIf(customer -> customer.getId().equals(customerId));
|
||||
customers.removeIf(customer -> customer.id().equals(customerId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user