[Event Sourcing] Trying out Sekiban DCB: Implementation
Introduction
This article is a continuation of "[Event Sourcing] Trying out Sekiban DCB: Introduction". In the previous post, we covered setting up the DCB Native environment and its processing flow.
Initially, features like creating a Student, fetching individual and list data, and enrolling/dropping classes are already implemented. The student's state is built from recorded events. The information a student holds includes Student ID, Name, Max Class Count, and a list of currently enrolled classes.
In this post, we will add a feature to update a student's name and their maximum class limit. The Student ID and enrolled classes will remain unchanged. Decreasing the max limit below the current number of enrolled classes will be prohibited.
When updating, we don't directly overwrite the current data. Instead, we record a StudentProfileUpdated event. A Projector then processes this event to build the updated student state.
Update Feature Specifications
| Item | Specification |
|---|---|
StudentId |
Specifies the student to update. It is not changed. |
Name |
Required, 1 to 100 characters |
MaxClassCount |
1 to 10. Changing it to a value lower than the current enrollment count is not allowed. |
| Enrollment list | Keeps the contents before the update. |
| Non-existing student | The update is rejected. |
The API receives JSON containing the student ID.
POST /api/students/update
Content-Type: application/json
{
"studentId": "9912a519-a6f6-41fe-92bf-07b99045efff",
"name": "John",
"maxClassCount": 3
}
We will add the implementation in the order of Event, Decider, Command, Projector, and API.
The sample code is available on GitHub.
1. Add an Event That Represents the Update
We define the fact that the student information was updated as StudentProfileUpdated event.
using Dcb.ImmutableModels.Tags;
using Sekiban.Dcb.Events;
namespace Dcb.ImmutableModels.Events.Student;
public record StudentProfileUpdated(
Guid StudentId,
string Name,
int MaxClassCount<Introduction
This article is a continuation of "[Event Sourcing] Trying out Sekiban DCB: Introduction". In the previous post, we covered setting up the DCB Native environment and its processing flow.
Initially, features like creating a Student, fetching individual and list data, and enrolling/dropping classes are already implemented. The student's state is built from recorded events. The information a student holds includes Student ID, Name, Max Class Count, and a list of currently enrolled classes.
In this post, we will add a feature to update a student's name and their maximum class limit. The Student ID and enrolled classes will remain unchanged. Decreasing the max limit below the current number of enrolled classes will be prohibited.
When updating, we don't directly overwrite the current data. Instead, we record a StudentProfileUpdated event. A Projector then processes this event to build the updated student state.
Update Feature Specifications
| Item | Specification |
|---|---|
StudentId |
Specifies the student to update. It is not changed. |
Name |
Required, 1 to 100 characters |
MaxClassCount |
1 to 10. Changing it to a value lower than the current enrollment count is not allowed. |
| Enrollment list | Keeps the contents before the update. |
| Non-existing student | The update is rejected. |
The API receives JSON containing the student ID.
POST /api/students/update
Content-Type: application/json
{
"studentId": "9912a519-a6f6-41fe-92bf-07b99045efff",
"name": "John",
"maxClassCount": 3
}
We will add the implementation in the order of Event, Decider, Command, Projector, and API.
The sample code is available on GitHub.
1. Add an Event That Represents the Update
We define the fact that the student information was updated as StudentProfileUpdated event.
using Dcb.ImmutableModels.Tags;
using Sekiban.Dcb.Events;
namespace Dcb.ImmutableModels.Events.Student;
public record StudentProfileUpdated(
Guid StudentId,
string Name,
int MaxClassCount<