Skip to content

Commit

Permalink
Merge pull request #30027 from wonwoo
Browse files Browse the repository at this point in the history
* gh-30027:
  Polish RestController examples

Closes gh-30027
  • Loading branch information
wilkinsona committed Mar 3, 2022
2 parents 57f935f + c2bf0d5 commit ef92762
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public MyRestController(UserRepository userRepository, CustomerRepository custom
this.customerRepository = customerRepository;
}

@GetMapping("/{user}")
@GetMapping("/{userId}")
public User getUser(@PathVariable Long userId) {
return this.userRepository.findById(userId).get();
}

@GetMapping("/{user}/customers")
@GetMapping("/{userId}/customers")
public List<Customer> getUserCustomers(@PathVariable Long userId) {
return this.userRepository.findById(userId).map(this.customerRepository::findByUser).get();
}

@DeleteMapping("/{user}")
@DeleteMapping("/{userId}")
public void deleteUser(@PathVariable Long userId) {
this.userRepository.deleteById(userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public MyRestController(UserRepository userRepository, CustomerRepository custom
this.customerRepository = customerRepository;
}

@GetMapping("/{user}")
@GetMapping("/{userId}")
public Mono<User> getUser(@PathVariable Long userId) {
return this.userRepository.findById(userId);
}

@GetMapping("/{user}/customers")
@GetMapping("/{userId}/customers")
public Flux<Customer> getUserCustomers(@PathVariable Long userId) {
return this.userRepository.findById(userId).flatMapMany(this.customerRepository::findByUser);
}

@DeleteMapping("/{user}")
public void deleteUser(@PathVariable Long userId) {
this.userRepository.deleteById(userId);
@DeleteMapping("/{userId}")
public Mono<Void> deleteUser(@PathVariable Long userId) {
return this.userRepository.deleteById(userId);
}

}

0 comments on commit ef92762

Please sign in to comment.