Skip to content

Instantly share code, notes, and snippets.

@psamatt
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psamatt/e36bfc6d9fda091c79ef to your computer and use it in GitHub Desktop.
Save psamatt/e36bfc6d9fda091c79ef to your computer and use it in GitHub Desktop.
Process of a teacher email students
<?php
class Lecture extends EventSourcedAggregateRoot
{
public function __construct(LectureId $id, StartTime $startTime) {
}
public function remindStudents()
{
$this->guardNotLAstDay();
$this->apply(TeacherRequestedReminderForLecture($lectureId, $teacherId, $studentIds))
}
}
<?php
class TeacherRequestsReminderForLecture {
public function __construct(TeacherId $teacherId, LectureId $lectureId) {}
}
class LectureCommandHandler {
function handleTeacherRequestsReminderForLecture(TeacherRequestsReminderForLecture $cmd)
{
$lecture = $this->repo->find($cmd->lectureId);
$lecture->remindStudents();
}
}
<?php
class LectureProcessor
{
public function whenTeacherRequestedReminderForLecture(TeacherRequestedReminderForLecture $event)
{
foreach($event->studentIds as $studentId) {
$this->emailer->remindStudent($studentId, $lectureId);
$this->commandBus->dispatch(RemindStudentOfLecture($studentId, $lectureId));
}
}
}
class StudentCommandHandler
{
public function handleRemindStudentOfLecture(RemindStudentOfLecture $cmd)
{
student = $this->repo->find($cmd->studentId);
student->remind($lectureId);
}
}
class Student{
public function remind($lectureId) {
apply(StudentRemindedOfLecture($studentId, $lectureId));
}
}
class StudentReminderProjector {
public function whenStudentRemindedOfLecture() {
// update view model
}
}
// command
class TeacherRequestsReminderForLecture {
public function __construct(LectureId $lectureId, TeacherId $teacherId) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment