Skip to content

Commit 1835deb

Browse files
authored
Merge pull request #71 from oodd-team/dev
Dev
2 parents d519019 + 686c83f commit 1835deb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+262
-386
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/auth/strategies/jwt.strategy.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
2626
if (!user) {
2727
throw UnauthorizedException('유효하지 않은 토큰입니다.');
2828
}
29-
console.log(user);
3029
return { id: payload.id, email: payload.email, nickname: payload.nickname };
3130
}
3231
}

src/chat-message/chat-message.controller.spec.ts

-18
This file was deleted.

src/chat-message/chat-message.controller.ts

-4
This file was deleted.

src/chat-message/chat-message.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { forwardRef, Module } from '@nestjs/common';
22
import { ChatMessageService } from './chat-message.service';
3-
import { ChatMessageController } from './chat-message.controller';
43
import { TypeOrmModule } from '@nestjs/typeorm';
54
import { ChatMessage } from 'src/common/entities/chat-message.entity';
65
import { UserModule } from 'src/user/user.module';
@@ -13,7 +12,6 @@ import { ChatRoomModule } from 'src/chat-room/chat-room.module';
1312
forwardRef(() => ChatRoomModule),
1413
],
1514
providers: [ChatMessageService],
16-
controllers: [ChatMessageController],
1715
exports: [ChatMessageService],
1816
})
1917
export class ChatMessageModule {}

src/chat-room/chat-room.controller.spec.ts

-18
This file was deleted.

src/chat-room/chat-room.controller.ts

-22
This file was deleted.

src/chat-room/chat-room.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { forwardRef, Module } from '@nestjs/common';
2-
import { ChatRoomController } from './chat-room.controller';
32
import { ChatRoomService } from './chat-room.service';
43
import { ChatRoom } from 'src/common/entities/chat-room.entity';
54
import { TypeOrmModule } from '@nestjs/typeorm';
@@ -10,7 +9,6 @@ import { ChatMessageModule } from 'src/chat-message/chat-message.module';
109
TypeOrmModule.forFeature([ChatRoom]),
1110
forwardRef(() => ChatMessageModule),
1211
],
13-
controllers: [ChatRoomController],
1412
providers: [ChatRoomService],
1513
exports: [ChatRoomService],
1614
})

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

+32-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
33
import { ChatRoom } from 'src/common/entities/chat-room.entity';
44
import { Matching } from 'src/common/entities/matching.entity';
55
import { StatusEnum } from 'src/common/enum/entityStatus';
6+
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
67
import { DataNotFoundException } from 'src/common/exception/service.exception';
78
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
89
import { Repository, QueryRunner } from 'typeorm';
@@ -20,30 +21,46 @@ export class ChatRoomService {
2021
.leftJoinAndSelect('chatRoom.fromUser', 'fromUser')
2122
.leftJoinAndSelect('chatRoom.toUser', 'toUser')
2223
.leftJoinAndSelect('chatRoom.chatMessages', 'chatMessages')
23-
.where('chatRoom.fromUserId = :userId OR chatRoom.toUserId = :userId', {
24-
userId,
25-
})
26-
.andWhere('chatRoom.status = :status', { status: 'activated' })
27-
.andWhere('chatRoom.requestStatus = :requestStatus', {
28-
requestStatus: 'accepted',
29-
})
24+
.addSelect([
25+
'fromUser.id',
26+
'fromUser.nickname',
27+
'fromUser.profilePictureUrl',
28+
])
29+
.addSelect(['toUser.id', 'toUser.nickname', 'toUser.profilePictureUrl'])
30+
.where(
31+
'(chatRoom.fromUserId = :userId OR chatRoom.toUserId = :userId) AND chatRoom.status = :status AND chatRoom.requestStatus = :requestStatus',
32+
{
33+
userId,
34+
status: StatusEnum.ACTIVATED,
35+
requestStatus: MatchingRequestStatusEnum.ACCEPTED,
36+
},
37+
)
3038
.orderBy('chatMessages.createdAt', 'DESC')
3139
.getMany();
40+
if (!chatRooms || chatRooms.length === 0) {
41+
return [];
42+
}
3243

3344
// 각 채팅방에서 최신 메시지를 선택
3445
const chatRoomsWithLatestMessages = chatRooms.map((room) => {
3546
const otherUser =
36-
room.fromUser.id === userId ? room.toUser : room.fromUser;
47+
room.fromUser && room.fromUser.id === userId
48+
? room.toUser
49+
: room.fromUser;
50+
// fromUser나 toUser가 null인 경우, otherUser를 빈 객체로 설정
51+
const otherUserInfo = otherUser
52+
? {
53+
id: otherUser.id,
54+
nickname: otherUser.nickname,
55+
profilePictureUrl: otherUser.profilePictureUrl,
56+
}
57+
: {};
58+
3759
const latestMessage =
3860
room.chatMessages.length > 0 ? room.chatMessages[0] : null; // 가장 최근 메시지 선택
39-
4061
return {
41-
chatRoomId: room.id,
42-
otherUser: {
43-
id: otherUser.id,
44-
nickname: otherUser.nickname,
45-
profileUrl: otherUser.profilePictureUrl,
46-
},
62+
id: room.id,
63+
otherUser: otherUserInfo,
4764
latestMessage: latestMessage,
4865
};
4966
});

src/chat-room/chat-room.swagger.ts

-11
This file was deleted.
+6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
22
import { BaseEntity } from './base.entity';
33
import { Post } from './post.entity';
4+
import { ApiProperty } from '@nestjs/swagger';
45

56
@Entity('PostImage')
67
export class PostImage extends BaseEntity {
78
@ManyToOne(() => Post, (post) => post.postImages)
89
@JoinColumn({ name: 'postId' })
910
post!: Post;
1011

12+
@ApiProperty({
13+
example: 'http://imageurl.example',
14+
description: '게시글 이미지 URL',
15+
})
1116
@Column({ type: 'text' })
1217
url!: string;
1318

19+
@ApiProperty({ example: 1, description: '게시글 이미지 순서' })
1420
@Column({ type: 'bigint' })
1521
orderNum!: number;
1622
}

src/main.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { IoAdapter } from '@nestjs/platform-socket.io';
88
async function bootstrap() {
99
const app = await NestFactory.create(AppModule);
1010
app.useGlobalFilters(new ServiceExceptionToHttpExceptionFilter());
11-
app.useGlobalPipes(new ValidationPipe());
11+
app.useGlobalPipes(
12+
new ValidationPipe({
13+
transform: true,
14+
}),
15+
);
1216
app.useWebSocketAdapter(new IoAdapter(app));
1317
setupSwagger(app);
1418
await app.listen(process.env.PORT);

src/matching/dto/matching.response.ts

+37-35
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
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+
id: 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 {
1619
@ApiProperty({ example: 1, description: '매칭 ID' })
17-
matchingId: number;
20+
id: number;
1821

1922
@ApiProperty({ example: 1, description: '신청한 유저 아이디' })
2023
requesterId: number;
@@ -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,52 +72,33 @@ class RequesterResponse {
5172
example: 'https://example.com/image1.jpg',
5273
})
5374
profilePictureUrl: string;
54-
}
5575

56-
class RequesterPostResponse {
5776
@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'],
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 {
9597
@ApiProperty({
9698
description: '매칭 존재 여부',
9799
example: true,
98100
})
99-
isMatching: boolean;
101+
hasMatching: boolean;
100102

101103
@ApiProperty({
102104
description: '받은 매칭 수',
@@ -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
}

0 commit comments

Comments
 (0)