@PUT @Path("/{customerId}") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation( value = "Updates an existing customer", notes = "This will update a customer with supplied id", response = Customer.class) @ApiResponses( value = { @ApiResponse(code = 200, message = "Customer has been updated"), @ApiResponse(code = 400, message = "Customer details supplied are invalid"), @ApiResponse(code = 404, message = "Customer not found") }) public Response updateCustomer( @PathParam("customerId") @ApiParam(value = "customer id to update", defaultValue = "1", required = true) final String customerId, @ApiParam(value = "customer data", required = true) final Customer customer) throws Exception { final Customer findCustomer = service.findCustomer(customerId); if (findCustomer == null) { return Response.status(Status.NOT_FOUND).entity(customerNotFound()).build(); } else { customer.setId(customerId); final Customer updatedCustomer = service.updateCustomer(customer); return Response.ok(updatedCustomer).build(); } }
@GET @Path("/{customerId}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation( value = "Get customer by id", notes = "This will retrieve a customer by id", response = Customer.class) @ApiResponses( value = { @ApiResponse(code = 200, message = "Customer found"), @ApiResponse(code = 404, message = "Customer not found") }) public Response getCustomer( @PathParam("customerId") @ApiParam(value = "customer id to get", defaultValue = "1", required = true) final String customerId) { final Customer customer = service.findCustomer(customerId); if (customer == null) return Response.status(Status.NOT_FOUND).entity(customerNotFound()).build(); else return Response.ok(customer).build(); }