Skip to content

Commit

Permalink
product, event fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWeinstein92 committed Mar 8, 2024
1 parent 2b4234b commit e8f3dab
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/main/riddl/AllIdsProjections/allIdsProjections.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ context AllIdsProjections is {

projector AllStoreIdsView is {
record AllStoreIdsFields {
store: ImprovingApp.StoreContext.StoreId
store: StoreContext.StoreId
}
handler AllStoreIdsViewHandler is {
on event StoreCreated {
Expand Down
16 changes: 8 additions & 8 deletions src/main/riddl/Applications/application.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ application UserInterface is {
command EstablishOrganization is {
info: MemberContext.EditableInfo briefly "Details about an organization required for it to exist. See OrganizationContext.Organization.Info for details.",
tenant: TenantId,
parent: ImprovingApp.OrganizationContext.Parent?,
parent: OrganizationContext.Parent?,
members: MemberList,
owners: OwnerList,
contacts: ContactList,
Expand All @@ -12,7 +12,7 @@ application UserInterface is {
result OrganizationEstablished is {
organizationId: OrganizationId briefly "Unique identifier returned by EstablishOrganization command",
info: OrganizationContext.Info,
parent: ImprovingApp.OrganizationContext.Parent?,
parent: OrganizationContext.Parent?,
members: MemberList,
owners: OwnerList,
contacts: ContactList,
Expand All @@ -23,16 +23,16 @@ application UserInterface is {
group Organization is {
input EstablishOrganization acquires command UserInterface.EstablishOrganization

output DisplayOrganization presents result ImprovingApp.UserInterface.OrganizationEstablished
output DisplayOrganization presents result UserInterface.OrganizationEstablished
}

handler OrgHandler is {
on command ImprovingApp.OrganizationContext.EstablishOrganization from user OrgOwner {
tell command ImprovingApp.OrganizationContext.OrganizationEstablished to context ImprovingApp.OrganizationContext
on command OrganizationContext.EstablishOrganization from user OrgOwner {
tell command OrganizationContext.OrganizationEstablished to context OrganizationContext
}
on event ImprovingApp.OrganizationContext.OrganizationEstablished from context ImprovingApp.OrganizationContext {
//tell result ImprovingApp.OrganizationContext.OrganizationEstablished to
// projector ImprovingApp.Relationships.OrganizationViews
on event OrganizationContext.OrganizationEstablished from context OrganizationContext {
//tell resultOrganizationContext.OrganizationEstablished to
// projector Relationships.OrganizationViews
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/riddl/Commerce/commerce.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context Commerce is {
condition: String,
action: String
}
type PaymentId is Id( Payment )
type PaymentId is Id( Commerce.Payment )
type DeliveryId is Id( Delivery )
type DeliveryInfo is {
orderId: OrderId,
Expand Down
16 changes: 8 additions & 8 deletions src/main/riddl/Events/eventSources.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ source LiveUpdates is {

//ReservationAddedToEvent,
type PublicEventEvent is one of {
ImprovingApp.Events.EventContext.EventInfoEdited,
ImprovingApp.Events.EventContext.EventCreated,
ImprovingApp.Events.EventContext.EventScheduled,
ImprovingApp.Events.EventContext.EventCancelled,
ImprovingApp.Events.EventContext.EventRescheduled,
ImprovingApp.Events.EventContext.EventDelayed,
ImprovingApp.Events.EventContext.EventStarted,
ImprovingApp.Events.EventContext.EventEnded
Events.EventContext.EventInfoEdited,
Events.EventContext.EventCreated,
Events.EventContext.EventScheduled,
Events.EventContext.EventCancelled,
Events.EventContext.EventRescheduled,
Events.EventContext.EventDelayed,
Events.EventContext.EventStarted,
Events.EventContext.EventEnded
}
source EventEvents is {
outlet Events is type PublicEventEvent
Expand Down
62 changes: 31 additions & 31 deletions src/main/riddl/Product/product.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ context ProductContext is {
lastModifiedBy: MemberId,
lastModifiedOn: Date
}
command CreateProduct is {sku: SKU, info: ProductInfo, onBehalfOf: MemberId}
event ProductCreated is {sku: SKU, info: ProductInfo, meta: ProductMetaInfo}
command UpdateProductInfo is {sku: SKU, info: ProductInfoUpdate, onBehalfOf: MemberId}
event ProductInfoUpdated is {sku: SKU, info: ProductInfo, meta: ProductMetaInfo}
command CreateProduct is {sku: SKU, info: ProductContext.ProductInfo, onBehalfOf: MemberId}
event ProductCreated is {sku: SKU, info: ProductContext.ProductInfo, meta: ProductMetaInfo}
command UpdateProductInfo is {sku: SKU, info: ProductContext.ProductInfoUpdate, onBehalfOf: MemberId}
event ProductInfoUpdated is {sku: SKU, info: ProductContext.ProductInfo, meta: ProductMetaInfo}
command DeleteProduct is {sku: SKU, onBehalfOf: MemberId}
event ProductDeleted is {sku: SKU}
command ActivateProduct is {sku: SKU, onBehalfOf: MemberId}
event ProductActivated is {sku: SKU}
command InactivateProduct is {sku: SKU, onBehalfOf: MemberId}
event ProductInactivated is {sku: SKU}
query GetProductInfo is {sku: SKU}
result ProductInfoResult is {info: ProductInfo, meta: ProductMetaInfo}
result ProductInfoResult is {info: ProductContext.ProductInfo, meta: ProductContext.ProductMetaInfo}
query GetTicketsForEvent is {event: EventId} //TODO: Move this query/result to a projector?
result TicketsForEvent is {event: EventId, tickets: SKU*}

entity Product is {
option event-sourced
handler ProductHandler is {
on command CreateProduct {
morph entity Product to state DraftProductState with record DraftProduct
on command ProductContext.CreateProduct {
morph entity ProductContext.Product to state DraftProductState with record DraftProduct
}
on other {
error "Only the CreateProduct command is allowed in the default state."
Expand All @@ -81,12 +81,12 @@ context ProductContext is {

record DraftProduct is {
sku: SKU,
info: ProductInfo,
info: ProductContext.ProductInfo,
meta: ProductMetaInfo
}
state DraftProductState of Product.DraftProduct is {
handler CreatedProductHandler is {
on command CreateProduct {
on command ProductContext.CreateProduct {
error "Product already created."
}
on command UpdateProductInfo{
Expand All @@ -98,7 +98,7 @@ context ProductContext is {
set field DraftProductState.meta to "ProductContext.ProductMetaInfo"
send event ProductDeleted
to outlet ProductEvents.Events
morph entity Product to state DeletedProductState with record DeletedProduct
morph entity ProductContext.Product to state DeletedProductState with record DeletedProduct
}
on command ActivateProduct{
if "not all required fields are filled in" then {
Expand All @@ -121,56 +121,56 @@ context ProductContext is {

record DefinedProduct is {
sku: SKU,
info: ProductInfo,
meta: ProductMetaInfo
info: ProductContext.ProductInfo,
meta: ProductContext.ProductMetaInfo
}
state DefinedProductState of Product.DefinedProduct is {
handler ActiveProductHandler is {
on command CreateProduct {
on command ProductContext.CreateProduct {
error "Product already created."
}
on command UpdateProductInfo{
on command ProductContext.UpdateProductInfo{
"Copy fields that are provided from UpdateProductInfo.info into DefinedProductState.info fields"
"adjust meta fields to reflect the change set"
"yield ProductInfoUpdated event with new info"
}
on command DeleteProduct{
on command ProductContext.DeleteProduct{
set field DefinedProductState.meta to "ProductContext.ProductMetaInfo"
send event ProductDeleted to outlet ProductEvents.Events
morph entity Product to state DeletedProductState with record DeletedProduct
morph entity ProductContext.Product to state DeletedProductState with record DeletedProduct
}
on command ActivateProduct{
on command ProductContext.ActivateProduct{
error "Product is already active"
}
on command InactivateProduct {
on command ProductContext.InactivateProduct {
set field DefinedProductState.meta to "ProductContext.ProductMetaInfo"
send event ProductInactivated to outlet ProductEvents.Events
become entity Product to handler InactiveProductHandler
become entity ProductContext.Product to handler ProductContext.Product.DefinedProductState.InactiveProductHandler
}
on query GetProductInfo{
"yield ProductInfoResult message"
}
}
handler InactiveProductHandler is {
on command CreateProduct {
on command ProductContext.CreateProduct {
error "Product already created."
}
on command UpdateProductInfo{
on command ProductContext.UpdateProductInfo{
"Copy fields that are provided from UpdateProductInfo.info into DefinedProductState.info fields"
"adjust meta fields to reflect the change set"
"yield ProductInfoUpdated event with new info"
}
on command DeleteProduct{
on command ProductContext.DeleteProduct{
set field DefinedProductState.meta to "ProductContext.ProductMetaInfo"
send event ProductDeleted to outlet ProductEvents.Events
morph entity Product to state DeletedProductState with record DeletedProduct
morph entity ProductContext.Product to state ProductContext.Product.DefinedProductState.DeletedProductState with record DeletedProduct
}
on command ActivateProduct{
on command ProductContext.ActivateProduct{
set field DefinedProductState.meta to "ProductContext.ProductMetaInfo"
send event ProductActivated to outlet ProductEvents.Events
become entity Product to handler ActiveProductHandler
become entity ProductContext.Product.DefinedProductState.Product to handler ActiveProductHandler
}
on command InactivateProduct{
on command ProductContext.InactivateProduct{
error "Product is already Inactive"
}
on query GetProductInfo{
Expand All @@ -185,19 +185,19 @@ context ProductContext is {
}
state DeletedProductState of Product.DeletedProduct is {
handler DeletedProductHandler is {
on command CreateProduct {
on command ProductContext.CreateProduct {
error "Product already created."
}
on command UpdateProductInfo{
on command ProductContext.UpdateProductInfo{
error "Cannot update a Deleted product"
}
on command DeleteProduct{
on command ProductContext.DeleteProduct{
error "Product already deleted"
}
on command ActivateProduct{
on command ProductContext.ActivateProduct{
error "Cannot activate a deleted product. Consider creating a new product instead."
}
on command InactivateProduct{
on command ProductContext.InactivateProduct{
error "Cannot inactivate a Deleted product."
}
on query GetProductInfo{
Expand Down

0 comments on commit e8f3dab

Please sign in to comment.