Skip to content
Merged

Dev #87

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3a37486
매칭 신청시 소켓 업데이트
khmandarrin Feb 14, 2025
7747fe7
Merge branch 'dev' of https://github.com/oodd-team/oodd-server-nestjs…
khmandarrin Feb 14, 2025
e000c2c
userStyleTag 필드 추가
khmandarrin Feb 15, 2025
f2e37d3
Merge pull request #75 from oodd-team/OD-185
happbob Feb 16, 2025
3695db3
feat: kakao strategy 수정
happbob Feb 16, 2025
e238ff3
feat: kakao strategy 해결중
happbob Feb 16, 2025
cafa9d2
feat: kakao 고쳐
happbob Feb 16, 2025
f5cedf6
매칭 신청 소켓 생성
khmandarrin Feb 17, 2025
acc16ff
Merge pull request #76 from oodd-team/OD-184
happbob Feb 17, 2025
2d2f678
매칭 상태 변경 소켓 추가
khmandarrin Feb 18, 2025
b3a4e14
Merge pull request #77 from oodd-team/OD-189
happbob Feb 19, 2025
22662d5
최근 매칭 조회 api 기능
khmandarrin Feb 19, 2025
f5cd128
최근 매칭 조회 소켓
khmandarrin Feb 20, 2025
7b01fdb
Merge pull request #79 from oodd-team/OD-190
happbob Feb 21, 2025
7166e63
userStyletags 추가 기능
khmandarrin Feb 21, 2025
6364195
충돌 해결
khmandarrin Feb 21, 2025
69a406a
Merge pull request #80 from oodd-team/OD-195
happbob Feb 22, 2025
07782ab
매칭 소켓 수정
khmandarrin Feb 22, 2025
357cc79
Merge pull request #81 from oodd-team/OD-196
happbob Feb 23, 2025
8c72011
getUser 수정
khmandarrin Feb 24, 2025
9b2bc9d
Merge pull request #82 from oodd-team/OD-196
happbob Feb 24, 2025
d2cb72b
getUser 조건 수정
khmandarrin Feb 24, 2025
20c6be2
feat: 수정!
happbob Feb 28, 2025
a617cee
매칭 요청 이벤트 수정
khmandarrin Mar 1, 2025
65d20a6
매칭 소켓 수정
khmandarrin Mar 1, 2025
108ac79
Merge pull request #84 from oodd-team/OD-200
happbob Mar 2, 2025
f2685cc
매칭 소켓 이벤트 수정
khmandarrin Mar 3, 2025
40a25ee
Merge pull request #85 from oodd-team/OD-200
happbob Mar 10, 2025
834c49c
매칭 수정
khmandarrin Mar 10, 2025
4a20511
Merge pull request #86 from oodd-team/OD-200
happbob Mar 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,122 changes: 0 additions & 12,122 deletions package-lock.json

This file was deleted.

5 changes: 4 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { AuthModule } from './auth/auth.module';
import { DayjsModule } from './common/dayjs/dayjs.module'; // DayjsModule 추가
import { EventsGateway } from './eventGateway';
import { ConfigService } from '@nestjs/config';
import { MatchingEventsGateway } from './matchingEventGateway';
import { UserStyletagModule } from './user-styletag/user-styletag.module';

const configService: ConfigService = new ConfigService();

Expand Down Expand Up @@ -64,8 +66,9 @@ const configService: ConfigService = new ConfigService();
UserBlockModule,
UserReportModule,
AuthModule,
UserStyletagModule,
],
controllers: [AppController],
providers: [AppService, EventsGateway],
providers: [AppService, EventsGateway, MatchingEventsGateway],
})
export class AppModule {}
30 changes: 16 additions & 14 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Controller, Get, Query, Req, Res, UseGuards } from '@nestjs/common';
import {
BadRequestException,
Controller,
Get,
Query,
Req,
Res,
UseGuards,
} from '@nestjs/common';
import { UserService } from 'src/user/user.service';
import {
GetJwtInfoSwagger,
Expand All @@ -13,8 +21,6 @@ import { NaverAuthGuard } from './guards/naver.auth.guard';
import { AuthGuard } from './guards/jwt.auth.guard';
import { BaseResponse } from '../common/response/dto';
import { GetUserInfo } from 'src/user/dto/response/user.response';
import dayjs from 'dayjs';

@Controller('auth')
@ApiTags('[서비스] Auth 관련')
export class AuthController {
Expand Down Expand Up @@ -66,16 +72,12 @@ export class AuthController {
@GetJwtInfoSwagger('JWT 토큰 정보 조회 API')
@Get('/me')
async test(@Req() req: Request): Promise<BaseResponse<GetUserInfo>> {
const user = await this.userService.getUserById(req.user?.id);
return new BaseResponse<GetUserInfo>(true, 'SUCCESS', {
id: user.id,
email: user.email,
nickname: user.nickname,
profilePictureUrl: user.profilePictureUrl,
name: user.name,
phoneNumber: user.phoneNumber,
birthDate: dayjs(user.birthDate).format('YYYY-MM-DD'),
bio: user.bio,
});
console.log(req.user);
const user = await this.userService.getUserWithTag(req.user?.id);
if (!user) throw new BadRequestException('User not found');

const userInfo = new GetUserInfo(user);

return new BaseResponse<GetUserInfo>(true, 'SUCCESS', userInfo);
}
}
8 changes: 4 additions & 4 deletions src/auth/strategies/kakao.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PassportStrategy } from '@nestjs/passport';
import { Profile, Strategy } from 'passport-kakao';
import { SocialUser } from '../dto/auth.dto';
import { ConfigService } from '@nestjs/config';
import { Request } from 'express';

@Injectable()
export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
Expand All @@ -16,19 +15,20 @@ export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
});
}

async authenticate(req: Request) {
authenticate(req: any, options?: any) {
if (req.query.redirectUrl) {
// /auth
return super.authenticate(req, {
...options,
state: encodeURIComponent(req.query.redirectUrl as string),
});
}
// /auth/callback
return super.authenticate(req);
return super.authenticate(req, options);
}

async validate(
req: Request,
req: any,
accessToken: string,
refreshToken: string,
profile: Profile,
Expand Down
4 changes: 2 additions & 2 deletions src/chat-message/chat-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { ChatMessage } from 'src/common/entities/chat-message.entity';
import { ChatRoom } from 'src/common/entities/chat-room.entity';
import { StatusEnum } from 'src/common/enum/entityStatus';
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
import { CreateMatchingRequest } from 'src/matching/dto/matching.request';
import { QueryRunner, Repository } from 'typeorm';

@Injectable()
Expand Down Expand Up @@ -80,7 +80,7 @@ export class ChatMessageService {
async createChatMessage(
queryRunner: QueryRunner,
chatRoom: ChatRoom,
body: CreateMatchingReqeust,
body: CreateMatchingRequest,
): Promise<ChatMessage> {
return queryRunner.manager.save(ChatMessage, {
chatRoom: chatRoom,
Expand Down
6 changes: 4 additions & 2 deletions src/chat-room/chat-room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Matching } from 'src/common/entities/matching.entity';
import { StatusEnum } from 'src/common/enum/entityStatus';
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
import { DataNotFoundException } from 'src/common/exception/service.exception';
import { CreateMatchingReqeust } from 'src/matching/dto/matching.request';
import { CreateMatchingRequest } from 'src/matching/dto/matching.request';
import { Repository, QueryRunner } from 'typeorm';

@Injectable()
Expand Down Expand Up @@ -60,6 +60,7 @@ export class ChatRoomService {

const latestMessage =
room.chatMessages.length > 0 ? room.chatMessages[0] : null; // 가장 최근 메시지 선택

return {
id: room.id,
otherUser: otherUserInfo,
Expand All @@ -72,7 +73,7 @@ export class ChatRoomService {
async createChatRoom(
queryRunner: QueryRunner,
matching: Matching,
body: CreateMatchingReqeust,
body: CreateMatchingRequest,
): Promise<ChatRoom> {
// 채팅방 생성 로직
return await queryRunner.manager.save(ChatRoom, {
Expand Down Expand Up @@ -116,6 +117,7 @@ export class ChatRoomService {
matching: { id: matchingId },
},
relations: ['matching'],
withDeleted: true, // 소프트 딜리트된 데이터도 조회
});
}
}
4 changes: 4 additions & 0 deletions src/common/entities/styletag.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Entity, Column, OneToMany } from 'typeorm';
import { BaseEntity } from './base.entity';
import { PostStyletag } from './post-styletag.entity';
import { UserStyletag } from './user-styletag.entity';

@Entity('Styletag')
export class Styletag extends BaseEntity {
Expand All @@ -9,4 +10,7 @@ export class Styletag extends BaseEntity {

@OneToMany(() => PostStyletag, (postStyletag) => postStyletag.styletag)
postStyletags!: PostStyletag[];

@OneToMany(() => UserStyletag, (userStyletag) => userStyletag.styletag)
userStyletags!: UserStyletag[];
}
15 changes: 15 additions & 0 deletions src/common/entities/user-styletag.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Entity, JoinColumn, ManyToOne } from 'typeorm';
import { BaseEntity } from './base.entity';
import { Styletag } from './styletag.entity';
import { User } from './user.entity';

@Entity('UserStyletag')
export class UserStyletag extends BaseEntity {
@ManyToOne(() => User, (user) => user.userStyletags)
@JoinColumn({ name: 'userId' })
user!: User;

@ManyToOne(() => Styletag, (styletag) => styletag.userStyletags)
@JoinColumn({ name: 'styletagId' })
styletag!: Styletag;
}
4 changes: 4 additions & 0 deletions src/common/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PostLike } from './post-like.entity';
import { PostReport } from './post-report.entity';
import { ChatMessage } from './chat-message.entity';
import { ApiProperty } from '@nestjs/swagger';
import { UserStyletag } from './user-styletag.entity';

@Entity('User')
export class User extends BaseEntity {
Expand Down Expand Up @@ -96,6 +97,9 @@ export class User extends BaseEntity {
@OneToMany(() => PostReport, (postReport) => postReport.reporter)
postReports!: PostReport[];

@OneToMany(() => UserStyletag, (userStyletag) => userStyletag.user)
userStyletags!: UserStyletag[];

// 대표 게시물 필드 추가
@OneToOne(() => Post, (post) => post.user)
representativePost?: Post | null;
Expand Down
6 changes: 5 additions & 1 deletion src/matching/dto/matching.request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsIn, IsInt, IsString, MaxLength, MinLength } from 'class-validator';

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

export class PatchMatchingRequest {
@ApiProperty({ example: 1, description: '매칭 아이디' })
@IsInt()
id: number;

@ApiProperty({
example: 'accept',
enum: ['accept', 'reject'],
Expand Down
85 changes: 59 additions & 26 deletions src/matching/dto/matching.response.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, OmitType } from '@nestjs/swagger';
import { Type } from 'class-transformer';

export class CreateMatchingResponse {
@ApiProperty({ example: 1, description: '매칭 ID' })
id: number;

@ApiProperty({ example: 1, description: '채팅방 아이디' })
chatRoomId: number;

@ApiProperty({ example: 1, description: '신청한 유저 아이디' })
requesterId: number;

@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
targetId: number;
}
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';

export class PatchMatchingResponse {
@ApiProperty({ example: 1, description: '매칭 ID' })
Expand Down Expand Up @@ -81,7 +68,7 @@ class RequesterResponse {
representativePost?: RepresentativePost;
}

class Matching {
export class MatchingResponse {
@ApiProperty({ example: 1, description: '매칭 ID' })
id: number;

Expand All @@ -93,23 +80,69 @@ class Matching {
requester: RequesterResponse;
}

export class GetMatchingsResponse {
export class CreateMatchingResponse {
@ApiProperty({ example: 1, description: '매칭 ID' })
id: number;

@ApiProperty({
description: '매칭 존재 여부',
example: true,
description: '매칭 요청 메시지',
example: '안녕하세요! 매칭 요청합니다.',
})
hasMatching: boolean;
message: string;

@ApiProperty({ example: 1, description: '채팅방 아이디' })
chatRoomId?: number;

@ApiProperty({
description: '받은 매칭 수',
example: 10,
example: '2024-10-11T09:00:00.000Z',
description: '신청 시각',
})
matchingsCount: number;
createdAt: string;

@ApiProperty({ example: 2, description: '매칭 상대 유저 아이디' })
targetId: number;

@ApiProperty({
description: '매칭 요청자 정보',
type: RequesterResponse,
})
@Type(() => RequesterResponse)
requester: RequesterResponse;
}

export class GetMatchingsResponse {
@ApiProperty({
description: '매칭 정보',
type: [Matching],
type: [MatchingResponse],
})
@Type(() => MatchingResponse)
matching: MatchingResponse[];
}

export class GetOneMatchingResponse extends OmitType(PatchMatchingResponse, [
'chatRoomId',
] as const) {
@ApiProperty({
example: '2024-10-11T09:00:00.000Z',
description: '신청 시각',
})
@Type(() => Matching)
matching: Matching[];
createdAt: string;
}

export interface MatchingRequest {
id: number;
message: string;
createdAt: string;
requestStatus: MatchingRequestStatusEnum;
chatRoomId: number;
targetId: number;
requester: {
id: number;
nickname: string;
profilePictureUrl: string;
representativePost?: {
postImages: { url: string; orderNum: number }[];
styleTags: string[];
};
};
}
15 changes: 5 additions & 10 deletions src/matching/matching.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from './matching.swagger';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import {
CreateMatchingReqeust,
CreateMatchingRequest,
PatchMatchingRequest,
} from './dto/matching.request';
import { UserService } from 'src/user/user.service';
Expand All @@ -31,9 +31,9 @@ import {
} from 'src/common/exception/service.exception';
import { BaseResponse } from 'src/common/response/dto';
import {
GetMatchingsResponse,
PatchMatchingResponse,
CreateMatchingResponse,
GetMatchingsResponse,
} from './dto/matching.response';
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
import { PostService } from 'src/post/post.service';
Expand All @@ -58,7 +58,7 @@ export class MatchingController {
@CreateMatchingSwagger('매칭 생성 API')
async createMatching(
@Req() req: Request,
@Body() body: CreateMatchingReqeust,
@Body() body: CreateMatchingRequest,
): Promise<BaseResponse<CreateMatchingResponse>> {
if (req.user.id !== body.requesterId)
throw UnauthorizedException('권한이 없습니다.');
Expand All @@ -82,13 +82,8 @@ export class MatchingController {
)
throw InvalidInputValueException('이미 매칭 요청을 보냈습니다.');

const chatRoom = await this.matchingService.createMatching(body);
return new BaseResponse<CreateMatchingResponse>(true, 'SUCCESS', {
id: chatRoom.matching.id,
chatRoomId: chatRoom.id,
targetId: chatRoom.toUser.id,
requesterId: chatRoom.fromUser.id,
});
await this.matchingService.createMatching(body);
return new BaseResponse<CreateMatchingResponse>(true, 'SUCCESS');
}

@Patch(':matchingId')
Expand Down
1 change: 0 additions & 1 deletion src/matching/matching.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ChatMessageModule } from 'src/chat-message/chat-message.module';
import { ChatRoomModule } from 'src/chat-room/chat-room.module';
import { UserModule } from 'src/user/user.module';
import { PostModule } from 'src/post/post.module';
import { UserBlock } from 'src/common/entities/user-block.entity';
import { UserBlockModule } from 'src/user-block/user-block.module';

@Module({
Expand Down
Loading
Loading