Skip to content

Commit

Permalink
Use path instead of value in XXXMapping rest controller class.
Browse files Browse the repository at this point in the history
  • Loading branch information
czetsuya committed Jun 23, 2019
1 parent 2d9fc3a commit d0acd8c
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.broodcamp.web.assembler.CustomerResourceAssembler;

@RestController
//@RequestMapping("/v1/customers")
@RequestMapping("/v1/customers")
public class CustomerController {

@Autowired
Expand All @@ -41,7 +41,7 @@ public class CustomerController {
*
* @return list of customers
*/
@GetMapping("/v1/customers")
@GetMapping(path = "")
public Resources<Resource<Customer>> all() {
List<Resource<Customer>> entities = repository.findAll().stream().map(assembler::toResource)
.collect(Collectors.toList());
Expand All @@ -58,14 +58,14 @@ public Resources<Resource<Customer>> all() {
* @return newly created customer
* @throws URISyntaxException
*/
@PostMapping(value = "/v1/customers")
@PostMapping(path = "")
public ResponseEntity<Resource<Customer>> newCustomer(@RequestBody Customer newCustomer) throws URISyntaxException {

Resource<Customer> resource = assembler.toResource(repository.save(newCustomer));
return ResponseEntity.created(new URI(resource.getId().expand().getHref())).body(resource);
}

@PutMapping("/v1/customers/{id}")
@PutMapping(path = "/{id}")
public ResponseEntity<?> replaceCustomer(@RequestBody Customer newCustomer, @PathVariable Long id)
throws URISyntaxException {

Expand All @@ -91,7 +91,7 @@ public ResponseEntity<?> replaceCustomer(@RequestBody Customer newCustomer, @Pat
* @param id
* @return
*/
@DeleteMapping(value = "/v1/customers/{id}")
@DeleteMapping(path = "/{id}")
public ResponseEntity<String> deleteCustomer(@PathVariable Long id) {
repository.deleteById(id);
return ResponseEntity.noContent().build();
Expand All @@ -103,7 +103,7 @@ public ResponseEntity<String> deleteCustomer(@PathVariable Long id) {
* @param id
* @return customer detail
*/
@GetMapping(value = "/v1/customers/{id}")
@GetMapping(path = "/{id}")
public Resource<Customer> one(@PathVariable Long id) {

Customer entity = repository.findById(id).orElseThrow(() -> new CustomerNotFoundException(id));
Expand Down

0 comments on commit d0acd8c

Please sign in to comment.