Skip to main content

Execute commands from a Rest Controller

· One min read
Defrim Hasani
tip

You can clone an already prepared sample which is built on top of spring boot using the spring boot starter library.

src/adapters/rest/UsersController.java
@RestController
@RequestMapping("/users")
public class UsersController {

private final AlbanoiGateway albanoiGateway;

public UsersController(AlbanoiGateway albanoiGateway) {
this.albanoiGateway = albanoiGateway;
}

@GetMapping("{id}")
public ResponseEntity<User> findUser(@PathVariable UUID id){

GetUserByIdQuery getUserByIdQuery = new GetUserByIdQuery(id);
User user = albanoiGateway.handle(getUserByIdQuery, User.class);

return ResponseEntity.ok(user);
}
}