Hello!
I am new with ES and Axon and I am building an app that have two aggregates, lets call then Forum and Topic. Forum have a list of strings, that are used to validations, and Topic have a command handle that need to validate a command field based on that list in Forum aggregate. See the code bellow for example:
public class CreateTopic {
@TargetAggregateIdentifier
private String topicUuid;
private String topicName;
private String forumUuid;
}
@Aggregate
public class Forum {
@AggregateIdentifier
private String uuid;
private List<String> topicNames;
}
@Aggregate
public class Topic {
@AggregateIdentifier
private String uuid;
private String name;
// other fields
@CommandHandler
public Topic(CreateTopic command) {
// need to validate if the father aggregate A contains a children with that name
}
}
The problem is that the Forum doesn’t existis until their first child Topic is created. I did not want to have to check in the database if this forum does not exist and send a create command if it does not exist, just get an empty one with the UUID if it’s the first time it is being used, perhaps a createNewIfAbsent method in AggregateLifecycle was useful here. External users doesn’t even need to know the existence of the Forum inside that application because they just want to create a Topic (they send me just the Forum UUID, and nothing else related to the Forum), but I need to validate if there are any Topics inside that Forum with this topic name, and tell the user “there is already a topic with this name and forum” if that rule is violated on the topic creation.
I don’t know the proper way to validate that rule. At the moment, I am just ignoring the “Forum” aggregate, and calling a projection of Topics (by the query gateway) inside the command handler just to check if there is a topic with that name and forum UUID in the database. I think it isn’t the best way. Any suggestion?