Skip to content

Commit

Permalink
Add host XUID to session object
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianCassar committed Jul 18, 2024
1 parent b7f7734 commit cd48eef
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class CreateSessionCommandHandler
async execute(command: CreateSessionCommand) {
const session = Session.create({
id: command.sessionId,
xuid: command.xuid,
titleId: command.titleId,
title: command.title,
mediaId: command.mediaId,
Expand Down
2 changes: 2 additions & 0 deletions src/application/commands/CreateSessionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import MacAddress from 'src/domain/value-objects/MacAddress';
import SessionFlags from 'src/domain/value-objects/SessionFlags';
import SessionId from 'src/domain/value-objects/SessionId';
import TitleId from 'src/domain/value-objects/TitleId';
import Xuid from 'src/domain/value-objects/Xuid';

export class CreateSessionCommand {
constructor(
public readonly titleId: TitleId,
public readonly xuid: Xuid,
public readonly title: string,
public readonly mediaId: string,
public readonly version: string,
Expand Down
11 changes: 11 additions & 0 deletions src/domain/aggregates/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Xuid from '../value-objects/Xuid';
interface SessionProps {
id: SessionId;
titleId: TitleId;
xuid: Xuid;
title: string;
mediaId: string;
version: string;
Expand All @@ -27,6 +28,7 @@ interface SessionProps {
interface CreateProps {
id: SessionId;
titleId: TitleId;
xuid: Xuid;
title: string;
mediaId: string;
version: string;
Expand Down Expand Up @@ -115,6 +117,11 @@ export default class Session {
}

public static createMigration(props: CreateMigrationProps) {
if (props.session.players.size > 0) {
// Remove old host from migrated session
props.session.players.delete(props.session.xuid.value);
}

const newSession = new Session({
...props.session.props,
id: new SessionId(this.GenerateSessionId()),
Expand Down Expand Up @@ -240,6 +247,10 @@ export default class Session {
return this.props.titleId;
}

get xuid() {
return this.props.xuid;
}

get title() {
return this.props.title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import IpAddress from 'src/domain/value-objects/IpAddress';
import SessionFlags from 'src/domain/value-objects/SessionFlags';
import MacAddress from 'src/domain/value-objects/MacAddress';
import SessionId from 'src/domain/value-objects/SessionId';
import Xuid from 'src/domain/value-objects/Xuid';

@Injectable()
export default class SessionDomainMapper {
Expand All @@ -14,8 +15,9 @@ export default class SessionDomainMapper {
public mapToDomainModel(session: SessionModel): Session {
return new Session({
id: new SessionId(session.id),
title: session.title,
titleId: new TitleId(session.titleId),
xuid: session.xuid ? new Xuid(session.xuid) : undefined,
title: session.title,
mediaId: session.mediaId,
version: session.version,
flags: new SessionFlags(session.flags),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export default class SessionPersistanceMapper {
public mapToDataModel(session: Session, updatedAt: Date): SessionModel {
return {
id: session.id.value,
title: session.title,
titleId: session.titleId.toString(),
xuid: session.xuid ? session.xuid.value : undefined,
title: session.title,
mediaId: session.mediaId,
version: session.version,
hostAddress: session.hostAddress.value,
Expand Down
2 changes: 2 additions & 0 deletions src/infrastructure/persistance/models/SessionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class Session {
@Prop({ required: true })
titleId: string;
@Prop({ required: true })
xuid: string;
@Prop({ required: true })
title: string;
@Prop({ required: true })
mediaId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class SessionController {
await this.commandBus.execute(
new CreateSessionCommand(
new TitleId(titleId),
request.xuid ? new Xuid(request.xuid) : undefined,
request.title,
request.mediaId,
request.version,
Expand Down Expand Up @@ -345,7 +346,7 @@ export class SessionController {
: false;

if (!request.privateSlots) {
this.logger.warn('Defaulting to public slot');
this.logger.debug('Defaulting to public slot');
}

members.set(new Xuid(xuid), is_private);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface CreateSessionRequest {
xuid: string;
title: string;
mediaId: string;
version: string;
Expand Down

0 comments on commit cd48eef

Please sign in to comment.