import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* {@link CustomerDto} is a data transfer object POJO. Instead of sending individual information to
* client We can send related information together in POJO.
*
* <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;
}
import java.util.List;
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;
}
/**
* Save new customer.
*
* @param customer save new customer to list.
*/
public void save(CustomerDto customer) {
customers.add(customer);
}
/**
* Delete customer with given id.
*
* @param customerId delete customer with id {@code customerId}
*/
public void delete(String customerId) {
customers.removeIf(customer -> customer.getId().equals(customerId));
}
}