Skip to content

Commit f5cd128

Browse files
committed
최근 매칭 조회 소켓
1 parent 22662d5 commit f5cd128

5 files changed

+38
-48
lines changed

src/matching/dto/matching.response.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,10 @@ export class GetMatchingsResponse {
132132

133133
export class GetOneMatchingResponse extends OmitType(PatchMatchingResponse, [
134134
'chatRoomId',
135-
] as const) {}
135+
] as const) {
136+
@ApiProperty({
137+
example: '2024-10-11T09:00:00.000Z',
138+
description: '신청 시각',
139+
})
140+
createdAt: string;
141+
}

src/matching/matching.controller.ts

-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { MatchingService } from './matching.service';
1414
import {
1515
CreateMatchingSwagger,
1616
DeleteMatchingSwagger,
17-
getLatestMatchingSwagger,
1817
GetMatchingsSwagger,
1918
PatchMatchingRequestStatusSwagger,
2019
} from './matching.swagger';
@@ -142,22 +141,4 @@ export class MatchingController {
142141
const response = await this.matchingService.getMatchings(req.user.id);
143142
return new BaseResponse(true, 'SUCCESS', response);
144143
}
145-
146-
@Get('latest')
147-
@UseGuards(AuthGuard)
148-
@getLatestMatchingSwagger('최근 매칭 조회 API')
149-
async getLatestMatching(
150-
@Req() req: Request,
151-
): Promise<BaseResponse<GetOneMatchingResponse>> {
152-
const matching = await this.matchingService.getLatestMatching(req.user.id);
153-
if (!matching) {
154-
throw DataNotFoundException('매칭을 찾을 수 없습니다.');
155-
}
156-
return new BaseResponse<GetOneMatchingResponse>(true, '매칭 조회 성공', {
157-
id: matching.id,
158-
requesterId: matching.requester.id,
159-
targetId: matching.target.id,
160-
requestStatus: matching.requestStatus,
161-
});
162-
}
163144
}

src/matching/matching.service.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { InjectRepository } from '@nestjs/typeorm';
1212
import {
1313
CreateMatchingResponse,
1414
GetMatchingsResponse,
15+
GetOneMatchingResponse,
1516
} from './dto/matching.response';
1617
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
1718
import { StatusEnum } from 'src/common/enum/entityStatus';
@@ -146,12 +147,26 @@ export class MatchingService {
146147
}
147148
}
148149

149-
async getLatestMatching(currentUserId: number): Promise<Matching> {
150-
return await this.matchingRepository.findOne({
151-
where: { target: { id: currentUserId } },
150+
async getLatestMatching(
151+
userId: number,
152+
): Promise<GetOneMatchingResponse | {}> {
153+
const matching = await this.matchingRepository.findOne({
154+
where: { target: { id: userId } },
152155
relations: ['target', 'requester'],
153156
order: { createdAt: 'DESC' },
154157
});
158+
159+
if (!matching) {
160+
return {};
161+
}
162+
163+
return {
164+
id: matching.id,
165+
requesterId: matching.requester.id,
166+
targetId: matching.target.id,
167+
requestStatus: matching.requestStatus,
168+
createdAt: dayjs(matching.createdAt).format('YYYY-MM-DDTHH:mm:ssZ'),
169+
};
155170
}
156171

157172
async getMatchings(currentUserId: number): Promise<GetMatchingsResponse> {

src/matching/matching.swagger.ts

-25
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,6 @@ export function GetMatchingSwagger(apiSummary: string) {
9292
return ApiOperation({ summary: apiSummary });
9393
}
9494

95-
// 최근 매칭 조회 API Swagger
96-
export function getLatestMatchingSwagger(apiSummary: string) {
97-
return BaseSwaggerDecorator(
98-
{ summary: apiSummary },
99-
[
100-
{
101-
statusCode: 200,
102-
responseOptions: [
103-
{
104-
model: PatchMatchingResponse,
105-
exampleTitle: '성공',
106-
exampleDescription: '성공했을 때 값',
107-
},
108-
],
109-
baseResponseDto: BaseResponse,
110-
},
111-
],
112-
[
113-
ApiBadRequestResponse({ description: 'Bad Request' }),
114-
ApiNotFoundResponse({ description: '해당 유저가 존재하지 않습니다.' }),
115-
ApiInternalServerErrorResponse({ description: 'Internal Server Error' }),
116-
],
117-
);
118-
}
119-
12095
// 매칭 삭제 API Swagger
12196
export function DeleteMatchingSwagger(apiSummary: string) {
12297
return ApiOperation({ summary: apiSummary });

src/matchingEventGateway.ts

+13
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,17 @@ export class MatchingEventsGateway
158158
client.emit('error', '매칭 상태 변경 처리 중 오류가 발생했습니다.');
159159
}
160160
}
161+
162+
@SubscribeMessage('getLatestMatching')
163+
async handleGetLatestMatching(client: Socket, payload: { userId: number }) {
164+
const { userId } = payload;
165+
try {
166+
const latestMatching =
167+
await this.matchingService.getLatestMatching(userId);
168+
169+
client.emit('latestMatching', latestMatching);
170+
} catch (error) {
171+
client.emit('error', '매칭 조회 중 오류가 발생했습니다.');
172+
}
173+
}
161174
}

0 commit comments

Comments
 (0)