Skip to content

Commit 52f99dc

Browse files
committed
feat: merge from dev
2 parents e9bad16 + 17618d6 commit 52f99dc

28 files changed

+285
-206
lines changed

src/auth/auth.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class AuthService {
1515
user: SocialUser,
1616
provider: 'kakao' | 'naver',
1717
): Promise<string> {
18-
console.log(user);
1918
let userBySocial;
2019
if (provider === 'kakao')
2120
userBySocial = await this.userSerivce.getUserByKaKaoId(user.kakaoId);

src/auth/strategies/kakao.strategy.ts

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class JwtKakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
3535
done: (error: any, user?: SocialUser, info?: any) => void,
3636
) {
3737
try {
38-
console.log('profile', profile);
3938
const { _json } = profile;
4039
const kakaoUser: SocialUser = {
4140
kakaoId: _json.id,

src/auth/strategies/naver.strategy.ts

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class NaverStrategy extends PassportStrategy(Strategy, 'naver') {
3636
): Promise<any> {
3737
try {
3838
const { _json } = profile;
39-
console.log('profile', profile);
4039
const naverUser: SocialUser = {
4140
naverId: _json.id,
4241
email: _json.email,

src/clothing/clothing.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Injectable } from '@nestjs/common';
22
import { InjectRepository } from '@nestjs/typeorm';
33
import { QueryRunner, Repository } from 'typeorm';
44
import { Clothing } from 'src/common/entities/clothing.entity';
5-
import { UploadClothingDto } from 'src/post/dtos/post.request';
5+
import { UploadClothingDto } from 'src/post/dto/request/post.request';
66
import { DataNotFoundException } from 'src/common/exception/service.exception';
7-
import { PatchClothingDto } from 'src/post/dtos/post.request';
7+
import { PatchClothingDto } from 'src/post/dto/request/post.request';
88

99
@Injectable()
1010
export class ClothingService {

src/common/entities/matching.entity.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BaseEntity } from './base.entity';
33
import { User } from './user.entity';
44
import { ChatRoom } from './chat-room.entity';
55
import { ApiProperty } from '@nestjs/swagger';
6+
import { MatchingRequestStatusEnum } from '../enum/matchingRequestStatus';
67

78
@Entity('Matching')
89
export class Matching extends BaseEntity {
@@ -23,13 +24,13 @@ export class Matching extends BaseEntity {
2324
})
2425
message!: string;
2526

26-
@Column({ type: 'enum', enum: ['pending', 'accepted', 'rejected'] })
27+
@Column({ type: 'enum', enum: MatchingRequestStatusEnum })
2728
@ApiProperty({
28-
enum: ['pending', 'accepted', 'rejected'],
29+
enum: MatchingRequestStatusEnum,
2930
description: '매칭 상태',
3031
example: 'pending',
3132
})
32-
requestStatus: 'pending' | 'accepted' | 'rejected' = 'pending';
33+
requestStatus: MatchingRequestStatusEnum = MatchingRequestStatusEnum.PENDING;
3334

3435
@Column({ type: 'datetime', nullable: true })
3536
rejectedAt: Date = null;

src/common/entities/post.entity.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PostLike } from './post-like.entity';
77
import { PostStyletag } from './post-styletag.entity';
88
import { PostClothing } from './post-clothing.entity';
99
import { PostReport } from './post-report.entity';
10-
1110
@Entity('Post')
1211
export class Post extends BaseEntity {
1312
@ManyToOne(() => User, (user) => user.posts)
@@ -38,15 +37,16 @@ export class Post extends BaseEntity {
3837

3938
@OneToMany(() => PostReport, (postReport) => postReport.post)
4039
postReports!: PostReport[];
41-
images: string[];
40+
41+
images: string[];
4242

4343
// 댓글 수
4444
get commentCount(): number {
45-
return this.postComments? this.postComments.length : 0;
45+
return this.postComments ? this.postComments.length : 0;
4646
}
4747

4848
// Like 수
4949
get likeCount(): number {
50-
return this.postLikes? this.postLikes.length : 0;
50+
return this.postLikes ? this.postLikes.length : 0;
5151
}
5252
}

src/common/entities/user.entity.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export class User extends BaseEntity {
8585
sentChatMessages?: ChatMessage[];
8686

8787
@OneToMany(() => Matching, (matching) => matching.requester)
88-
requestedMatchings?: Matching[];
88+
requestedMatchings: Matching[];
8989

9090
@OneToMany(() => Matching, (matching) => matching.target)
91-
targetedMatchings?: Matching[];
91+
targetedMatchings: Matching[];
9292

9393
@OneToMany(() => PostLike, (postLike) => postLike.user)
9494
postLikes!: PostLike[];
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum MatchingRequestStatusEnum {
2+
PENDING = 'pending',
3+
ACCEPTED = 'accepted',
4+
REJECTED = 'rejected',
5+
}

src/common/response/page.dto.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { IsArray } from 'class-validator';
22
import { PageMetaDto } from './page-meta.dto';
33
import { ApiProperty } from '@nestjs/swagger';
4-
import { GetAllPostsResponse } from '../../post/dtos/all-posts.response';
4+
import { GetAllPostsResponse } from '../../post/dto/all-posts.response';
55
import {
66
GetMyPostsResponse,
77
GetOtherPostsResponse,
8-
} from '../../post/dtos/user-posts.response';
8+
} from '../../post/dto/user-posts.response';
99

1010
export class PageDto<T> {
1111
@ApiProperty({

src/matching/matching.controller.ts

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export class MatchingController {
7575
throw DataNotFoundException('신청 유저의 게시물이 존재하지 않습니다.');
7676
}
7777

78+
if (
79+
await this.matchingService.getMatchingByUserId(
80+
body.requesterId,
81+
body.targetId,
82+
)
83+
)
84+
throw InvalidInputValueException('이미 매칭 요청을 보냈습니다.');
85+
7886
const chatRoom = await this.matchingService.createMatching(body);
7987
return new BaseResponse<PostMatchingResponse>(true, 'SUCCESS', {
8088
chatRoomId: chatRoom.id,

src/matching/matching.service.ts

+34-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ChatMessageService } from 'src/chat-message/chat-message.service';
1414
import { ChatRoom } from 'src/common/entities/chat-room.entity';
1515
import { InjectRepository } from '@nestjs/typeorm';
1616
import { GetMatchingsResponse } from './dto/matching.response';
17+
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
1718

1819
@Injectable()
1920
export class MatchingService {
@@ -24,6 +25,35 @@ export class MatchingService {
2425
private readonly chatMessageService: ChatMessageService,
2526
private readonly dataSource: DataSource,
2627
) {}
28+
async getMatchingByUserId(
29+
requesterId: number,
30+
targetId: number,
31+
): Promise<Matching> {
32+
return await this.matchingRepository.findOne({
33+
where: [
34+
{
35+
requester: { id: requesterId },
36+
target: { id: targetId },
37+
status: 'activated',
38+
},
39+
{
40+
requester: { id: targetId },
41+
target: { id: requesterId },
42+
status: 'activated',
43+
},
44+
],
45+
});
46+
}
47+
48+
async getMatchingsByCurrentId(currentUserId: number): Promise<Matching[]> {
49+
return await this.matchingRepository.find({
50+
relations: ['requester', 'target'],
51+
where: [
52+
{ requester: { id: currentUserId }, status: 'activated' },
53+
{ target: { id: currentUserId }, status: 'activated' },
54+
],
55+
});
56+
}
2757

2858
async createMatching(body: CreateMatchingReqeust): Promise<ChatRoom> {
2959
let matching, chatRoom;
@@ -68,10 +98,10 @@ export class MatchingService {
6898

6999
try {
70100
if (body.requestStatus === 'accept') {
71-
matching.requestStatus = 'accepted';
101+
matching.requestStatus = MatchingRequestStatusEnum.ACCEPTED;
72102
matching.acceptedAt = new Date();
73103
} else if (body.requestStatus === 'reject') {
74-
matching.requestStatus = 'rejected';
104+
matching.requestStatus = MatchingRequestStatusEnum.REJECTED;
75105
matching.rejectedAt = new Date();
76106
}
77107

@@ -157,13 +187,13 @@ export class MatchingService {
157187
{
158188
requester: { id: requesterId },
159189
target: { id: targetId },
160-
requestStatus: 'accepted',
190+
requestStatus: MatchingRequestStatusEnum.ACCEPTED,
161191
status: 'activated',
162192
},
163193
{
164194
requester: { id: targetId },
165195
target: { id: requesterId },
166-
requestStatus: 'accepted',
196+
requestStatus: MatchingRequestStatusEnum.ACCEPTED,
167197
status: 'activated',
168198
},
169199
],

src/post-clothing/post-clothing.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ClothingService } from 'src/clothing/clothing.service';
44
import { Clothing } from 'src/common/entities/clothing.entity';
55
import { PostClothing } from 'src/common/entities/post-clothing.entity';
66
import { Post } from 'src/common/entities/post.entity';
7-
import { UploadClothingDto } from 'src/post/dtos/post.request';
8-
import { PatchClothingDto } from 'src/post/dtos/post.request';
7+
import { UploadClothingDto } from 'src/post/dto/request/post.request';
8+
import { PatchClothingDto } from 'src/post/dto/request/post.request';
99
import { QueryRunner, Repository } from 'typeorm';
1010

1111
@Injectable()

src/post-comment/post-comment.controller.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import {
1818
import { CreateCommentDto } from './dtos/create-comment.dto';
1919
import { Request } from 'express';
2020
import { BaseResponse } from 'src/common/response/dto';
21-
import { PostService } from 'src/post/post.service';
2221
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
2322
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
2423
import { PostComment } from 'src/common/entities/post-comment.entity';
2524
import { GetCommentsDto } from './dtos/get-comment.dto';
2625
import dayjs from 'dayjs';
26+
import { UserBlockService } from 'src/user-block/user-block.service';
2727

2828
@ApiBearerAuth('Authorization')
2929
@Controller('post-comment')
@@ -32,7 +32,7 @@ import dayjs from 'dayjs';
3232
export class PostCommentController {
3333
constructor(
3434
private readonly postCommentService: PostCommentService,
35-
private readonly postService: PostService,
35+
private readonly userBlockService: UserBlockService,
3636
) {}
3737

3838
@Post()
@@ -61,7 +61,13 @@ export class PostCommentController {
6161
): Promise<BaseResponse<GetCommentsDto>> {
6262
const currentUserId = req.user.id;
6363

64-
const comments = await this.postCommentService.getPostComments(postId);
64+
const blockedUserIds: number[] =
65+
await this.userBlockService.getBlockedUserIds(currentUserId);
66+
67+
const comments = await this.postCommentService.getPostComments(
68+
postId,
69+
blockedUserIds,
70+
);
6571

6672
const commenteResponse: GetCommentsDto = {
6773
comments: comments.map((comment) => ({

src/post-comment/post-comment.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { TypeOrmModule } from '@nestjs/typeorm';
55
import { PostComment } from 'src/common/entities/post-comment.entity';
66
import { PostModule } from 'src/post/post.module';
77
import { UserModule } from 'src/user/user.module';
8+
import { UserBlockModule } from 'src/user-block/user-block.module';
89

910
@Module({
1011
imports: [
1112
TypeOrmModule.forFeature([PostComment]),
1213
forwardRef(() => UserModule),
1314
forwardRef(() => PostModule),
15+
UserBlockModule,
1416
],
1517
controllers: [PostCommentController],
1618
providers: [PostCommentService],

src/post-comment/post-comment.service.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forwardRef, Inject, Injectable } from '@nestjs/common';
22
import { PostComment } from 'src/common/entities/post-comment.entity';
3-
import { QueryRunner } from 'typeorm';
3+
import { In, Not, QueryRunner } from 'typeorm';
44
import { InjectRepository } from '@nestjs/typeorm';
55
import { Repository } from 'typeorm';
66
import { CreateCommentDto } from './dtos/create-comment.dto';
@@ -85,16 +85,27 @@ export class PostCommentService {
8585
}
8686

8787
// 댓글 리스트 조회
88-
async getPostComments(postId: number): Promise<PostComment[]> {
88+
async getPostComments(
89+
postId: number,
90+
blockedUserIds: number[],
91+
): Promise<PostComment[]> {
8992
return await this.postCommentRepository.find({
90-
where: { post: { id: postId }, status: 'activated' },
93+
where: {
94+
post: { id: postId },
95+
status: 'activated',
96+
user: { status: 'activated', id: Not(In(blockedUserIds)) },
97+
},
9198
relations: ['user'],
9299
});
93100
}
94101

95102
private async findCommentById(commentId: number): Promise<PostComment> {
96103
const comment = await this.postCommentRepository.findOne({
97-
where: { id: commentId, status: 'activated' },
104+
where: {
105+
id: commentId,
106+
status: 'activated',
107+
user: { status: 'activated' },
108+
},
98109
relations: ['user'],
99110
});
100111

src/post-image/post-image.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
33
import { PostImage } from 'src/common/entities/post-image.entity';
44
import { Repository, QueryRunner } from 'typeorm';
55
import { Post } from 'src/common/entities/post.entity';
6-
import { UploadImageDto } from 'src/post/dtos/post.request';
6+
import { UploadImageDto } from 'src/post/dto/request/post.request';
77
import { InvalidInputValueException } from 'src/common/exception/service.exception';
88

99
@Injectable()

src/post/dto/all-posts.response.ts

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import dayjs from 'dayjs';
3+
import { GetAllPostDto, UserDto } from './dto/get-all-posts.dto';
4+
import { MatchingRequestStatusEnum } from '../../common/enum/matchingRequestStatus';
5+
import { Matching } from 'src/common/entities/matching.entity';
6+
7+
export class PostDto extends GetAllPostDto {
8+
@ApiProperty({
9+
description: '게시글에 좋아요 눌렀는지 여부입니다.',
10+
example: true,
11+
})
12+
isPostLike: boolean;
13+
14+
@ApiProperty({
15+
required: false,
16+
enum: MatchingRequestStatusEnum,
17+
description: '매칭 요청 상태입니다.',
18+
})
19+
requestStatus?: MatchingRequestStatusEnum | null;
20+
21+
constructor(
22+
post: GetAllPostDto,
23+
currentUserId: number,
24+
requestStatus?: MatchingRequestStatusEnum | null,
25+
) {
26+
super();
27+
this.id = post.id;
28+
this.content = post.content;
29+
this.createdAt = dayjs(post.createdAt).format('YYYY-MM-DDTHH:mm:ssZ');
30+
this.postImages = post.postImages ?? [];
31+
this.isPostLike =
32+
post.postLikesUserIds?.some((like) => like === currentUserId) || false;
33+
this.requestStatus = requestStatus;
34+
this.user = new UserDto(post.user);
35+
}
36+
}
37+
38+
export class GetAllPostsResponse {
39+
@ApiProperty({
40+
type: [PostDto],
41+
description: '조회된 게시글 목록입니다.',
42+
})
43+
post: PostDto[];
44+
45+
constructor(
46+
posts: GetAllPostDto[],
47+
currentUserId: number,
48+
matchings?: Matching[],
49+
) {
50+
this.post = posts.map((post) => {
51+
const matching = matchings?.find(
52+
(matching) =>
53+
matching.requester.id === post.user.id ||
54+
matching.target.id === post.user.id,
55+
);
56+
return new PostDto(post, currentUserId, matching?.requestStatus ?? null);
57+
});
58+
}
59+
}

0 commit comments

Comments
 (0)