jaduff / LabLog

Software for recording physical users of computers in a lab environment.
MIT License
0 stars 1 forks source link

Implement User and Damage recording #42

Closed jaduff closed 6 years ago

jaduff commented 6 years ago
  1. Write Tests
  2. Read Tests
  3. Read Model
  4. Interface
jaduff commented 6 years ago

What's the best way to handle this? I can create a class of Student. But I'll need something that contains the time the user was assigned, as well as who assigned them. Its not so complicated for the Write Model, where the event already contains that information, all I need is an event with the username and the computer serial number in the event. But what about the Read Model? A computer will have a list of its previous users, but that will require the time they were assigned, as well as who assigned them. So I'll need a class of Student, and a class of StudentAssigned or something?

simonjduff commented 6 years ago

Something like that yeah. Consider mapping out what you want in JSON before seeing how it can fit in C#, might make it easier to visualize

jaduff commented 6 years ago

Ok, working on the event side of things at the moment. I have School.Rooms. In one of those rooms, there is a computer with a serial number. How do I find the computer without knowing which room its in, and without iterating through all the rooms? There are ways I can know the room first, which would make this trivial. But is there a way of searching for child of child objects?

jaduff commented 6 years ago

It seems silly to have to include the RoomId in the event body, when it is the computer that is being assigned to. Storing that just to find the computer doesn't feel right. I found Rooms.Contains(), but that would seem to need me to pass in a Computer object, when all I have is the SerialNumber.

simonjduff commented 6 years ago

Are you searching for the room at Write time for command validation or are you searching for the room to build the Read model after the event has been raised?

jaduff commented 6 years ago

For building the Write Model, with ApplyStudentAssignedEvent. I want to make sure that the same student is not assigned to two computers in the same room at the same time. It'd be even better to check that the student is not assigned two computers ANYWHERE at the same time, but I don't think this is something I can solve. Students won't be unassigned from computers (under normal conditions), but instead the next student will be assigned over the top. But what if the student has to move computers, without anyone being assigned to the machine they left? The system would either need to tolerate simultaneous assignment, or the teacher would need to assign blank to that machine, which is something I'm not keen on doing.

Your point about replaying events for the Read Model is a good one though, the same problem occurs.

jaduff commented 6 years ago

So I'll need to find some way of validating how many computers a student is assigned to, at a specific point in time (the time the teacher pressed submit). So its fine for a student to be assigned to two computers, but the assignment must not be at a single point of time.

jaduff commented 6 years ago

Another version number would do it I suppose.