Skip to content

Commit ccb2c29

Browse files
committed
feat: 게시글 댓글 리스트 조회
1 parent b732e19 commit ccb2c29

8 files changed

+20
-22
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/post-comment/post-comment.controller.ts

+6-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,9 +61,12 @@ export class PostCommentController {
6161
): Promise<BaseResponse<GetCommentsDto>> {
6262
const currentUserId = req.user.id;
6363

64+
const blockedUserIds: number[] =
65+
await this.userBlockService.getBlockedUserIds(currentUserId);
66+
6467
const comments = await this.postCommentService.getPostComments(
6568
postId,
66-
currentUserId,
69+
blockedUserIds,
6770
);
6871

6972
const commenteResponse: GetCommentsDto = {

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

+3-3
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 { Not, 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';
@@ -87,13 +87,13 @@ export class PostCommentService {
8787
// 댓글 리스트 조회
8888
async getPostComments(
8989
postId: number,
90-
currentUserId: number,
90+
blockedUserIds: number[],
9191
): Promise<PostComment[]> {
9292
return await this.postCommentRepository.find({
9393
where: {
9494
post: { id: postId },
9595
status: 'activated',
96-
user: { status: 'activated', id: Not(currentUserId) },
96+
user: { status: 'activated', id: Not(In(blockedUserIds)) },
9797
},
9898
relations: ['user'],
9999
});

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@ export class UserBlockController {
1919
@CreateBlockUserSwagger('유저 차단하기 API')
2020
async createUserBlock(
2121
@Body() createUserBlockDto: CreateUserBlockDto,
22-
@Req() req: Request,
22+
@Req() req: Request,
2323
): Promise<BaseResponse<null>> {
24-
const fromUserId = req.user['id'];
25-
//console.log('fromUserId is ', fromUserId);
24+
const fromUserId = req.user['id'];
2625

2726
createUserBlockDto.fromUserId = fromUserId;
2827

29-
const resultCode = await this.userBlockService.createBlock(createUserBlockDto);
28+
const resultCode =
29+
await this.userBlockService.createBlock(createUserBlockDto);
3030

31-
if (resultCode === 'BLOCKED_SUCCESS') {
32-
return new BaseResponse<null>(true, 'BLOCKED_SUCCESS', null);
33-
} else if (resultCode === 'UNBLOCKED_SUCCESS') {
34-
return new BaseResponse<null>(true, 'UNBLOCKED_SUCCESS', null);
31+
if (resultCode === 'BLOCKED_SUCCESS') {
32+
return new BaseResponse<null>(true, 'BLOCKED_SUCCESS', null);
33+
} else if (resultCode === 'UNBLOCKED_SUCCESS') {
34+
return new BaseResponse<null>(true, 'UNBLOCKED_SUCCESS', null);
35+
}
3536
}
36-
3737
}
38-
}

src/user/user.controller.ts

-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class UserController {
4747
): Promise<BaseResponse<GetOtherUserInfo>> {
4848
const user = await this.userService.getUserById(userId);
4949

50-
console.log(req.user);
5150
// 현재 사용자의 ID를 가져옵니다. req.user에서 추출할 수 있습니다.
5251
const currentUserId = req.user.id; // 또는 다른 방법으로 현재 사용자 ID를 가져옴
5352

@@ -75,8 +74,6 @@ export class UserController {
7574
@Param('userId') userId: number,
7675
@Req() req: Request,
7776
): Promise<BaseResponse<null>> {
78-
//console.log("req.user['id'] is ~~~~~~~~~~~~~~~~~",typeof(req.user['id']) );
79-
//console.log("Number(userId) is ~~~~~~~~~~~~~~~~~", typeof(Number(userId)));
8077
if (req.user['id'] != Number(userId)) {
8178
throw UnauthorizedException('권한이 없습니다.');
8279
}

0 commit comments

Comments
 (0)