Skip to content
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

Dev #134

Merged
merged 41 commits into from
Sep 27, 2023
Merged

Dev #134

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6c04842
updated event schema for chat persistance
LucaLoubser Sep 25, 2023
bc28fd6
added service for chat persistance
LucaLoubser Sep 25, 2023
931895c
updated create event event handler to initailize chat attribute
LucaLoubser Sep 25, 2023
eeec0d1
updated event model to alloe chat persistence
LucaLoubser Sep 25, 2023
af68970
updated event interface to allow chat persistence
LucaLoubser Sep 25, 2023
2a438e8
added db funciton to allow chat persistence
LucaLoubser Sep 25, 2023
46a081f
added interface for messages to be saved
LucaLoubser Sep 25, 2023
fa8e51c
added command handler for persisting chat messages
LucaLoubser Sep 25, 2023
113711f
added interface for message persistence
LucaLoubser Sep 25, 2023
de6f1d7
added query handler for getting historic chats
LucaLoubser Sep 25, 2023
29eaf71
added command for storing chat messages
LucaLoubser Sep 25, 2023
30091d5
added query to retrieve historic chat data
LucaLoubser Sep 25, 2023
21e2934
added request format to perssit chats
LucaLoubser Sep 25, 2023
dde7c98
added request format to get persisted chats
LucaLoubser Sep 25, 2023
1695417
added response format to get persisted chats
LucaLoubser Sep 25, 2023
0c69e0a
linking for chat presistence and retrieval feature
LucaLoubser Sep 25, 2023
54cee58
added endpoint to retreive event chat data
LucaLoubser Sep 25, 2023
699838f
added service to retreive event chat data
LucaLoubser Sep 25, 2023
8d9a8d8
Merge branch 'dev' into api_chat_feature_dev
LucaLoubser Sep 27, 2023
400a9cd
Fix access error for public events
Stefan-vdm Sep 27, 2023
dc16e3c
updated socket event handler to persist messages in DB
LucaLoubser Sep 27, 2023
71d2e68
updated endpoint to retrive a event's chat
LucaLoubser Sep 27, 2023
e128b81
updated db fucniton to retrieve an event's chat
LucaLoubser Sep 27, 2023
be0f265
updated chat message interface
LucaLoubser Sep 27, 2023
1f26ac8
updated service to retrieve an event's chat
LucaLoubser Sep 27, 2023
3950793
updated event model to persist event chat messages
LucaLoubser Sep 27, 2023
79acfad
updated event handler for event chat persistence
LucaLoubser Sep 27, 2023
3fdf43f
updated chat message interface
LucaLoubser Sep 27, 2023
2f1cd87
updated event interface for chat persistence
LucaLoubser Sep 27, 2023
220d44d
updated request format
LucaLoubser Sep 27, 2023
035cc61
updated resonse format
LucaLoubser Sep 27, 2023
fb56c94
Fix event not returning event
Stefan-vdm Sep 27, 2023
2f0a950
Fixed chat bug with managers
08Arno30 Sep 27, 2023
3bde7ba
Added functionality to send message with enter key
08Arno30 Sep 27, 2023
9434e03
Fix: zooming out and then dragging
JsteReubsSoftware Sep 27, 2023
922692f
Merge pull request #133 from COS301-SE-2023/api_chat_feature_dev
Stefan-vdm Sep 27, 2023
134a9d0
Integrate chat persistence
Stefan-vdm Sep 27, 2023
f727af4
Fix providers for test
Stefan-vdm Sep 27, 2023
6d47393
Fixed bar chart on dashboard page
JsteReubsSoftware Sep 27, 2023
e5dd438
Merge branch 'dev' of https://github.com/COS301-SE-2023/Event-Partici…
JsteReubsSoftware Sep 27, 2023
8b1f0a5
Fix compiled tailwindcss
Stefan-vdm Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/api/src/app/socket/socket.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SocketGateway } from './socket.gateway';
import { SocketServiceService } from './socket-service.service';
import { EventService } from '@event-participation-trends/api/event/feature';
import { CommandBus, QueryBus } from '@nestjs/cqrs';

describe('SocketGateway', () => {
let gateway: SocketGateway;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [SocketGateway, SocketServiceService],
providers: [SocketGateway, SocketServiceService, EventService, CommandBus, QueryBus],
}).compile();

gateway = module.get<SocketGateway>(SocketGateway);
Expand Down
13 changes: 11 additions & 2 deletions apps/api/src/app/socket/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import { SocketServiceService as SocketService } from './socket-service.service';
import { Logger } from '@nestjs/common';
import { types as MediasoupTypes } from 'mediasoup';
import { EventService } from '@event-participation-trends/api/event/feature';

@WebSocketGateway({path: '/api/ws'})
export class SocketGateway implements OnGatewayDisconnect{
@WebSocketServer()
server: Server;
constructor(private readonly appService: SocketService) {
constructor(
private readonly appService: SocketService,
private readonly eventService: EventService,
) {
}

handleDisconnect(client: any) {
Expand All @@ -33,7 +37,12 @@

@SubscribeMessage('message')
message(client: Socket, payload: any){
Logger.debug(this.appService.users.get(client.id).eventID);
const eventId = this.appService.users.get(client.id).eventID;
Logger.debug(eventId);
this.eventService.addEventChatMessage({

Check warning on line 42 in apps/api/src/app/socket/socket.gateway.ts

View check run for this annotation

Codecov / codecov/patch

apps/api/src/app/socket/socket.gateway.ts#L40-L42

Added lines #L40 - L42 were not covered by tests
eventId: eventId,
messagePacket: payload,
});
this.server.to(this.appService.users.get(client.id).eventID).emit('message', payload);
}

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/assets/compiled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script src="assets/compiled.js"></script>
</head>
<body class="select-none">
<event-participation-trends-root></event-participation-trends-root>
Expand Down
26 changes: 25 additions & 1 deletion libs/api/core/feature/src/controllers/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
IUpdateEventFloorLayoutImgResponse,
IGetEventFloorlayoutImageResponse,
IGetEventStatisticsResponse,
IGetEventChatMessagesRequest,
IGetEventChatMessagesResponse,
} from '@event-participation-trends/api/event/util';
import {
Body,
Expand Down Expand Up @@ -593,10 +595,32 @@
imageType: requestBody.imageType,
};
return this.eventService.updateEventFloorLayoutImage(extractRequest);
}

}

@Get('getEventChats')
@SetMetadata('role', Role.VIEWER)
@UseGuards(JwtGuard,RbacGuard, CsrfGuard)
async getEventChats(
@Req() req: Request,
@Query() query: any

Check warning on line 606 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L606

Added line #L606 was not covered by tests
): Promise<IGetEventChatMessagesResponse> {
const request: any = req;

Check warning on line 608 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L608

Added line #L608 was not covered by tests

if(!query.eventId)
throw new HttpException("Bad Request: eventId not provided", 400);

Check warning on line 611 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L611

Added line #L611 was not covered by tests

if (request.user['email'] == undefined || request.user['email'] == null)
throw new HttpException('Bad Request: Manager email not provided', 400);

Check warning on line 614 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L614

Added line #L614 was not covered by tests

const extractRequest: IGetEventChatMessagesRequest = {

Check warning on line 616 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L616

Added line #L616 was not covered by tests
eventId: query.eventId,
};
return this.eventService.getEventChats(extractRequest);

Check warning on line 619 in libs/api/core/feature/src/controllers/event.controller.ts

View check run for this annotation

Codecov / codecov/patch

libs/api/core/feature/src/controllers/event.controller.ts#L619

Added line #L619 was not covered by tests
}
}


function computePreviousDayDate(): Date{
const currentDate = moment();
const dayBefore = currentDate.subtract(1, 'day');
Expand Down
6 changes: 4 additions & 2 deletions libs/api/event/data-access/schemas/event.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose, { HydratedDocument, Types } from 'mongoose';
import { Stall } from './stall.schema';
import { Sensor } from './sensor.schema';
import { Image } from './image.schema';
import { Position } from '../src/interfaces';
import { Position ,ChatMessage } from '../src/interfaces';

export type EventDocument = HydratedDocument<Event>;

Expand Down Expand Up @@ -52,6 +51,9 @@ export class Event{
@Prop({ type: Boolean })
PublicEvent: boolean | undefined | null;

@Prop( [ChatMessage] )
eventChats: ChatMessage[] | undefined | null;

}

export const EventSchema = SchemaFactory.createForClass(Event);
Expand Down
12 changes: 12 additions & 0 deletions libs/api/event/data-access/src/event.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Event,
Image,
} from '../schemas';
import { Types } from 'mongoose';
import { ChatMessage } from './interfaces';

@Injectable()
export class EventRepository {
Expand All @@ -22,6 +23,17 @@ export class EventRepository {
await this.eventModel.create(event);
}

async createChatMessage(eventId: Types.ObjectId, message: ChatMessage){
await this.eventModel.updateOne(
{ _id: {$eq: eventId}},
{ $addToSet: {eventChats :message}});
}

async getEventChatMessages(eventId: Types.ObjectId){
return await this.eventModel.find(
{_id :{$eq: eventId}}).select("eventChats");
}

async uploadImage(image: Image){
await this.imageModel.create(image);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

export interface IChatMessage {
text: string | undefined | null,
timestamp: Date | undefined | null,
user: {
id: string | undefined | null,
fullname: string | undefined | null,
profilePic: string | undefined | null,
role: string | undefined | null,
},
};

export class ChatMessage {
text: string | undefined | null;
timestamp: Date | undefined | null;
user: {
id: string | undefined | null;
fullname: string | undefined | null;
profilePic: string | undefined | null;
role: string | undefined | null;
} | undefined | null;
};
3 changes: 2 additions & 1 deletion libs/api/event/data-access/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './position.interface';
export * from './position.interface';
export * from './chat-message.interface';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AddChatMessageCommand } from '@event-participation-trends/api/event/util';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { EventRepository } from '@event-participation-trends/api/event/data-access';
import { Types } from 'mongoose';

@CommandHandler(AddChatMessageCommand)
export class AddChatMessageHandler implements ICommandHandler<AddChatMessageCommand, void> {
constructor(
private readonly eventRepository: EventRepository,

) {}

async execute(command: AddChatMessageCommand) {
console.log(`${AddChatMessageHandler.name}`);

const request = command.request;

if(request.messagePacket)
this.eventRepository.createChatMessage(
<Types.ObjectId> <unknown> request.eventId,
request.messagePacket
);
}
}
3 changes: 2 additions & 1 deletion libs/api/event/feature/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * from './upload-image.handler';
export * from './add-image-to-event.handler';
export * from './delete-event-image.handler';
export * from './remove-image-from-event.handler';
export * from './update-event-floorlayout.handler';
export * from './update-event-floorlayout.handler';
export * from './add-event-chat-message.handler';
4 changes: 4 additions & 0 deletions libs/api/event/feature/src/event.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
RemoveEventImageHandler,
DeleteEventImageHandler,
UpdateEventFloorLayoutImgHandler,
AddChatMessageHandler,
} from './commands';

import {
Expand All @@ -37,6 +38,7 @@ import {
GetAllActiveEventsHandler,
GetEventFloorlayoutImageHandler,
GetEventStatisticsHandler,
GetEventChatMessagesHandler,
} from './queries';

import {
Expand Down Expand Up @@ -81,6 +83,7 @@ export const CommandHandlers = [
RemoveEventImageHandler,
DeleteEventImageHandler,
UpdateEventFloorLayoutImgHandler,
AddChatMessageHandler,
]

export const EventHandlers = [
Expand Down Expand Up @@ -117,6 +120,7 @@ export const QueryHandlers = [
GetAllActiveEventsHandler,
GetEventFloorlayoutImageHandler,
GetEventStatisticsHandler,
GetEventChatMessagesHandler,
];


Expand Down
15 changes: 14 additions & 1 deletion libs/api/event/feature/src/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ import {
IUpdateEventFloorLayoutImgResponse,
IGetEventStatisticsResponse,
IGetEventFloorlayoutImageResponse,
IAddChatMessageRequest,
AddChatMessageCommand,
IGetEventChatMessagesRequest,
IGetEventChatMessagesResponse,
GetEventChatMessagesQuery,
} from '@event-participation-trends/api/event/util';
import { Injectable } from '@nestjs/common';
import { CommandBus, QueryBus } from '@nestjs/cqrs';
Expand All @@ -83,7 +88,7 @@ import { CommandBus, QueryBus } from '@nestjs/cqrs';
export class EventService {
constructor(
private readonly commandBus: CommandBus,
private readonly queryBus: QueryBus
private readonly queryBus: QueryBus,
) {}

async createEvent(request: ICreateEventRequest) {
Expand Down Expand Up @@ -205,4 +210,12 @@ export class EventService {
async updateEventFloorLayoutImage(request: IUpdateEventFloorLayoutImgRequest) {
return await this.commandBus.execute<UpdateEventFloorLayoutImgCommand, IUpdateEventFloorLayoutImgResponse>(new UpdateEventFloorLayoutImgCommand(request));
}

async addEventChatMessage(request: IAddChatMessageRequest){
return await this.commandBus.execute<AddChatMessageCommand, void>(new AddChatMessageCommand(request));
}

async getEventChats(request: IGetEventChatMessagesRequest) {
return await this.queryBus.execute<GetEventChatMessagesQuery, IGetEventChatMessagesResponse>(new GetEventChatMessagesQuery(request));
}
}
3 changes: 2 additions & 1 deletion libs/api/event/feature/src/events/create-event.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateEventEvent, Position } from '@event-participation-trends/api/event/util';
import { IEventHandler, EventsHandler } from '@nestjs/cqrs';
import { IEvent } from "@event-participation-trends/api/event/util";
import { EventRepository } from '@event-participation-trends/api/event/data-access';
import { ChatMessage, EventRepository } from '@event-participation-trends/api/event/data-access';
import { Types } from 'mongoose';
import { EmailService } from '@event-participation-trends/api/email/feature'
import { EmailContent, EmailSubject} from '@event-participation-trends/api/email/util';
Expand Down Expand Up @@ -37,6 +37,7 @@ export class CreateEventEventHandler implements IEventHandler<CreateEventEvent>
Requesters: new Array<Types.ObjectId>(),
Viewers: ViewersArr,
PublicEvent: event.event.PublicEvent,
eventChats: Array<ChatMessage>(),
}

await this.eventRepository.createEvent(eventToCreate);
Expand Down
8 changes: 6 additions & 2 deletions libs/api/event/feature/src/models/event.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
IEvent,
CreateEventEvent,
IFloorLayout,
IFloorLayout,
ChatMessage,
} from '@event-participation-trends/api/event/util';
import {
IStall,
Expand All @@ -27,6 +28,7 @@ export class Event extends AggregateRoot implements IEvent {
public Requesters?: Types.ObjectId[] | undefined | null,
public Viewers?: Types.ObjectId[] | undefined | null,
public PublicEvent?: boolean | undefined | null,
public eventChats?: ChatMessage[] | undefined | null,
){
super();
}
Expand All @@ -50,7 +52,8 @@ export class Event extends AggregateRoot implements IEvent {
event.Manager,
event.Requesters,
event.Viewers,
event.PublicEvent
event.PublicEvent,
event.eventChats,
);
return instance;
}
Expand All @@ -71,6 +74,7 @@ export class Event extends AggregateRoot implements IEvent {
Requesters: this.Requesters,
Viewers: this.Viewers,
PublicEvent: this.PublicEvent,
eventChats: this.eventChats,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EventRepository } from '@event-participation-trends/api/event/data-access';
import { ChatMessage, GetEventChatMessagesQuery, IGetEventChatMessagesResponse } from '@event-participation-trends/api/event/util';
import { QueryHandler, IQueryHandler } from '@nestjs/cqrs';
import { Types } from 'mongoose';

@QueryHandler(GetEventChatMessagesQuery)
export class GetEventChatMessagesHandler implements IQueryHandler<GetEventChatMessagesQuery, IGetEventChatMessagesResponse> {
constructor(
private readonly eventRepository: EventRepository,
) {}

async execute(query: GetEventChatMessagesQuery) {
console.log(`${GetEventChatMessagesHandler.name}`);
const request = query.request;
const eventIdObj = <Types.ObjectId> <unknown> request.eventId;

const chats = new Array<ChatMessage>();
const chatDocs = await this.eventRepository.getEventChatMessages(eventIdObj);
chatDocs[0]?.eventChats?.forEach(doc=>{
chats.push({
text: doc.text,
timestamp: doc.timestamp,
user: doc.user,
})
})

return {messages :<ChatMessage[]><unknown> chats};
}

}
3 changes: 2 additions & 1 deletion libs/api/event/feature/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './get-managed-event-categories.handler';
export * from './get-floorplan-boundaries.handler';
export * from './get-all-active-events.handler';
export * from './get-event-floorlayout-image.handler';
export * from './get-event-statistics.handler';
export * from './get-event-statistics.handler';
export * from './get-event-chat-messages.handler';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IAddChatMessageRequest} from '../requests';

export class AddChatMessageCommand {
constructor(public readonly request: IAddChatMessageRequest) {}
}
3 changes: 2 additions & 1 deletion libs/api/event/util/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * from './upload-image.command';
export * from './add-image-to-event.command';
export * from './delete-event-image.command';
export * from './remove-image-from-event.command';
export * from './update-event-floorlayout-image.command';
export * from './update-event-floorlayout-image.command';
export * from './add-event-chat-message.command';
Loading
Loading