Files
spring-security-series/Spring-Boot/spring-rest-exception-handling/src/main/java/com/javadevjournal/controller/CustomerController.java
2020-02-03 22:08:28 -08:00

28 lines
882 B
Java

package com.javadevjournal.controller;
import com.javadevjournal.DefaultCustomerService;
import com.javadevjournal.data.Customer;
import com.javadevjournal.exception.CustomRestServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@RestController
@RequestMapping("/customers")
public class CustomerController {
@Autowired
DefaultCustomerService customerService;
@GetMapping("/customer/{id}")
public Customer getCustomer(@PathVariable long id) throws CustomRestServiceException {
return customerService.getCustomerById(id);
}
@PostMapping("/customer/register")
public Customer createCustomer(@Valid @RequestBody Customer customer) throws CustomRestServiceException {
return customerService.registerCustomer(customer);
}
}