Skip to content

feat: Participant management #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 19, 2024
Merged

Conversation

elementbound
Copy link
Contributor

Closes #24

@@ -0,0 +1,7 @@
export interface Participant {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will move this to shared/src/api in #43

@Post('/:id/participants')
public async joinSession(
@Param('id') id: string
): Promise<Participant | undefined> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have return type as Promise<Participant>
If for some reason we can't provide a 'Participant', we should throw the appropriate HTTP error

): Promise<Participant> {
assert(await this.hasSession(session), 'Unknown session!');

assert(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got that the previous check (hasSession) is basically an assert, whether the consumer found a living session,
but this one is rather an error check IMHO.

The consumer (SessionController) can't verify whether the found living session is in good state or not, therefore it's the responsibility of the SessionService.
As a result, it's not a presumption, but a requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will call it verify to reflect the above.


// Save updated session
session.participants.push(participant);
await this.sessionDAO.save(session);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rather theoretical question, but what happens if the save of the participant is done, but for some reason session save has failed? We got a fractured/inconsistent state.
My point is here, that we don't express the part-whole connection between them, plus we don't have any transaction-like mechanism.

We should talk about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

public async join(
session: Session,
options?: JoinSessionOptions
): Promise<Participant> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK whether we can solve it, but this method violates CQS principle.
Maybe an ideal solution from the consumer:

const session = this.sessionService.find(sessionId);
const participant = this.sessionService.createParticipant(participantOptions);
session.join(participant);
this.sessionService.save(session);

@elementbound elementbound merged commit 626e216 into main Dec 19, 2024
5 checks passed
@elementbound elementbound deleted the feat/participant-management branch December 19, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Participant management
2 participants