Skip to main content

· One min read
Defrim Hasani

It does not matter if you are using a Rest API or any other way of data input i.e. kafka consumers. Albanoi cares only what's in your domain layer.

Below you can see two different scenarios where albanoi works as designed.

When you have a rest controller, which is used to execute http requests against our application that controller can prepare the domain commands and execute them using the albanoi gateway. The gateway itself will find the registered handler for you command and return the handler result.

The same can be done using a kafka consumer, once you deserialize the message you can prepare your domain command and execute it, similar to rest controllers. img alt

· 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);
}
}

· 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;
}

@PostMapping
public ResponseEntity<User> createUser(@RequestBody CreateUserRequest createUserRequest) {

// Commands are part of your domain
var createUserCommand = new CreateUserCommand();
createUserCommand.setUsername(createUserRequest.getUsername());

// You don't need to inject the handler itself, let the gateway handle it 😊
CommandResult<User> createUserResult = albanoiGateway.execute(createUserCommand, User.class);

return ResponseEntity.ok(createUserResult.getResult());
}
}