Customer Address JPA Service
https://github.com/ZenWave360/zenwave-playground/tree/main/examples/kustomer-address-jpa
SpringBoot + Java microservice for a "Customer Address Service" using JPA for persistence for this Domain Model:
With these REST Endpoints:
And these Domain Events published to a Kafka Topic:
As defined on this
ZenWave Model for Customer Address JPA Service
/*** Sample ZenWave Model Definition.* Use zenwave-scripts.zdl to generate your code from this model definition.*/config {title "Project Name"basePackage "io.zenwave360.examples.kotlin"persistence jpadatabaseType postgresql// you can choose: DefaultProjectLayout, CleanHexagonalProjectLayout, LayeredProjectLayout, SimpleDomainProjectLayout, HexagonalProjectLayout, CleanArchitectureProjectLayoutlayout LayeredProjectLayout// these should match the values of openapi-generator-maven-plugin// used by the OpenAPIControllersPlugin and SpringWebTestClientPluginlayout.openApiApiPackage "{{basePackage}}.web"layout.openApiModelPackage "{{basePackage}}.web.dtos"openApiModelNameSuffix DTO}/*** Customer entity*/@aggregate@auditing // adds auditing fields to the entityentity Customer {name String required maxlength(254) /** Customer name */email String required maxlength(254) pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)/** Customer Addresses can be stored in a JSON column in the database. */@json addresses Address[] minlength(1) maxlength(5) {street String required maxlength(254)city String required maxlength(254)}}@auditingentity PaymentMethod {type PaymentMethodType requiredcardNumber String required}enum PaymentMethodType { VISA(1), MASTERCARD(2) }relationship OneToMany {@eagerCustomer{paymentMethods required maxlength(3)} to PaymentMethod{customer required}}// you can create 'inputs' as dtos for your service methods, or use entities directlyinput CustomerSearchCriteria {name Stringemail Stringcity Stringstate String}@rest("/customers")service CustomerService for (Customer) {@postcreateCustomer(Customer) Customer withEvents CustomerEvent@get("/{customerId}")getCustomer(id) Customer?@put("/{customerId}")updateCustomer(id, Customer) Customer? withEvents CustomerEvent@delete("/{customerId}")deleteCustomer(id) withEvents CustomerEvent@post({path: "/search", status: 200}) @paginatedsearchCustomers(CustomerSearchCriteria) Customer[]}@copy(Customer)@asyncapi({ channel: "CustomersChannel", topic: "customers" })event CustomerEvent {id Longversion Integer// all fields from Customer are copied here, but not relationshipspaymentMethods PaymentMethod[]}
And generated using this
ZenWave Scripts for Customer Address JPA Service
with [ZenWave Model Editor] for IntelliJ IDEA.