Skip to content

Commit 7c38dfb

Browse files
committed
매칭 응답 chatRoomId 추가, dto 통합
1 parent f9ecfa6 commit 7c38dfb

9 files changed

+152
-126
lines changed

src/chat-room/chat-room.service.ts

+9
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,13 @@ export class ChatRoomService {
7777

7878
await this.chatRoomRepository.save(chatRoom);
7979
}
80+
81+
async getChatRoomByMatchingId(matchingId: number): Promise<ChatRoom> {
82+
return await this.chatRoomRepository.findOne({
83+
where: {
84+
matching: { id: matchingId },
85+
},
86+
relations: ['matching'],
87+
});
88+
}
8089
}

src/matching/dto/Patch-matching.request.ts

-13
This file was deleted.

src/matching/dto/Patch-matching.response.ts

-19
This file was deleted.

src/matching/dto/get-matching.response.ts

-81
This file was deleted.

src/matching/dto/matching.request.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsInt, IsString, MaxLength, MinLength } from 'class-validator';
2+
import { IsIn, IsInt, IsString, MaxLength, MinLength } from 'class-validator';
33

44
export class CreateMatchingReqeust {
55
@ApiProperty({ example: 1, description: '신청하는 유저 아이디' })
@@ -19,3 +19,14 @@ export class CreateMatchingReqeust {
1919
@MaxLength(100)
2020
message: string;
2121
}
22+
23+
export class PatchMatchingRequest {
24+
@ApiProperty({
25+
example: 'accept',
26+
enum: ['accept', 'reject'],
27+
description: '수락 또는 거절',
28+
})
29+
@IsString()
30+
@IsIn(['accept', 'reject'])
31+
requestStatus: 'accept' | 'reject';
32+
}

src/matching/dto/matching.response.ts

+101
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ApiProperty } from '@nestjs/swagger';
2+
import { Type } from 'class-transformer';
23

34
export class PostMatchingResponse {
45
@ApiProperty({ example: 1, description: '채팅방 아이디' })
@@ -10,3 +11,103 @@ export class PostMatchingResponse {
1011
@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
1112
toUserId: number;
1213
}
14+
15+
export class PatchMatchingResponse {
16+
@ApiProperty({ example: 1, description: '매칭 ID' })
17+
matchingId: number;
18+
19+
@ApiProperty({ example: 1, description: '신청한 유저 아이디' })
20+
requesterId: number;
21+
22+
@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
23+
targetId: number;
24+
25+
@ApiProperty({
26+
example: 'accept',
27+
enum: ['accept', 'reject', 'pending'],
28+
description: '수락 또는 거절',
29+
})
30+
requestStatus: 'accept' | 'reject' | 'pending';
31+
32+
@ApiProperty({ example: 1, description: '채팅방 아이디' })
33+
chatRoomId?: number;
34+
}
35+
36+
class RequesterResponse {
37+
@ApiProperty({
38+
description: '매칭 요청자의 ID',
39+
example: '19',
40+
})
41+
requesterId: number;
42+
43+
@ApiProperty({
44+
description: '매칭 요청자의 닉네임',
45+
example: '1d1d1d',
46+
})
47+
nickname: string;
48+
49+
@ApiProperty({
50+
description: '매칭 요청자의 프로필 이미지 url',
51+
example: 'https://example.com/image1.jpg',
52+
})
53+
profilePictureUrl: string;
54+
}
55+
56+
class RequesterPostResponse {
57+
@ApiProperty({
58+
description: '매칭 요청자의 게시물 이미지 목록',
59+
type: [String],
60+
example: [
61+
{ url: 'https://example.com/image1.jpg', orderNum: 1 },
62+
{ url: 'https://example.com/image2.jpg', orderNum: 2 },
63+
],
64+
})
65+
postImages: { url: string; orderNum: number }[];
66+
67+
@ApiProperty({
68+
description: '매칭 요청자의 게시물 스타일 태그 목록',
69+
type: [String],
70+
example: ['classic', 'basic'],
71+
})
72+
styleTags: string[];
73+
}
74+
75+
class MatchingResponse {
76+
@ApiProperty({ example: 1, description: '매칭 ID' })
77+
matchingId: number;
78+
79+
@ApiProperty({
80+
description: '매칭 요청자 정보',
81+
type: RequesterResponse,
82+
})
83+
@Type(() => RequesterResponse)
84+
requester: RequesterResponse;
85+
86+
@ApiProperty({
87+
description: '매칭 요청자의 대표 게시물이 없을 경우, 가장 최근 게시물 정보',
88+
type: RequesterPostResponse,
89+
})
90+
@Type(() => RequesterPostResponse)
91+
requesterPost: RequesterPostResponse;
92+
}
93+
94+
export class GetMatchingsResponse {
95+
@ApiProperty({
96+
description: '매칭 존재 여부',
97+
example: true,
98+
})
99+
isMatching: boolean;
100+
101+
@ApiProperty({
102+
description: '받은 매칭 수',
103+
example: 10,
104+
})
105+
matchingsCount: number;
106+
107+
@ApiProperty({
108+
description: '매칭 정보',
109+
type: [MatchingResponse],
110+
})
111+
@Type(() => MatchingResponse)
112+
matching: MatchingResponse[];
113+
}

src/matching/matching.controller.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
PatchMatchingRequestStatusSwagger,
1919
} from './matching.swagger';
2020
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
21-
import { CreateMatchingReqeust } from './dto/matching.request';
21+
import {
22+
CreateMatchingReqeust,
23+
PatchMatchingRequest,
24+
} from './dto/matching.request';
2225
import { UserService } from 'src/user/user.service';
2326
import { Request } from 'express';
2427
import {
@@ -27,12 +30,14 @@ import {
2730
UnauthorizedException,
2831
} from 'src/common/exception/service.exception';
2932
import { BaseResponse } from 'src/common/response/dto';
30-
import { PostMatchingResponse } from './dto/matching.response';
33+
import {
34+
GetMatchingsResponse,
35+
PatchMatchingResponse,
36+
PostMatchingResponse,
37+
} from './dto/matching.response';
3138
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
32-
import { PatchMatchingRequest } from './dto/Patch-matching.request';
33-
import { GetMatchingsResponse } from './dto/get-matching.response';
34-
import { PatchMatchingResponse } from './dto/Patch-matching.response';
3539
import { PostService } from 'src/post/post.service';
40+
import { ChatRoomService } from 'src/chat-room/chat-room.service';
3641

3742
@ApiBearerAuth('Authorization')
3843
@Controller('matching')
@@ -43,6 +48,7 @@ export class MatchingController {
4348
@Inject(forwardRef(() => UserService))
4449
private readonly userService: UserService,
4550
private readonly postService: PostService,
51+
private readonly chatRoomService: ChatRoomService,
4652
) {}
4753

4854
@Post()
@@ -86,6 +92,9 @@ export class MatchingController {
8692
@Body() body: PatchMatchingRequest,
8793
): Promise<BaseResponse<PatchMatchingResponse>> {
8894
const matching = await this.matchingService.getMatchingById(matchingId);
95+
const chatRoom = await this.chatRoomService.getChatRoomByMatchingId(
96+
matching.id,
97+
);
8998
if (req.user.id !== matching.target.id) {
9099
throw UnauthorizedException('권한이 없습니다.');
91100
}
@@ -94,6 +103,10 @@ export class MatchingController {
94103
throw InvalidInputValueException('이미 처리된 요청입니다.');
95104
}
96105

106+
if (!chatRoom) {
107+
throw DataNotFoundException('채팅방을 찾을 수 없습니다.');
108+
}
109+
97110
await this.matchingService.patchMatchingRequestStatus(matching, body);
98111
return new BaseResponse<PatchMatchingResponse>(
99112
true,
@@ -103,6 +116,7 @@ export class MatchingController {
103116
requesterId: matching.requester.id,
104117
targetId: matching.target.id,
105118
requestStatus: matching.requestStatus,
119+
chatRoomId: chatRoom.id,
106120
},
107121
);
108122
}

src/matching/matching.service.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Injectable } from '@nestjs/common';
2-
import { CreateMatchingReqeust } from './dto/matching.request';
2+
import {
3+
CreateMatchingReqeust,
4+
PatchMatchingRequest,
5+
} from './dto/matching.request';
36
import { DataSource, Repository } from 'typeorm';
47
import { Matching } from 'src/common/entities/matching.entity';
58
import { ChatRoomService } from '../chat-room/chat-room.service';
@@ -10,8 +13,7 @@ import {
1013
import { ChatMessageService } from 'src/chat-message/chat-message.service';
1114
import { ChatRoom } from 'src/common/entities/chat-room.entity';
1215
import { InjectRepository } from '@nestjs/typeorm';
13-
import { PatchMatchingRequest } from './dto/Patch-matching.request';
14-
import { GetMatchingsResponse } from './dto/get-matching.response';
16+
import { GetMatchingsResponse } from './dto/matching.response';
1517

1618
@Injectable()
1719
export class MatchingService {
@@ -29,7 +31,7 @@ export class MatchingService {
2931
await queryRunner.connect();
3032
await queryRunner.startTransaction();
3133
try {
32-
queryRunner.manager.save(Matching, {
34+
matching = await queryRunner.manager.save(Matching, {
3335
requester: { id: body.requesterId },
3436
target: { id: body.targetId },
3537
});

src/matching/matching.swagger.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
ApiOperation,
66
} from '@nestjs/swagger';
77
import { BaseSwaggerDecorator } from 'nestjs-swagger-decorator';
8-
import { PostMatchingResponse } from './dto/matching.response';
8+
import {
9+
GetMatchingsResponse,
10+
PatchMatchingResponse,
11+
PostMatchingResponse,
12+
} from './dto/matching.response';
913
import { BaseResponse } from 'src/common/response/dto';
10-
import { GetMatchingsResponse } from './dto/get-matching.response';
11-
import { PatchMatchingResponse } from './dto/Patch-matching.response';
1214

1315
// 매칭 생성 API Swagger
1416
export function CreateMatchingSwagger(apiSummary: string) {

0 commit comments

Comments
 (0)