Entities

Let's start by defining our entities:

  1. Copy the following snippet for Product and ProductCategory into the JDL-Studio editor:
/** Product sold by the Online store */
entity Product {
name String required
description String
price BigDecimal required min(0)
size Size required
image ImageBlob
}

enum Size {
S, M, L, XL, XXL
}

entity ProductCategory {
name String required
description String
}

The Product entity is the core of the domain model; it holds product information such as the namedescriptionpricesize, and image, which is a blob. The name, price, and size are required fields. The price also has a minimum value validation. The size field is an enum with defined values.

The ProductCategory entity is used to group products together. It has the name and description fields, where name is a required field.

  1. Add the following snippet for Customer into the JDL-Studio editor:
entity Customer {
firstName String required
lastName String required
gender Gender required
email String required pattern(/^[^@s]+@[^@s]+.[^@s]+$/)
phone String required
addressLine1 String required
addressLine2 String
city String required
country String required
}

enum Gender {
MALE, FEMALE, OTHER
}

The Customer entity holds details of the customers using the online shopping portal. Most of the fields are marked as required, and the email field has regex pattern validation. The gender field is an enum. This entity is related to the system user, which we will see in more detail soon.

  1. Add the following snippet for ProductOrder and OrderItem into the JDL-Studio editor:
entity ProductOrder {
placedDate Instant required
status OrderStatus required
code String required
}

enum OrderStatus {
COMPLETED, PENDING, CANCELLED
}

entity OrderItem {
quantity Integer required min(0)
totalPrice BigDecimal required min(0)
status OrderItemStatus required
}

enum OrderItemStatus {
AVAILABLE, OUT_OF_STOCK, BACK_ORDER
}

The ProductOrder and OrderItem entities are used to track product orders made by customers. The ProductOrder entity holds the placedDatestatus, and code of the order, which are all required fields, while OrderItem holds information about the quantity, totalPrice, and status of individual items. All fields are required and the quantity and totalPrice fields have a minimum value validation. The OrderStatus and OrderItemStatus fields are enum fields.

  1. Add the following snippet for Invoice and Shipment into the JDL-Studio editor:
entity Invoice {
date Instant required
details String
status InvoiceStatus required
paymentMethod PaymentMethod required
paymentDate Instant required
paymentAmount BigDecimal required
}

enum InvoiceStatus {
PAID, ISSUED, CANCELLED
}

enum PaymentMethod {
CREDIT_CARD, CASH_ON_DELIVERY, PAYPAL
}

entity Shipment {
trackingCode String
date Instant required
details String
}

The Invoice and Shipment entities are used to track the invoice and shipping for the product orders, respectively. Most of the fields in Invoice are required and the status and paymentMethod fields are enums.

The enumerations are used to contain the scope of certain fields, which gives more granular control over those fields.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset