Skip to content

Commit

Permalink
member, reservation, store connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWeinstein92 committed Mar 13, 2024
1 parent cfc1456 commit a83c90f
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 53 deletions.
12 changes: 3 additions & 9 deletions src/main/riddl/Events/Reservations/reservation.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ type ReservationId is Id (ImprovingApp.Events.ReservationContext.Reservation)
context ReservationContext is {
include "reservationTypeDefinitions"
include "reservationMessages"

// TODO: List the names of the public reservation events here
type PublicReservationEvent is one of {
???
}

outlet Events is type PublicReservationEvent
include "reservationSources"

entity Reservation is {
option event-sourced
Expand All @@ -22,7 +16,7 @@ context ReservationContext is {
record ImprovingApp.Events.ReservationContext.Reservation.DraftState
"Copy fields from the command into Draft fields"
"adjust meta fields to reflect the change set"
send event ReservationEstablished to outlet ReservationContext.Events
send event ReservationEstablished to outlet ReservationEventsSource.Events
}
on other {
error "Only EstablishReservation command is allowed in the default state"
Expand All @@ -41,7 +35,7 @@ context ReservationContext is {
}
on command ImprovingApp.Events.ReservationContext.EditReservationInfo {
set field ImprovingApp.Events.ReservationContext.Reservation.Draft.reservationInfo to "EditReservationInfo.info"
send event ReservationInfoUpdated to outlet ReservationContext.Events
send event ReservationInfoUpdated to outlet ReservationEventsSource.Events
}
on command ImprovingApp.Events.ReservationContext.UpdateReservationStatus {
"morph entity Reservation to state provided in UpdateReservationStatus"
Expand Down
41 changes: 41 additions & 0 deletions src/main/riddl/Events/Reservations/reservationSources.riddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
connector ReservationCommandsChannel is {
from outlet ReservationCommandsSource.Commands to
inlet ReservationCommandsSink.Commands
}

connector ReservationEventsChannel is {
from outlet ReservationEventsSource.Events to
inlet ReservationEventsSink.Events
}

source ReservationCommandsSource is {
outlet Commands is type ReservationCommand
}

sink ReservationCommandsSink is {
inlet Commands is type ReservationCommand
}

source ReservationEventsSource is {
outlet Events is type ReservationEvent
}

sink ReservationEventsSink is {
inlet Events is type ReservationEvent
}

type ReservationCommand is one of {
EstablishReservation,
EditReservationInfo,
UpdateReservationStatus,
DeleteReservation,
GetReservationInfo
}

type ReservationEvent is one of {
ReservationEstablished,
ReservationInfoUpdated,
ReservationStatusUpdated,
ReservationDeleted,
ReservationInfoResult
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ epic CreateReservation {
step from user GatewayAPI "Create Reservation" to entity ImprovingApp.Events.ReservationContext.Reservation
briefly "create reservation"
step send event ImprovingApp.Events.ReservationContext.ReservationEstablished
from entity ImprovingApp.Events.ReservationContext.Reservation to source ImprovingApp.Events.ReservationContext.PublicReservationEvent
from entity ImprovingApp.Events.ReservationContext.Reservation to source ImprovingApp.Events.ReservationContext.ReservationEventsSource
briefly "reservation created"
step send event ImprovingApp.Events.ReservationContext.ReservationEstablished
from source ImprovingApp.Events.ReservationContext.PublicReservationEvent to application App
from source ImprovingApp.Events.ReservationContext.ReservationEventsSource to application App
}
} briefly "A story about creating a reservation in Improving.app"
described as "This is the story of how a reservation comes into existence"
Expand Down
4 changes: 2 additions & 2 deletions src/main/riddl/Gateway/gatewayStories.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ epic RegisterMember {
briefly "send creation message"
step from context GatewayAPI "Register Member" to entity ImprovingApp.MemberContext.Member
briefly "add new Member"
step send event ImprovingApp.MemberContext.MemberRegistered from entity ImprovingApp.MemberContext.Member to source ImprovingApp.MemberContext.MemberEvents
step send event ImprovingApp.MemberContext.MemberRegistered from entity ImprovingApp.MemberContext.Member to source ImprovingApp.MemberContext.MemberEventsSource
briefly "Member added in Draft state"
step send event ImprovingApp.MemberContext.MemberRegistered from source ImprovingApp.MemberContext.MemberEvents to application App
step send event ImprovingApp.MemberContext.MemberRegistered from source ImprovingApp.MemberContext.MemberEventsSource to application App
//example Foo is {...}
}
} briefly "A story about registering a member in Improving.app"
Expand Down
43 changes: 43 additions & 0 deletions src/main/riddl/Members/memberSources.riddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
connector MemberCommandsChannel is {
from outlet MemberCommandsSource.Commands to
inlet MemberCommandsSink.Commands
}

connector MemberEventsChannel is {
from outlet MemberEventsSource.Events to
inlet MemberEventsSink.Events
}

source MemberCommandsSource is {
outlet Commands is type MemberCommand
}

sink MemberCommandsSink is {
inlet Commands is type MemberCommand
}

source MemberEventsSource is {
outlet Events is type MemberEvent
}

sink MemberEventsSink is {
inlet Events is type MemberEvent
}

type MemberCommand is one of {
ImprovingApp.MemberContext.RegisterMember,
ImprovingApp.MemberContext.ActivateMember,
ImprovingApp.MemberContext.SuspendMember,
ImprovingApp.MemberContext.TerminateMember,
ImprovingApp.MemberContext.EditMemberInfo,
ImprovingApp.MemberContext.GetMemberData
}

type MemberEvent is one of {
ImprovingApp.MemberContext.MemberRegistered,
ImprovingApp.MemberContext.MemberActivated,
ImprovingApp.MemberContext.MemberSuspended,
ImprovingApp.MemberContext.MemberTerminated,
ImprovingApp.MemberContext.MemberInfoEdited,
ImprovingApp.MemberContext.MemberData
}
28 changes: 9 additions & 19 deletions src/main/riddl/Members/members.riddl
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
context MemberContext is {
include "memberSources"

type MemberId is Id(MemberContext.Member)
briefly "Unique identifier for Tenant Entity"

type PublicMemberEvent is one of {
ImprovingApp.MemberContext.MemberRegistered,
ImprovingApp.MemberContext.MemberActivated,
ImprovingApp.MemberContext.MemberSuspended,
ImprovingApp.MemberContext.MemberTerminated,
ImprovingApp.MemberContext.MemberInfoEdited,
ImprovingApp.MemberContext.MemberData
}
source MemberEvents is {
outlet Events is type PublicMemberEvent
} explained as "This is a source for Organization Events"

type MemberMap is mapping from MemberContext.MemberId to MemberContext.Info

//Member Details
Expand Down Expand Up @@ -249,7 +239,7 @@ context MemberContext is {
on command ImprovingApp.MemberContext.ActivateMember {
if "all required fields in requiredInfo are not None or Empty"
then {
send event MemberRegistered to outlet MemberEvents.Events
send event MemberRegistered to outlet MemberEventsSource.Events
morph entity Member to state RegisteredMemberState with record RegisteredMember

} else {
Expand All @@ -261,13 +251,13 @@ context MemberContext is {
on command EditMemberInfo {
set field Member.DraftMemberState.info to "MemberContext.EditableInfo"
set field Member.DraftMemberState.meta to "MemberContext.MetaInfo"
send event MemberInfoEdited to outlet ImprovingApp.MemberContext.MemberEvents.Events
send event MemberInfoEdited to outlet ImprovingApp.MemberContext.MemberEventsSource.Events
}
// For GetMemberData, eventually probably only admins and self should be able to make this call. Also
// potentially allow other roles to get some limited information (this will require adding another
// aggregate).
on query GetMemberData {
send record MemberInfo to outlet ImprovingApp.MemberContext.MemberEvents.Events
send record MemberInfo to outlet ImprovingApp.MemberContext.MemberEventsSource.Events
}
}
} described as {
Expand Down Expand Up @@ -310,11 +300,11 @@ context MemberContext is {
lastUpdatedBy = @EditMemberInfo.editingMember,
currentState = @MemberStates.Draft
)"
send event MemberInfoEdited to outlet ImprovingApp.MemberContext.MemberEvents.Events
send event MemberInfoEdited to outlet ImprovingApp.MemberContext.MemberEventsSource.Events
}
on command ImprovingApp.MemberContext.SuspendMember {
if "all required fields in requiredInfo are not None or Empty" then {
send event MemberSuspended to outlet MemberEvents.Events
send event MemberSuspended to outlet MemberEventsSource.Events
become entity Member to handler SuspendedMemberHandler
}
}
Expand All @@ -331,12 +321,12 @@ context MemberContext is {
error "Member has already been registered."
}
on command ImprovingApp.MemberContext.ActivateMember {
send event ImprovingApp.GatewayAPI.MemberGateway.MemberActivated to outlet ImprovingApp.MemberContext.MemberEvents.Events
send event ImprovingApp.GatewayAPI.MemberGateway.MemberActivated to outlet ImprovingApp.MemberContext.MemberEventsSource.Events
become entity ImprovingApp.MemberContext.Member to handler ActiveMemberHandler
}
on command ImprovingApp.MemberContext.SuspendMember {
set field RegisteredMemberState.meta to "MemberContext.MetaInfo"
send event ImprovingApp.MemberContext.MemberSuspended to outlet ImprovingApp.MemberContext.MemberEvents.Events
send event ImprovingApp.MemberContext.MemberSuspended to outlet ImprovingApp.MemberContext.MemberEventsSource.Events
} briefly "A suspension reason can be updated by re-issuing the command"
on command ImprovingApp.MemberContext.TerminateMember {
set field RegisteredMemberState.meta to "MemberContext.MetaInfo"
Expand Down
28 changes: 7 additions & 21 deletions src/main/riddl/Store/Store.riddl
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
context StoreContext is {
type PublicStoreEvent is one of {
StoreCreated,
StoreInfoEdited,
StoreIsReady,
StoreDeleted,
StoreOpened,
StoreClosed,
ProductsAddedToStore,
ProductsRemovedFromStore
}

source StoreEvents is {
outlet Events is type PublicStoreEvent
} explained as "This is a source for Store Events"
include "storeSources"

type StoreStates is any of {Draft, Ready, Open, Closed, Deleted}
type StoreId is Id(StoreContext.Store)
Expand Down Expand Up @@ -76,8 +63,7 @@ context StoreContext is {

handler DefaultStoreHandler is {
on command CreateStore {
send event StoreCreated
to outlet StoreEvents.Events
send event StoreCreated to outlet StoreEventsSource.Events
morph entity StoreContext.Store to state Store.DraftStore with record Store.DraftStoreData
}
on other {
Expand Down Expand Up @@ -154,13 +140,13 @@ context StoreContext is {
}
on command OpenStore {
set field Store.CreatedStore.meta to "StoreContext.MetaInfo"
send event StoreOpened to outlet StoreEvents.Events
send event StoreOpened to outlet StoreEventsSource.Events
become entity StoreContext.Store to handler StoreContext.Store.CreatedStore.OpenStoreHandler
}
on command CloseStore {
"ensure all orders associated with store are Delivered or Cancelled before closing store"
set field CreatedStore.meta to "StoreContext.MetaInfo"
send event StoreClosed to outlet StoreEvents.Events
send event StoreClosed to outlet StoreEventsSource.Events
become entity StoreContext.Store to handler StoreContext.Store.CreatedStore.ClosedStoreHandler
}
on command AddProductsToStore {
Expand Down Expand Up @@ -203,7 +189,7 @@ context StoreContext is {
on command CloseStore {
"ensure all orders associated with store are Delivered or Cancelled before closing store"
set field CreatedStore.meta to "StoreContext.MetaInfo"
send event StoreClosed to outlet StoreEvents.Events
send event StoreClosed to outlet StoreEventsSource.Events
become entity StoreContext.Store to handler StoreContext.Store.CreatedStore.ClosedStoreHandler
}
on command AddProductsToStore {
Expand Down Expand Up @@ -239,12 +225,12 @@ context StoreContext is {
}
on command DeleteStore {
set field CreatedStore.meta to "StoreContext.MetaInfo"
send event StoreDeleted to outlet StoreEvents.Events
send event StoreDeleted to outlet StoreEventsSource.Events
morph entity StoreContext.Store to state DeletedStore with record DeletedStoreData
}
on command OpenStore {
set field CreatedStore.meta to "StoreContext.MetaInfo"
send event StoreOpened to outlet StoreEvents.Events
send event StoreOpened to outlet StoreEventsSource.Events
become entity StoreContext.Store to handler Store.CreatedStore.OpenStoreHandler
}
on command CloseStore {
Expand Down
50 changes: 50 additions & 0 deletions src/main/riddl/Store/storeSources.riddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
connector StoreCommandsChannel is {
from outlet StoreCommandsSource.Commands to
inlet StoreCommandsSink.Commands
}

connector StoreEventsChannel is {
from outlet StoreEventsSource.Events to
inlet StoreEventsSink.Events
}

source StoreCommandsSource is {
outlet Commands is type StoreCommand
}

sink StoreCommandsSink is {
inlet Commands is type StoreCommand
}

source StoreEventsSource is {
outlet Events is type StoreEvent
}

sink StoreEventsSink is {
inlet Events is type StoreEvent
}

type StoreCommand is one of {
CreateStore,
EditStoreInfo,
MakeStoreReady,
DeleteStore,
OpenStore,
CloseStore,
TerminateStore,
AddProductsToStore,
RemoveProductsFromStore,
GetStoreInfo,
GetProductsInStore
}

type StoreEvent is one of {
StoreCreated,
StoreInfoEdited,
StoreIsReady,
StoreDeleted,
StoreOpened,
StoreClosed,
ProductsAddedToStore,
ProductsRemovedFromStore
}

0 comments on commit a83c90f

Please sign in to comment.