Untitled

mail@pastecode.io avatar
unknown
java
a year ago
1.1 kB
2
Indexable
Never
import org.axonframework.commandhandling.CommandHandler;
import org.axonframework.commandhandling.CommandMessage;
import org.axonframework.commandhandling.model.AggregateIdentifier;
import org.axonframework.commandhandling.model.AggregateLifecycle;
import org.axonframework.commandhandling.model.CommandAggregate;

@CommandAggregate
public class MyAggregate {

    @AggregateIdentifier
    private String aggregateId;

    public MyAggregate() {
    }

    @CommandHandler
    public MyAggregate(CreateMyAggregateCommand cmd) {
        AggregateLifecycle.apply(new MyAggregateCreatedEvent(cmd.getAggregateId(), cmd.getName()));
    }

    @CommandHandler
    public void updateName(@CommandBody String name) {
        AggregateLifecycle.apply(new MyAggregateNameUpdatedEvent(aggregateId, name));
    }

    @CommandHandler
    public void updateDescription(@CommandParam("description") String description) {
        AggregateLifecycle.apply(new MyAggregateDescriptionUpdatedEvent(aggregateId, description));
    }

    // Other methods and event handlers omitted for brevity
}