@Bean public CustomerAdapter customerAdapter() { return new CustomerAdapter(customerService, customerEditService); } }
public CustomersDTO customers() { final List<Customer> customers = customerService.customers(); return new CustomersDTO(CustomerDTOFactory.customers(customers)); }
public void create(final CustomerDTO customerDTO) { notNull(customerDTO); customerEditService.create(CustomerFactory.customer(customerDTO)); }
private List<Link> customerLinks() { final CustomersDTO customers = customerAdapter.customers(); return customers.customers.stream() .map(cust -> linkTo(methodOn(CustomerController.class).customer(cust.id)).withRel(REL_CUSTOMER_PREFIX + cust.id)) .collect(Collectors.toList()); } }
public CustomerDTO customer(final long customerId) { final Customer customer = customerService.customer(Customer.Id.of(customerId)); return CustomerDTOFactory.customer(customer); }
@GetMapping(path = "/{customerId}") public ResponseEntity<Resource<CustomerDTO>> customer(@PathVariable final long customerId) { LOGGER.info("Getting customer {}", customerId); final ControllerLinkBuilder selfLink = linkTo(methodOn(CustomerController.class).customer(customerId)); final ControllerLinkBuilder updateLink = linkTo(CustomerController.class).slash(customerId); final ControllerLinkBuilder deleteLink = linkTo(CustomerController.class).slash(customerId); final Resource<CustomerDTO> customerDto = new Resource<>(customerAdapter.customer(customerId)); customerDto.add(selfLink.withSelfRel()); customerDto.add(homeLink()); customerDto.add(customersLink()); customerDto.add(updateLink.withRel(REL_UPDATE)); customerDto.add(deleteLink.withRel(REL_DELETE)); return ResponseEntity.ok(customerDto); }
@DeleteMapping(path = "/{customerId}") public ResponseEntity<?> delete(@PathVariable final long customerId) { customerAdapter.delete(customerId); return ResponseEntity.ok().location(URI.create(customersLink().getHref())).build(); }
public static CustomerDTO customer(final Customer customer) { return new CustomerDTO(customer.getId().getId(), name(customer.getName())); }
@PostMapping(consumes = APPLICATION_JSON_V1_VALUE) public ResponseEntity<?> create(@RequestBody @Valid final CustomerDTO customerDto) { customerAdapter.create(customerDto); return ResponseEntity.created(URI.create(customersLink().getHref())).build(); }
public static Customer customer(final CustomerDTO customer) { return Customer.of(Customer.Id.of(customer.id), name(customer.name)); }
public static CustomersDTO customersDTO() { final List<CustomerDTO> customers = CustomerDTOFactory.customers(ImmutableList.of(customer())); return new CustomersDTO(customers); } }
@GetMapping public ResponseEntity<Resource<CustomersDTO>> customers() { final ControllerLinkBuilder selfLink = linkTo(methodOn(CustomerController.class).customers()); final ControllerLinkBuilder createLink = linkTo(CustomerController.class); final Resource<CustomersDTO> customersDto = new Resource<>(customerAdapter.customers()); customersDto.add(selfLink.withSelfRel()); customersDto.add(homeLink()); customersDto.add(createLink.withRel(REL_CREATE)); customersDto.add(customerLinks()); return ResponseEntity.ok(customersDto); }
public static CustomerDTO customerDTO() { return CustomerDTOFactory.customer(customer()); }
@Test public void shouldValidateCustomerSchema() throws Exception { given(customerAdapter.customer(any(Long.class))).willReturn(customerDTO()); final ResultActions result = RestHelper.get(mvc, API_CUSTOMERS_PATH + "/123"); assertSuccessfulSchemaValidation(result, "CustomerDTOSchema.json"); } }
@Before public void setUp() throws Exception { customerAdapter = new CustomerAdapter(customerService, customerEditService); }
public void update(final CustomerDTO customerDTO) { notNull(customerDTO); customerEditService.update(CustomerFactory.customer(customerDTO)); }
@Test public void shouldDeleteCustomer() throws Exception { customerAdapter.delete(customer().getId().getId()); verify(customerEditService, times(1)).delete(customer().getId()); } }
@Test public void shouldValidateCustomersSchema() throws Exception { given(customerAdapter.customers()).willReturn(customersDTO()); final ResultActions result = RestHelper.get(mvc, API_CUSTOMERS_PATH); assertSuccessfulSchemaValidation(result, "CustomersDTOSchema.json"); }