Skip to content

Commit ed5a26c

Browse files
authored
Merge pull request #65 from oodd-team/OD-164
매칭, 유저 응답 수정 Od 164
2 parents ea7a507 + fae0098 commit ed5a26c

18 files changed

+142
-176
lines changed

src/auth/auth.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { KakaoAuthGuard } from './guards/kakao.auth.guard';
1212
import { NaverAuthGuard } from './guards/naver.auth.guard';
1313
import { AuthGuard } from './guards/jwt.auth.guard';
1414
import { BaseResponse } from '../common/response/dto';
15-
import { GetUserInfo } from 'src/user/dto/response/get-user.response';
15+
import { GetUserInfo } from 'src/user/dto/response/user.response';
1616
import dayjs from 'dayjs';
1717

1818
@Controller('auth')
@@ -68,7 +68,7 @@ export class AuthController {
6868
async test(@Req() req: Request): Promise<BaseResponse<GetUserInfo>> {
6969
const user = await this.userService.getUserById(req.user?.id);
7070
return new BaseResponse<GetUserInfo>(true, 'SUCCESS', {
71-
userId: user.id,
71+
id: user.id,
7272
email: user.email,
7373
nickname: user.nickname,
7474
profilePictureUrl: user.profilePictureUrl,

src/auth/auth.swagger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { LoginResponse } from './dto/auth.response';
33
import { BaseResponse } from 'src/common/response/dto';
44
import { ErrorCodeVo } from 'src/common/exception/error';
55
import { ApiInternalServerErrorResponse } from '@nestjs/swagger';
6-
import { GetUserInfo } from 'src/user/dto/response/get-user.response';
6+
import { GetUserInfo } from 'src/user/dto/response/user.response';
77

88
// 카카오 로그인 API Swagger
99
export const KakaoLoginSwagger = (text: string) => {

src/matching/dto/matching.response.ts

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { Type } from 'class-transformer';
33

4-
export class PostMatchingResponse {
4+
export class CreateMatchingResponse {
5+
@ApiProperty({ example: 1, description: '매칭 ID' })
6+
matchingId: number;
7+
58
@ApiProperty({ example: 1, description: '채팅방 아이디' })
69
chatRoomId: number;
710

811
@ApiProperty({ example: 1, description: '신청한 유저 아이디' })
9-
fromUserId: number;
12+
requesterId: number;
1013

1114
@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
12-
toUserId: number;
15+
targetId: number;
1316
}
1417

1518
export class PatchMatchingResponse {
@@ -33,16 +36,34 @@ export class PatchMatchingResponse {
3336
chatRoomId?: number;
3437
}
3538

39+
class RepresentativePost {
40+
@ApiProperty({
41+
description: '매칭 요청자의 게시물 이미지 목록',
42+
type: [String],
43+
example: [
44+
{ url: 'https://example.com/image1.jpg', orderNum: 1 },
45+
{ url: 'https://example.com/image2.jpg', orderNum: 2 },
46+
],
47+
})
48+
postImages: { url: string; orderNum: number }[];
49+
50+
@ApiProperty({
51+
description: '매칭 요청자의 게시물 스타일 태그 목록',
52+
type: [String],
53+
example: ['classic', 'basic'],
54+
})
55+
styleTags: string[];
56+
}
3657
class RequesterResponse {
3758
@ApiProperty({
3859
description: '매칭 요청자의 ID',
3960
example: 19,
4061
})
41-
requesterId: number;
62+
id: number;
4263

4364
@ApiProperty({
4465
description: '매칭 요청자의 닉네임',
45-
example: '1d1d1d',
66+
example: '러러',
4667
})
4768
nickname: string;
4869

@@ -51,44 +72,25 @@ class RequesterResponse {
5172
example: 'https://example.com/image1.jpg',
5273
})
5374
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 }[];
6675

6776
@ApiProperty({
68-
description: '매칭 요청자의 게시물 스타일 태그 목록',
69-
type: [String],
70-
example: ['classic', 'basic'],
77+
description: '매칭 요청자의 대표 게시물이 없을 경우, 가장 최근 게시물 정보',
78+
type: RepresentativePost,
7179
})
72-
styleTags: string[];
80+
@Type(() => RepresentativePost)
81+
representativePost: RepresentativePost;
7382
}
7483

75-
class MatchingResponse {
84+
class Matching {
7685
@ApiProperty({ example: 1, description: '매칭 ID' })
77-
matchingId: number;
86+
id: number;
7887

7988
@ApiProperty({
8089
description: '매칭 요청자 정보',
8190
type: RequesterResponse,
8291
})
8392
@Type(() => RequesterResponse)
8493
requester: RequesterResponse;
85-
86-
@ApiProperty({
87-
description: '매칭 요청자의 대표 게시물이 없을 경우, 가장 최근 게시물 정보',
88-
type: RequesterPostResponse,
89-
})
90-
@Type(() => RequesterPostResponse)
91-
requesterPost: RequesterPostResponse;
9294
}
9395

9496
export class GetMatchingsResponse {
@@ -106,8 +108,8 @@ export class GetMatchingsResponse {
106108

107109
@ApiProperty({
108110
description: '매칭 정보',
109-
type: [MatchingResponse],
111+
type: [Matching],
110112
})
111-
@Type(() => MatchingResponse)
112-
matching: MatchingResponse[];
113+
@Type(() => Matching)
114+
matching: Matching[];
113115
}

src/matching/matching.controller.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { BaseResponse } from 'src/common/response/dto';
3333
import {
3434
GetMatchingsResponse,
3535
PatchMatchingResponse,
36-
PostMatchingResponse,
36+
CreateMatchingResponse,
3737
} from './dto/matching.response';
3838
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
3939
import { PostService } from 'src/post/post.service';
@@ -59,7 +59,7 @@ export class MatchingController {
5959
async createMatching(
6060
@Req() req: Request,
6161
@Body() body: CreateMatchingReqeust,
62-
): Promise<BaseResponse<PostMatchingResponse>> {
62+
): Promise<BaseResponse<CreateMatchingResponse>> {
6363
if (req.user.id !== body.requesterId)
6464
throw UnauthorizedException('권한이 없습니다.');
6565

@@ -83,10 +83,11 @@ export class MatchingController {
8383
throw InvalidInputValueException('이미 매칭 요청을 보냈습니다.');
8484

8585
const chatRoom = await this.matchingService.createMatching(body);
86-
return new BaseResponse<PostMatchingResponse>(true, 'SUCCESS', {
86+
return new BaseResponse<CreateMatchingResponse>(true, 'SUCCESS', {
87+
matchingId: chatRoom.matching.id,
8788
chatRoomId: chatRoom.id,
88-
toUserId: chatRoom.toUser.id,
89-
fromUserId: chatRoom.fromUser.id,
89+
targetId: chatRoom.toUser.id,
90+
requesterId: chatRoom.fromUser.id,
9091
});
9192
}
9293

src/matching/matching.service.ts

+23-21
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ export class MatchingService {
7474
const queryRunner = this.dataSource.createQueryRunner();
7575
await queryRunner.connect();
7676
await queryRunner.startTransaction();
77-
77+
const chatRoom = await this.chatRoomService.getChatRoomByMatchingId(
78+
matching.id,
79+
);
7880
try {
7981
if (body.requestStatus === 'accept') {
8082
matching.requestStatus = MatchingRequestStatusEnum.ACCEPTED;
8183
matching.acceptedAt = new Date();
82-
83-
const chatRoom = await this.chatRoomService.getChatRoomByMatchingId(
84-
matching.id,
85-
);
8684
chatRoom.requestStatus = MatchingRequestStatusEnum.ACCEPTED;
87-
await queryRunner.manager.save(chatRoom);
8885
} else if (body.requestStatus === 'reject') {
8986
matching.requestStatus = MatchingRequestStatusEnum.REJECTED;
9087
matching.rejectedAt = new Date();
88+
chatRoom.requestStatus = MatchingRequestStatusEnum.REJECTED;
89+
chatRoom.status = StatusEnum.DEACTIVATED;
90+
chatRoom.softDelete();
9191
}
92-
92+
await queryRunner.manager.save(chatRoom);
9393
await queryRunner.manager.save(matching);
9494
await queryRunner.commitTransaction();
9595

@@ -114,7 +114,9 @@ export class MatchingService {
114114
.andWhere('matching.requestStatus = :status', {
115115
status: MatchingRequestStatusEnum.PENDING,
116116
})
117-
.andWhere('matching.status = :activated', { activated: 'activated' })
117+
.andWhere('matching.status = :activated', {
118+
activated: StatusEnum.ACTIVATED,
119+
})
118120
.orderBy(
119121
// 우선순위: isRepresentative가 true인 게시물 먼저, 그 다음은 최신 게시물
120122
'CASE WHEN post.isRepresentative = true THEN 0 ELSE 1 END',
@@ -130,22 +132,22 @@ export class MatchingService {
130132
const requesterPost = matching.requester.posts[0];
131133

132134
return {
133-
matchingId: matching.id,
135+
id: matching.id,
134136
requester: {
135-
requesterId: matching.requester.id,
137+
id: matching.requester.id,
136138
nickname: matching.requester.nickname,
137139
profilePictureUrl: matching.requester.profilePictureUrl,
138-
},
139-
requesterPost: {
140-
postImages: requesterPost.postImages.map((image) => ({
141-
url: image.url,
142-
orderNum: image.orderNum,
143-
})),
144-
styleTags: requesterPost.postStyletags
145-
? requesterPost.postStyletags.map(
146-
(styleTag) => styleTag.styletag.tag,
147-
)
148-
: [],
140+
representativePost: {
141+
postImages: requesterPost.postImages.map((image) => ({
142+
url: image.url,
143+
orderNum: image.orderNum,
144+
})),
145+
styleTags: requesterPost.postStyletags
146+
? requesterPost.postStyletags.map(
147+
(styleTag) => styleTag.styletag.tag,
148+
)
149+
: [],
150+
},
149151
},
150152
};
151153
}),

src/matching/matching.swagger.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BaseSwaggerDecorator } from 'nestjs-swagger-decorator';
88
import {
99
GetMatchingsResponse,
1010
PatchMatchingResponse,
11-
PostMatchingResponse,
11+
CreateMatchingResponse,
1212
} from './dto/matching.response';
1313
import { BaseResponse } from 'src/common/response/dto';
1414

@@ -21,7 +21,7 @@ export function CreateMatchingSwagger(apiSummary: string) {
2121
statusCode: 200,
2222
responseOptions: [
2323
{
24-
model: PostMatchingResponse,
24+
model: CreateMatchingResponse,
2525
exampleTitle: '성공',
2626
exampleDescription: '성공했을 때 값',
2727
},
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
33

4-
export class CreateUserBlockDto {
4+
export class UserBlockRequest {
55
@ApiProperty({ example: 1, description: '차단한 사람' })
66
@IsNumber()
77
@IsNotEmpty()
8-
fromUserId!: number;
8+
requesterId!: number;
99

1010
@ApiProperty({ example: 2, description: '차단 당한 사람' })
1111
@IsNumber()
1212
@IsNotEmpty()
13-
toUserId!: number;
13+
targetId!: number;
1414

15-
@ApiProperty({ example: 'block', description: '차단하고 싶으면 block, 안 하고 싶으면 unblock' })
15+
@ApiProperty({
16+
example: 'block',
17+
description: '차단하고 싶으면 block, 안 하고 싶으면 unblock',
18+
})
1619
@IsString()
1720
@IsNotEmpty()
1821
action!: 'block' | 'unblock';
19-
}
22+
}

src/user-block/user-block.controller.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
22
import { UserBlockService } from './user-block.service';
33
import { CreateBlockUserSwagger } from './user-block.swagget';
44
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
5-
import { CreateUserBlockDto } from './dtos/user-block.dto';
5+
import { UserBlockRequest } from './dtos/user-block.request';
66
import { BaseResponse } from 'src/common/response/dto';
77
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
88
import { Request } from 'express';
@@ -17,13 +17,10 @@ export class UserBlockController {
1717
@Post()
1818
@CreateBlockUserSwagger('유저 차단하기 API')
1919
async createUserBlock(
20-
@Body() createUserBlockDto: CreateUserBlockDto,
20+
@Body() createUserBlockDto: UserBlockRequest,
2121
@Req() req: Request,
2222
): Promise<BaseResponse<null>> {
23-
const fromUserId = req.user['id'];
24-
25-
createUserBlockDto.fromUserId = fromUserId;
26-
23+
createUserBlockDto.requesterId = req.user.id;
2724
const resultCode =
2825
await this.userBlockService.createBlock(createUserBlockDto);
2926

src/user-block/user-block.service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
22
import { InjectRepository } from '@nestjs/typeorm';
33
import { UserBlock } from 'src/common/entities/user-block.entity';
44
import { Repository } from 'typeorm';
5-
import { CreateUserBlockDto } from './dtos/user-block.dto';
5+
import { UserBlockRequest } from './dtos/user-block.request';
66
import { UserService } from 'src/user/user.service';
77
import {
88
DataNotFoundException,
@@ -29,14 +29,14 @@ export class UserBlockService {
2929
return blockedUsers.map((block) => block.target.id);
3030
}
3131

32-
async createBlock(createUserBlockDto: CreateUserBlockDto): Promise<string> {
33-
const { fromUserId, toUserId, action } = createUserBlockDto;
32+
async createBlock(createUserBlockDto: UserBlockRequest): Promise<string> {
33+
const { requesterId, targetId, action } = createUserBlockDto;
3434

3535
const fromUser = await this.userService.findByFields({
36-
where: { id: fromUserId, status: StatusEnum.ACTIVATED },
36+
where: { id: requesterId, status: StatusEnum.ACTIVATED },
3737
});
3838
const toUser = await this.userService.findByFields({
39-
where: { id: toUserId, status: StatusEnum.ACTIVATED },
39+
where: { id: targetId, status: StatusEnum.ACTIVATED },
4040
});
4141

4242
if (!fromUser || !toUser) {
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { IsNotEmpty, IsNumber, IsString, MinLength } from 'class-validator';
33

4-
export class CreateUserReportDto {
4+
export class UserReportRequest {
55
@ApiProperty({ example: 1, description: '신고한 사람' })
66
@IsNumber()
77
@IsNotEmpty()
8-
fromUserId!: number;
8+
requesterId!: number;
99

1010
@ApiProperty({ example: 2, description: '신고당한 사람' })
1111
@IsNumber()
1212
@IsNotEmpty()
13-
toUserId!: number;
13+
targetId!: number;
1414

1515
@ApiProperty({ example: '질척거림', description: '신고 사유' })
1616
@IsString()
1717
reason!: string;
18-
}
18+
}

0 commit comments

Comments
 (0)