Skip to content

Commit 887704e

Browse files
authored
Merge pull request #87 from oodd-team/dev
Dev
2 parents d327b40 + 4a20511 commit 887704e

24 files changed

+731
-12266
lines changed

package-lock.json

-12,122
This file was deleted.

src/app.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { AuthModule } from './auth/auth.module';
2222
import { DayjsModule } from './common/dayjs/dayjs.module'; // DayjsModule 추가
2323
import { EventsGateway } from './eventGateway';
2424
import { ConfigService } from '@nestjs/config';
25+
import { MatchingEventsGateway } from './matchingEventGateway';
26+
import { UserStyletagModule } from './user-styletag/user-styletag.module';
2527

2628
const configService: ConfigService = new ConfigService();
2729

@@ -64,8 +66,9 @@ const configService: ConfigService = new ConfigService();
6466
UserBlockModule,
6567
UserReportModule,
6668
AuthModule,
69+
UserStyletagModule,
6770
],
6871
controllers: [AppController],
69-
providers: [AppService, EventsGateway],
72+
providers: [AppService, EventsGateway, MatchingEventsGateway],
7073
})
7174
export class AppModule {}

src/auth/auth.controller.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Controller, Get, Query, Req, Res, UseGuards } from '@nestjs/common';
1+
import {
2+
BadRequestException,
3+
Controller,
4+
Get,
5+
Query,
6+
Req,
7+
Res,
8+
UseGuards,
9+
} from '@nestjs/common';
210
import { UserService } from 'src/user/user.service';
311
import {
412
GetJwtInfoSwagger,
@@ -13,8 +21,6 @@ import { NaverAuthGuard } from './guards/naver.auth.guard';
1321
import { AuthGuard } from './guards/jwt.auth.guard';
1422
import { BaseResponse } from '../common/response/dto';
1523
import { GetUserInfo } from 'src/user/dto/response/user.response';
16-
import dayjs from 'dayjs';
17-
1824
@Controller('auth')
1925
@ApiTags('[서비스] Auth 관련')
2026
export class AuthController {
@@ -66,16 +72,12 @@ export class AuthController {
6672
@GetJwtInfoSwagger('JWT 토큰 정보 조회 API')
6773
@Get('/me')
6874
async test(@Req() req: Request): Promise<BaseResponse<GetUserInfo>> {
69-
const user = await this.userService.getUserById(req.user?.id);
70-
return new BaseResponse<GetUserInfo>(true, 'SUCCESS', {
71-
id: user.id,
72-
email: user.email,
73-
nickname: user.nickname,
74-
profilePictureUrl: user.profilePictureUrl,
75-
name: user.name,
76-
phoneNumber: user.phoneNumber,
77-
birthDate: dayjs(user.birthDate).format('YYYY-MM-DD'),
78-
bio: user.bio,
79-
});
75+
console.log(req.user);
76+
const user = await this.userService.getUserWithTag(req.user?.id);
77+
if (!user) throw new BadRequestException('User not found');
78+
79+
const userInfo = new GetUserInfo(user);
80+
81+
return new BaseResponse<GetUserInfo>(true, 'SUCCESS', userInfo);
8082
}
8183
}

src/auth/strategies/kakao.strategy.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PassportStrategy } from '@nestjs/passport';
33
import { Profile, Strategy } from 'passport-kakao';
44
import { SocialUser } from '../dto/auth.dto';
55
import { ConfigService } from '@nestjs/config';
6-
import { Request } from 'express';
76

87
@Injectable()
98
export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
@@ -16,19 +15,20 @@ export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
1615
});
1716
}
1817

19-
async authenticate(req: Request) {
18+
authenticate(req: any, options?: any) {
2019
if (req.query.redirectUrl) {
2120
// /auth
2221
return super.authenticate(req, {
22+
...options,
2323
state: encodeURIComponent(req.query.redirectUrl as string),
2424
});
2525
}
2626
// /auth/callback
27-
return super.authenticate(req);
27+
return super.authenticate(req, options);
2828
}
2929

3030
async validate(
31-
req: Request,
31+
req: any,
3232
accessToken: string,
3333
refreshToken: string,
3434
profile: Profile,

src/chat-message/chat-message.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
33
import { ChatMessage } from 'src/common/entities/chat-message.entity';
44
import { ChatRoom } from 'src/common/entities/chat-room.entity';
55
import { StatusEnum } from 'src/common/enum/entityStatus';
6-
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
6+
import { CreateMatchingRequest } from 'src/matching/dto/matching.request';
77
import { QueryRunner, Repository } from 'typeorm';
88

99
@Injectable()
@@ -80,7 +80,7 @@ export class ChatMessageService {
8080
async createChatMessage(
8181
queryRunner: QueryRunner,
8282
chatRoom: ChatRoom,
83-
body: CreateMatchingReqeust,
83+
body: CreateMatchingRequest,
8484
): Promise<ChatMessage> {
8585
return queryRunner.manager.save(ChatMessage, {
8686
chatRoom: chatRoom,

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Matching } from 'src/common/entities/matching.entity';
66
import { StatusEnum } from 'src/common/enum/entityStatus';
77
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
88
import { DataNotFoundException } from 'src/common/exception/service.exception';
9-
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
9+
import { CreateMatchingRequest } from 'src/matching/dto/matching.request';
1010
import { Repository, QueryRunner } from 'typeorm';
1111

1212
@Injectable()
@@ -60,6 +60,7 @@ export class ChatRoomService {
6060

6161
const latestMessage =
6262
room.chatMessages.length > 0 ? room.chatMessages[0] : null; // 가장 최근 메시지 선택
63+
6364
return {
6465
id: room.id,
6566
otherUser: otherUserInfo,
@@ -72,7 +73,7 @@ export class ChatRoomService {
7273
async createChatRoom(
7374
queryRunner: QueryRunner,
7475
matching: Matching,
75-
body: CreateMatchingReqeust,
76+
body: CreateMatchingRequest,
7677
): Promise<ChatRoom> {
7778
// 채팅방 생성 로직
7879
return await queryRunner.manager.save(ChatRoom, {
@@ -116,6 +117,7 @@ export class ChatRoomService {
116117
matching: { id: matchingId },
117118
},
118119
relations: ['matching'],
120+
withDeleted: true, // 소프트 딜리트된 데이터도 조회
119121
});
120122
}
121123
}

src/common/entities/styletag.entity.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Entity, Column, OneToMany } from 'typeorm';
22
import { BaseEntity } from './base.entity';
33
import { PostStyletag } from './post-styletag.entity';
4+
import { UserStyletag } from './user-styletag.entity';
45

56
@Entity('Styletag')
67
export class Styletag extends BaseEntity {
@@ -9,4 +10,7 @@ export class Styletag extends BaseEntity {
910

1011
@OneToMany(() => PostStyletag, (postStyletag) => postStyletag.styletag)
1112
postStyletags!: PostStyletag[];
13+
14+
@OneToMany(() => UserStyletag, (userStyletag) => userStyletag.styletag)
15+
userStyletags!: UserStyletag[];
1216
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Entity, JoinColumn, ManyToOne } from 'typeorm';
2+
import { BaseEntity } from './base.entity';
3+
import { Styletag } from './styletag.entity';
4+
import { User } from './user.entity';
5+
6+
@Entity('UserStyletag')
7+
export class UserStyletag extends BaseEntity {
8+
@ManyToOne(() => User, (user) => user.userStyletags)
9+
@JoinColumn({ name: 'userId' })
10+
user!: User;
11+
12+
@ManyToOne(() => Styletag, (styletag) => styletag.userStyletags)
13+
@JoinColumn({ name: 'styletagId' })
14+
styletag!: Styletag;
15+
}

src/common/entities/user.entity.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { PostLike } from './post-like.entity';
88
import { PostReport } from './post-report.entity';
99
import { ChatMessage } from './chat-message.entity';
1010
import { ApiProperty } from '@nestjs/swagger';
11+
import { UserStyletag } from './user-styletag.entity';
1112

1213
@Entity('User')
1314
export class User extends BaseEntity {
@@ -96,6 +97,9 @@ export class User extends BaseEntity {
9697
@OneToMany(() => PostReport, (postReport) => postReport.reporter)
9798
postReports!: PostReport[];
9899

100+
@OneToMany(() => UserStyletag, (userStyletag) => userStyletag.user)
101+
userStyletags!: UserStyletag[];
102+
99103
// 대표 게시물 필드 추가
100104
@OneToOne(() => Post, (post) => post.user)
101105
representativePost?: Post | null;

src/matching/dto/matching.request.ts

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

4-
export class CreateMatchingReqeust {
4+
export class CreateMatchingRequest {
55
@ApiProperty({ example: 1, description: '신청하는 유저 아이디' })
66
@IsInt()
77
requesterId: number;
@@ -21,6 +21,10 @@ export class CreateMatchingReqeust {
2121
}
2222

2323
export class PatchMatchingRequest {
24+
@ApiProperty({ example: 1, description: '매칭 아이디' })
25+
@IsInt()
26+
id: number;
27+
2428
@ApiProperty({
2529
example: 'accept',
2630
enum: ['accept', 'reject'],

src/matching/dto/matching.response.ts

+59-26
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
import { ApiProperty } from '@nestjs/swagger';
1+
import { ApiProperty, OmitType } from '@nestjs/swagger';
22
import { Type } from 'class-transformer';
3-
4-
export class CreateMatchingResponse {
5-
@ApiProperty({ example: 1, description: '매칭 ID' })
6-
id: number;
7-
8-
@ApiProperty({ example: 1, description: '채팅방 아이디' })
9-
chatRoomId: number;
10-
11-
@ApiProperty({ example: 1, description: '신청한 유저 아이디' })
12-
requesterId: number;
13-
14-
@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
15-
targetId: number;
16-
}
3+
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
174

185
export class PatchMatchingResponse {
196
@ApiProperty({ example: 1, description: '매칭 ID' })
@@ -81,7 +68,7 @@ class RequesterResponse {
8168
representativePost?: RepresentativePost;
8269
}
8370

84-
class Matching {
71+
export class MatchingResponse {
8572
@ApiProperty({ example: 1, description: '매칭 ID' })
8673
id: number;
8774

@@ -93,23 +80,69 @@ class Matching {
9380
requester: RequesterResponse;
9481
}
9582

96-
export class GetMatchingsResponse {
83+
export class CreateMatchingResponse {
84+
@ApiProperty({ example: 1, description: '매칭 ID' })
85+
id: number;
86+
9787
@ApiProperty({
98-
description: '매칭 존재 여부',
99-
example: true,
88+
description: '매칭 요청 메시지',
89+
example: '안녕하세요! 매칭 요청합니다.',
10090
})
101-
hasMatching: boolean;
91+
message: string;
92+
93+
@ApiProperty({ example: 1, description: '채팅방 아이디' })
94+
chatRoomId?: number;
10295

10396
@ApiProperty({
104-
description: '받은 매칭 수',
105-
example: 10,
97+
example: '2024-10-11T09:00:00.000Z',
98+
description: '신청 시각',
10699
})
107-
matchingsCount: number;
100+
createdAt: string;
101+
102+
@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
103+
targetId: number;
108104

105+
@ApiProperty({
106+
description: '매칭 요청자 정보',
107+
type: RequesterResponse,
108+
})
109+
@Type(() => RequesterResponse)
110+
requester: RequesterResponse;
111+
}
112+
113+
export class GetMatchingsResponse {
109114
@ApiProperty({
110115
description: '매칭 정보',
111-
type: [Matching],
116+
type: [MatchingResponse],
117+
})
118+
@Type(() => MatchingResponse)
119+
matching: MatchingResponse[];
120+
}
121+
122+
export class GetOneMatchingResponse extends OmitType(PatchMatchingResponse, [
123+
'chatRoomId',
124+
] as const) {
125+
@ApiProperty({
126+
example: '2024-10-11T09:00:00.000Z',
127+
description: '신청 시각',
112128
})
113-
@Type(() => Matching)
114-
matching: Matching[];
129+
createdAt: string;
130+
}
131+
132+
export interface MatchingRequest {
133+
id: number;
134+
message: string;
135+
createdAt: string;
136+
requestStatus: MatchingRequestStatusEnum;
137+
chatRoomId: number;
138+
targetId: number;
139+
requester: {
140+
id: number;
141+
nickname: string;
142+
profilePictureUrl: string;
143+
representativePost?: {
144+
postImages: { url: string; orderNum: number }[];
145+
styleTags: string[];
146+
};
147+
};
115148
}

src/matching/matching.controller.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from './matching.swagger';
2020
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
2121
import {
22-
CreateMatchingReqeust,
22+
CreateMatchingRequest,
2323
PatchMatchingRequest,
2424
} from './dto/matching.request';
2525
import { UserService } from 'src/user/user.service';
@@ -31,9 +31,9 @@ import {
3131
} from 'src/common/exception/service.exception';
3232
import { BaseResponse } from 'src/common/response/dto';
3333
import {
34-
GetMatchingsResponse,
3534
PatchMatchingResponse,
3635
CreateMatchingResponse,
36+
GetMatchingsResponse,
3737
} from './dto/matching.response';
3838
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
3939
import { PostService } from 'src/post/post.service';
@@ -58,7 +58,7 @@ export class MatchingController {
5858
@CreateMatchingSwagger('매칭 생성 API')
5959
async createMatching(
6060
@Req() req: Request,
61-
@Body() body: CreateMatchingReqeust,
61+
@Body() body: CreateMatchingRequest,
6262
): Promise<BaseResponse<CreateMatchingResponse>> {
6363
if (req.user.id !== body.requesterId)
6464
throw UnauthorizedException('권한이 없습니다.');
@@ -82,13 +82,8 @@ export class MatchingController {
8282
)
8383
throw InvalidInputValueException('이미 매칭 요청을 보냈습니다.');
8484

85-
const chatRoom = await this.matchingService.createMatching(body);
86-
return new BaseResponse<CreateMatchingResponse>(true, 'SUCCESS', {
87-
id: chatRoom.matching.id,
88-
chatRoomId: chatRoom.id,
89-
targetId: chatRoom.toUser.id,
90-
requesterId: chatRoom.fromUser.id,
91-
});
85+
await this.matchingService.createMatching(body);
86+
return new BaseResponse<CreateMatchingResponse>(true, 'SUCCESS');
9287
}
9388

9489
@Patch(':matchingId')

src/matching/matching.module.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ChatMessageModule } from 'src/chat-message/chat-message.module';
77
import { ChatRoomModule } from 'src/chat-room/chat-room.module';
88
import { UserModule } from 'src/user/user.module';
99
import { PostModule } from 'src/post/post.module';
10-
import { UserBlock } from 'src/common/entities/user-block.entity';
1110
import { UserBlockModule } from 'src/user-block/user-block.module';
1211

1312
@Module({

0 commit comments

Comments
 (0)