Skip to content

Commit 30ff2fe

Browse files
committed
Add interfaces
1 parent 796cd5f commit 30ff2fe

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

peerprep-fe/src/app/(main)/match/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { User, Code } from 'lucide-react';
66
import { Button } from '@/components/ui/button';
77
import { useAuthStore } from '@/state/useAuthStore';
88
import { consumeMessageFromQueue, sendMessageToQueue } from '@/lib/rabbitmq';
9-
import { Match } from '@/types/types';
9+
import { UserMatchingResponse } from '@/types/types';
1010

1111
export default function LoadingPage() {
1212
const [elapsedTime, setElapsedTime] = useState(0);
@@ -17,9 +17,9 @@ export default function LoadingPage() {
1717

1818
// Function to consume messages from the RabbitMQ queue
1919
const handleStartListening = () => {
20-
const onMessageReceived = (message: Match) => {
20+
const onMessageReceived = (message: UserMatchingResponse) => {
2121
if (message.status == "matched") {
22-
console.log('Match found, your partner is', message.match);
22+
console.log('Match found, your partner is', message.match.name);
2323
setMatchStatus('matched');
2424
} else {
2525
console.log('Match failed');

peerprep-fe/src/components/dialogs/PreMatch.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { TopicsPopover } from '@/app/(main)/components/filter/TopicsPopover';
1515
import { sendMessageToQueue } from '@/lib/rabbitmq';
1616
import { axiosAuthClient } from '@/network/axiosClient';
1717
import { DIFFICULTY_OPTIONS } from '@/lib/constants';
18+
import { UserMatchingRequest } from '@/types/types';
1819

1920
export function PreMatch() {
2021
const [open, setOpen] = useState(false);
@@ -25,7 +26,7 @@ export function PreMatch() {
2526
const handleConfirm = async () => {
2627
try {
2728
const profileDetails = await getProfileDetails();
28-
const message = {
29+
const message : UserMatchingRequest = {
2930
_id: profileDetails.id,
3031
name: profileDetails.username,
3132
topic: selectedTopics[0] || '', // TODO: change to list, but current backend only accepts 1

peerprep-fe/src/lib/rabbitmq.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { UserMatchingRequest, UserMatchingResponse } from '@/types/types';
23
import { Client, IFrame, IMessage } from '@stomp/stompjs';
34

45
let isConnected = false;
56

6-
const sendMessageToQueue = async (message: Record<string, any>) => {
7+
const sendMessageToQueue = async (message: UserMatchingRequest) => {
78
const uri = process.env.NEXT_PUBLIC_RABBITMQ_URL;
89
const user = process.env.NEXT_PUBLIC_RABBITMQ_USER;
910
const pass = process.env.NEXT_PUBLIC_RABBITMQ_PW;
@@ -52,7 +53,7 @@ const sendMessageToQueue = async (message: Record<string, any>) => {
5253

5354
const consumeMessageFromQueue = async (
5455
queue: string,
55-
onMessage: (message: any) => void,
56+
onMessage: (message: UserMatchingResponse) => void,
5657
) => {
5758
const uri = process.env.NEXT_PUBLIC_RABBITMQ_URL;
5859
const user = process.env.NEXT_PUBLIC_RABBITMQ_USER;

peerprep-fe/src/types/types.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ interface User {
4848
username: string;
4949
}
5050

51-
interface Match {
52-
status: string;
53-
match: string;
51+
interface UserMatchingRequest {
52+
_id: string;
53+
name?: string;
54+
difficulty?: string;
55+
topic?: string;
56+
type: string;
57+
}
5458

59+
interface UserMatchingResponse {
60+
status: string;
61+
match: UserMatchingRequest;
5562
}
5663

5764
export type {
@@ -61,5 +68,6 @@ export type {
6168
FilterBadgeProps,
6269
FilterSelectProps,
6370
User,
64-
Match,
71+
UserMatchingResponse,
72+
UserMatchingRequest,
6573
};

0 commit comments

Comments
 (0)