-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds support for rich 'aggregate' modeling
- Loading branch information
Showing
20 changed files
with
570 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ns/BackendApplicationDefaultGenerator/src/main/java/core/domain/common/Aggregate.java.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package {{entitiesPackage}}; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import {{domainEventsPackage}}.*; | ||
import {{inboundDtosPackage}}.*; | ||
|
||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
|
||
public class {{aggregate.name}} { | ||
private static final Mapper mapper = Mappers.getMapper(Mapper.class); | ||
|
||
private final {{aggregate.aggregateRoot}} rootEntity; | ||
|
||
private final List<Object> events = new ArrayList<>(); | ||
|
||
public {{aggregate.name}}() { | ||
this(new {{aggregate.aggregateRoot}}()); | ||
} | ||
public {{aggregate.name}}({{aggregate.aggregateRoot}} rootEntity) { | ||
this.rootEntity = rootEntity; | ||
} | ||
|
||
public String getId() { | ||
return rootEntity.getId(); | ||
} | ||
|
||
public {{aggregate.aggregateRoot}} getRootEntity() { | ||
return rootEntity; | ||
} | ||
|
||
public List<?> getEvents() { | ||
return Collections.unmodifiableList(events); | ||
} | ||
|
||
{{#each aggregate.commands as |method|}} | ||
{{~> (partial '../../implementation/partials/serviceMethodJavadoc')}} | ||
public void {{method.name}}({{method.parameter}} input) { | ||
// TODO: implement this command | ||
mapper.update(rootEntity, input); | ||
{{~#each (methodEvents method) as |event|}} | ||
events.add(mapper.as{{event.name}}(rootEntity)); | ||
{{~/each}} | ||
} | ||
{{/each}} | ||
|
||
@org.mapstruct.Mapper | ||
interface Mapper { | ||
{{~#each (findAggregateInputs aggregate) as |input|}} | ||
{{aggregate.aggregateRoot}} update(@MappingTarget {{aggregate.aggregateRoot}} entity, {{input}} input); | ||
{{~/each}} | ||
|
||
{{~#each (aggregateEvents aggregate) as |event|}} | ||
{{event.className}} as{{event.name}}({{aggregate.aggregateRoot}} entity); | ||
{{~/each}} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../BackendApplicationDefaultGenerator/src/main/java/core/domain/common/DomainEvent.java.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package {{domainEventsPackage}}; | ||
|
||
import java.io.Serializable; | ||
import java.math.*; | ||
import java.time.*; | ||
import java.util.*; | ||
import jakarta.validation.constraints.*; | ||
|
||
import {{entitiesPackage}}.*; | ||
|
||
/** | ||
* {{event.comment}} | ||
*/ | ||
{{~#if useLombok}} | ||
@lombok.Getter @lombok.Setter | ||
{{~/if}} | ||
public {{abstractClass event}} class {{event.className}} {{addExtends event}} implements Serializable { | ||
|
||
@java.io.Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
{{#each event.fields as |field|}} | ||
{{#each field.validations as |validation|~}} | ||
// @{{validation.name}}("{{validation.value}}") | ||
{{~/each}} | ||
private {{{fieldType field}}} {{field.name}}; | ||
{{/each}} | ||
|
||
|
||
{{#each event.fields as |field|}} | ||
{{~#if field.isArray}} | ||
public {{event.className}} add{{capitalize field.name}}({{javaType field}} {{field.name}}) { | ||
this.{{field.name}}.add({{field.name}}); | ||
return this; | ||
} | ||
{{~/if}} | ||
{{/each}} | ||
|
||
{{~#unless useLombok}} | ||
{{#each event.fields as |field|}} | ||
public {{{fieldType field}}} get{{capitalize field.name}}() { | ||
return {{field.name}}; | ||
} | ||
|
||
public {{event.className}} set{{capitalize field.name}}({{{fieldType field}}} {{field.name}}) { | ||
this.{{field.name}} = {{field.name}}; | ||
return this; | ||
} | ||
{{/each}} | ||
{{~/unless}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.