Create Enums
In this lesson we'll create the enumerations we'll need when we start implementing our entities.
We'll implement the enums first as they're the simplest to implement and will allow us to build our domain form the bottom up.
Create our Domain's Enums
Enums in Java provide a way to define a fixed set of constants.
In our ticket platform, enums help us maintain data integrity by restricting certain fields to specific, predefined values.
Let's explore each enum and its purpose:
Event Status
The EventStatusEnum represents the different states an event can be in throughout its lifecycle:
public enum EventStatusEnum {
DRAFT, // Initial state when creating an event
PUBLISHED, // Event is live and tickets can be purchased
CANCELLED, // Event will not take place
COMPLETED // Event has finished
}Ticket Status
The TicketStatusEnum tracks the state of purchased tickets:
public enum TicketStatusEnum {
PURCHASED, // Default state when ticket is bought
CANCELLED // Ticket has been cancelled
}Ticket Validation
We use two enums for ticket validation:
public enum TicketValidationMethod {
QR_SCAN, // Ticket validated via QR code scan
MANUAL // Ticket validated via manual entry
}
public enum TicketValidationStatusEnum {
VALID, // Ticket is valid for entry
INVALID, // Ticket is not valid
EXPIRED // Ticket has expired
}QR Code Status
The QrCodeStatusEnum manages the state of QR codes:
public enum QrCodeStatusEnum {
ACTIVE, // QR code can be used
EXPIRED // QR code has been invalidated
}Summary
- The
EventStatusEnumrepresents the states anEventcould be in - The
TicketStatusEnumrepresents the states aTicketcould be in - The
TicketValidationMethodEnumrepresents the different way a ticket can be validated - The
TicketValidationStatusEnumrepresents the the state aTicketValidationcould be in - The
QrCodeStatusEnumrepresents the different states aQrCodecould be in