Skip to content

Commit 22662d5

Browse files
committed
최근 매칭 조회 api 기능
1 parent b3a4e14 commit 22662d5

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

src/matching/dto/matching.response.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiProperty } from '@nestjs/swagger';
1+
import { ApiProperty, OmitType } from '@nestjs/swagger';
22
import { Type } from 'class-transformer';
33

44
export class PatchMatchingResponse {
@@ -94,7 +94,7 @@ export class CreateMatchingResponse {
9494

9595
@ApiProperty({
9696
example: '2024-10-11T09:00:00.000Z',
97-
description: '신청청 시각',
97+
description: '신청 시각',
9898
})
9999
createdAt: string;
100100

@@ -129,3 +129,7 @@ export class GetMatchingsResponse {
129129
@Type(() => MatchingResponse)
130130
matching: MatchingResponse[];
131131
}
132+
133+
export class GetOneMatchingResponse extends OmitType(PatchMatchingResponse, [
134+
'chatRoomId',
135+
] as const) {}

src/matching/matching.controller.ts

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { MatchingService } from './matching.service';
1414
import {
1515
CreateMatchingSwagger,
1616
DeleteMatchingSwagger,
17+
getLatestMatchingSwagger,
1718
GetMatchingsSwagger,
1819
PatchMatchingRequestStatusSwagger,
1920
} from './matching.swagger';
@@ -34,6 +35,7 @@ import {
3435
PatchMatchingResponse,
3536
CreateMatchingResponse,
3637
GetMatchingsResponse,
38+
GetOneMatchingResponse,
3739
} from './dto/matching.response';
3840
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
3941
import { PostService } from 'src/post/post.service';
@@ -140,4 +142,22 @@ export class MatchingController {
140142
const response = await this.matchingService.getMatchings(req.user.id);
141143
return new BaseResponse(true, 'SUCCESS', response);
142144
}
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+
}
143163
}

src/matching/matching.service.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from './dto/matching.response';
1616
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
1717
import { StatusEnum } from 'src/common/enum/entityStatus';
18-
import { UserBlockService } from 'src/user-block/user-block.service';
1918
import dayjs from 'dayjs';
2019

2120
@Injectable()
@@ -147,6 +146,14 @@ export class MatchingService {
147146
}
148147
}
149148

149+
async getLatestMatching(currentUserId: number): Promise<Matching> {
150+
return await this.matchingRepository.findOne({
151+
where: { target: { id: currentUserId } },
152+
relations: ['target', 'requester'],
153+
order: { createdAt: 'DESC' },
154+
});
155+
}
156+
150157
async getMatchings(currentUserId: number): Promise<GetMatchingsResponse> {
151158
const matchings = await this.matchingRepository
152159
.createQueryBuilder('matching')

src/matching/matching.swagger.ts

+25
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@ 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+
95120
// 매칭 삭제 API Swagger
96121
export function DeleteMatchingSwagger(apiSummary: string) {
97122
return ApiOperation({ summary: apiSummary });

0 commit comments

Comments
 (0)