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:

OpenAPI Endpoints

And these Domain Events published to a Kafka Topic:

AsyncAPI Operations

As defined on this

ZenWave Model for Customer Address JPA Service (๐Ÿ‘‡ view source)
/**
* 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 jpa
databaseType postgresql
// you can choose: DefaultProjectLayout, CleanHexagonalProjectLayout, LayeredProjectLayout, SimpleDomainProjectLayout, HexagonalProjectLayout, CleanArchitectureProjectLayout
layout LayeredProjectLayout
// these should match the values of openapi-generator-maven-plugin
// used by the OpenAPIControllersPlugin and SpringWebTestClientPlugin
layout.openApiApiPackage "{{basePackage}}.web"
layout.openApiModelPackage "{{basePackage}}.web.dtos"
openApiModelNameSuffix DTO
}
/**
* Customer entity
*/
@aggregate
@auditing // adds auditing fields to the entity
entity 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)
}
}
@auditing
entity PaymentMethod {
type PaymentMethodType required
cardNumber String required
}
enum PaymentMethodType { VISA(1), MASTERCARD(2) }
relationship OneToMany {
@eager
Customer{paymentMethods required maxlength(3)} to PaymentMethod{customer required}
}
// you can create 'inputs' as dtos for your service methods, or use entities directly
input CustomerSearchCriteria {
name String
email String
city String
state String
}
@rest("/customers")
service CustomerService for (Customer) {
@post
createCustomer(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}) @paginated
searchCustomers(CustomerSearchCriteria) Customer[]
}
@copy(Customer)
@asyncapi({ channel: "CustomersChannel", topic: "customers" })
event CustomerEvent {
id Long
version Integer
// all fields from Customer are copied here, but not relationships
paymentMethods PaymentMethod[]
}
๐Ÿ”—Navigate to source

And generated using this

ZenWave Scripts for Customer Address JPA Service (๐Ÿ‘‡ view source)
๐Ÿ”—Navigate to source

with [ZenWave Model Editor] for IntelliJ IDEA.