From 5940945b9446644e6ecaed94114b166780683c76 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 16:19:40 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20data=20=EB=B3=80=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=ED=95=98=EC=97=AC=20=EC=9D=BC=EA=B4=80=EC=84=B1=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/feed/controller/feed.controller.ts | 6 ++++-- .../controller/statistic.controller.ts | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/src/feed/controller/feed.controller.ts b/server/src/feed/controller/feed.controller.ts index 3ef169b..e58c0ac 100644 --- a/server/src/feed/controller/feed.controller.ts +++ b/server/src/feed/controller/feed.controller.ts @@ -88,8 +88,10 @@ export class FeedController { new ValidationPipe(), ) async searchFeedList(@Query() searchFeedReq: SearchFeedRequestDto) { - const data = await this.feedService.searchFeedList(searchFeedReq); - return ApiResponse.responseWithData('검색 결과 조회 완료', data); + return ApiResponse.responseWithData( + '검색 결과 조회 완료', + await this.feedService.searchFeedList(searchFeedReq), + ); } @ApiUpdateFeedViewCount() diff --git a/server/src/statistic/controller/statistic.controller.ts b/server/src/statistic/controller/statistic.controller.ts index 394a77c..6a931c8 100644 --- a/server/src/statistic/controller/statistic.controller.ts +++ b/server/src/statistic/controller/statistic.controller.ts @@ -25,8 +25,10 @@ export class StatisticController { }), ) async readTodayStatistic(@Query() queryObj: StatisticRequestDto) { - const data = await this.statisticService.readTodayStatistic(queryObj.limit); - return ApiResponse.responseWithData('금일 조회수 통계 조회 완료', data); + return ApiResponse.responseWithData( + '금일 조회수 통계 조회 완료', + await this.statisticService.readTodayStatistic(queryObj.limit), + ); } @ApiStatistic('all') @@ -37,14 +39,18 @@ export class StatisticController { }), ) async readAllStatistic(@Query() queryObj: StatisticRequestDto) { - const data = await this.statisticService.readAllStatistic(queryObj.limit); - return ApiResponse.responseWithData('전체 조회수 통계 조회 완료', data); + return ApiResponse.responseWithData( + '전체 조회수 통계 조회 완료', + await this.statisticService.readAllStatistic(queryObj.limit), + ); } @ApiReadPlatformStatistic() @Get('platform') async readPlatformStatistic() { - const data = await this.statisticService.readPlatformStatistic(); - return ApiResponse.responseWithData('블로그 플랫폼 통계 조회 완료', data); + return ApiResponse.responseWithData( + '블로그 플랫폼 통계 조회 완료', + await this.statisticService.readPlatformStatistic(), + ); } } From e919d38c38c5531b88ba90e294617d441084d81c Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 16:48:27 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20feed=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=88=98=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20API=20DTO=20=EB=B3=80=EA=B2=BD,=20Swagger=20example?= =?UTF-8?q?=20DTO=20=EC=9C=84=EC=9E=84=20(=EA=B0=92=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EC=95=88=EC=A0=95=EC=84=B1=20=ED=96=A5=EC=83=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-docs/updateFeedViewCount.api-docs.ts | 8 -------- server/src/feed/controller/feed.controller.ts | 9 +++++++-- server/src/feed/dto/request/feed-update.dto.ts | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 server/src/feed/dto/request/feed-update.dto.ts diff --git a/server/src/feed/api-docs/updateFeedViewCount.api-docs.ts b/server/src/feed/api-docs/updateFeedViewCount.api-docs.ts index 490a799..c475855 100644 --- a/server/src/feed/api-docs/updateFeedViewCount.api-docs.ts +++ b/server/src/feed/api-docs/updateFeedViewCount.api-docs.ts @@ -3,7 +3,6 @@ import { ApiNotFoundResponse, ApiOkResponse, ApiOperation, - ApiParam, } from '@nestjs/swagger'; export function ApiUpdateFeedViewCount() { @@ -11,13 +10,6 @@ export function ApiUpdateFeedViewCount() { ApiOperation({ summary: `피드 조회수 업데이트 API`, }), - ApiParam({ - name: 'feedId', - required: true, - type: Number, - description: '클릭한 피드의 id', - example: 1, - }), ApiOkResponse({ description: 'Ok', schema: { diff --git a/server/src/feed/controller/feed.controller.ts b/server/src/feed/controller/feed.controller.ts index e58c0ac..97750fb 100644 --- a/server/src/feed/controller/feed.controller.ts +++ b/server/src/feed/controller/feed.controller.ts @@ -26,6 +26,7 @@ import { ApiSearchFeedList } from '../api-docs/searchFeedList.api-docs'; import { ApiUpdateFeedViewCount } from '../api-docs/updateFeedViewCount.api-docs'; import { ApiReadRecentFeedList } from '../api-docs/readRecentFeedList.api-docs'; import { FeedTrendResponseDto } from '../dto/response/feed-pagination.dto'; +import { FeedViewUpdateRequestDto } from '../dto/request/feed-update.dto'; @ApiTags('Feed') @Controller('feed') @@ -99,11 +100,15 @@ export class FeedController { @HttpCode(HttpStatus.OK) @UsePipes(new ValidationPipe({ transform: true })) async updateFeedViewCount( - @Param('feedId') feedId: number, + @Param() params: FeedViewUpdateRequestDto, @Req() request: Request, @Res({ passthrough: true }) response: Response, ) { - await this.feedService.updateFeedViewCount(feedId, request, response); + await this.feedService.updateFeedViewCount( + params.feedId, + request, + response, + ); return ApiResponse.responseWithNoContent( '요청이 성공적으로 처리되었습니다.', ); diff --git a/server/src/feed/dto/request/feed-update.dto.ts b/server/src/feed/dto/request/feed-update.dto.ts new file mode 100644 index 0000000..737bcc4 --- /dev/null +++ b/server/src/feed/dto/request/feed-update.dto.ts @@ -0,0 +1,16 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { IsInt } from 'class-validator'; + +export class FeedViewUpdateRequestDto { + @ApiProperty({ + example: 10, + description: '조회할 ID 입력', + name: '게시글 ID', + }) + @IsInt({ + message: '정수를 입력해주세요.', + }) + @Type(() => Number) + feedId: number; +} From 40689c5da9837a64db46dc8373ab57784c516370 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 16:57:37 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20Validation=20=EC=A0=9C=EA=B1=B0,=20Validat?= =?UTF-8?q?ion=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/controller/admin.controller.ts | 1 - server/src/feed/controller/feed.controller.ts | 13 ++----------- .../statistic/controller/statistic.controller.ts | 12 ++---------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/server/src/admin/controller/admin.controller.ts b/server/src/admin/controller/admin.controller.ts index 580011e..952c476 100644 --- a/server/src/admin/controller/admin.controller.ts +++ b/server/src/admin/controller/admin.controller.ts @@ -72,7 +72,6 @@ export class AdminController { @Get('/sessionId') @HttpCode(HttpStatus.OK) @UseGuards(CookieAuthGuard) - @UsePipes(new ValidationPipe({ transform: true })) async readSessionIdAdmin() { return ApiResponse.responseWithNoContent('정상적인 sessionId 입니다.'); } diff --git a/server/src/feed/controller/feed.controller.ts b/server/src/feed/controller/feed.controller.ts index 97750fb..96876ca 100644 --- a/server/src/feed/controller/feed.controller.ts +++ b/server/src/feed/controller/feed.controller.ts @@ -39,11 +39,7 @@ export class FeedController { @ApiReadFeedPagination() @Get('') @HttpCode(HttpStatus.OK) - @UsePipes( - new ValidationPipe({ - transform: true, - }), - ) + @UsePipes(new ValidationPipe({ transform: true })) async readFeedPagination(@Query() queryFeedDto: FeedPaginationRequestDto) { return ApiResponse.responseWithData( '피드 조회 완료', @@ -82,12 +78,7 @@ export class FeedController { @ApiSearchFeedList() @Get('search') @HttpCode(HttpStatus.OK) - @UsePipes( - new ValidationPipe({ - transform: true, - }), - new ValidationPipe(), - ) + @UsePipes(new ValidationPipe({ transform: true })) async searchFeedList(@Query() searchFeedReq: SearchFeedRequestDto) { return ApiResponse.responseWithData( '검색 결과 조회 완료', diff --git a/server/src/statistic/controller/statistic.controller.ts b/server/src/statistic/controller/statistic.controller.ts index 6a931c8..7a0f21c 100644 --- a/server/src/statistic/controller/statistic.controller.ts +++ b/server/src/statistic/controller/statistic.controller.ts @@ -19,11 +19,7 @@ export class StatisticController { @ApiStatistic('today') @Get('today') - @UsePipes( - new ValidationPipe({ - transform: true, - }), - ) + @UsePipes(new ValidationPipe({ transform: true })) async readTodayStatistic(@Query() queryObj: StatisticRequestDto) { return ApiResponse.responseWithData( '금일 조회수 통계 조회 완료', @@ -33,11 +29,7 @@ export class StatisticController { @ApiStatistic('all') @Get('all') - @UsePipes( - new ValidationPipe({ - transform: true, - }), - ) + @UsePipes(new ValidationPipe({ transform: true })) async readAllStatistic(@Query() queryObj: StatisticRequestDto) { return ApiResponse.responseWithData( '전체 조회수 통계 조회 완료', From 11e0560c70850cc913839269d9cf9a1ce817c193 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 16:59:52 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=EC=82=AC=EC=9A=A9=EB=B2=95=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC=20(=EC=BD=94=EB=93=9C=20=EC=9D=BC=EA=B4=80=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/rss/controller/rss.controller.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/src/rss/controller/rss.controller.ts b/server/src/rss/controller/rss.controller.ts index 4dbd1db..3673eeb 100644 --- a/server/src/rss/controller/rss.controller.ts +++ b/server/src/rss/controller/rss.controller.ts @@ -4,7 +4,6 @@ import { Get, HttpCode, Param, - ParseIntPipe, Post, UsePipes, ValidationPipe, @@ -53,8 +52,7 @@ export class RssController { @Post('accept/:id') @HttpCode(201) async acceptRss(@Param() params: RssManagementRequestDto) { - const { id } = params; - await this.rssService.acceptRss(id); + await this.rssService.acceptRss(params.id); return ApiResponse.responseWithNoContent('승인이 완료되었습니다.'); } @@ -67,8 +65,7 @@ export class RssController { @Body() body: RejectRssRequestDto, @Param() params: RssManagementRequestDto, ) { - const { id } = params; - await this.rssService.rejectRss(id, body.description); + await this.rssService.rejectRss(params.id, body.description); return ApiResponse.responseWithNoContent('거절이 완료되었습니다.'); } From 6cb54eabbc40e5d167641ad102af6972f710d1d2 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 17:05:07 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20swagger=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D=20=EB=AA=BB=20=ED=95=98=EB=8A=94=20=EB=B2=84=EA=B7=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/feed/dto/request/feed-update.dto.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/feed/dto/request/feed-update.dto.ts b/server/src/feed/dto/request/feed-update.dto.ts index 737bcc4..3582a11 100644 --- a/server/src/feed/dto/request/feed-update.dto.ts +++ b/server/src/feed/dto/request/feed-update.dto.ts @@ -6,7 +6,6 @@ export class FeedViewUpdateRequestDto { @ApiProperty({ example: 10, description: '조회할 ID 입력', - name: '게시글 ID', }) @IsInt({ message: '정수를 입력해주세요.', From b218b5449a41a327a9e082604e484e403c6d867c Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 17:16:00 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=93=9D=20docs:=20swagger=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C=20Request=20=EB=8D=94=EB=AF=B8=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/dto/request/login-admin.dto.ts | 4 ++-- server/src/admin/dto/request/register-admin.dto.ts | 4 ++-- server/src/feed/api-docs/searchFeedList.api-docs.ts | 4 ++-- server/src/feed/dto/request/feed-update.dto.ts | 2 +- server/src/rss/dto/request/rss-register.dto.ts | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/src/admin/dto/request/login-admin.dto.ts b/server/src/admin/dto/request/login-admin.dto.ts index f497a26..fb9facf 100644 --- a/server/src/admin/dto/request/login-admin.dto.ts +++ b/server/src/admin/dto/request/login-admin.dto.ts @@ -3,7 +3,7 @@ import { ApiProperty } from '@nestjs/swagger'; export class LoginAdminRequestDto { @ApiProperty({ - example: 'minseokjo', + example: 'test', description: '관리자 로그인 아이디를 입력해주세요.', }) @IsNotEmpty({ @@ -15,7 +15,7 @@ export class LoginAdminRequestDto { loginId: string; @ApiProperty({ - example: 'heisgoat123!', + example: 'test1234!', description: '패스워드를 입력해주세요.', }) @IsNotEmpty({ diff --git a/server/src/admin/dto/request/register-admin.dto.ts b/server/src/admin/dto/request/register-admin.dto.ts index e981217..73c28f7 100644 --- a/server/src/admin/dto/request/register-admin.dto.ts +++ b/server/src/admin/dto/request/register-admin.dto.ts @@ -5,7 +5,7 @@ const PASSWORD_REG = /^(?=.*[!@#$%^&*()_+])[A-Za-z0-9!@#$%^&*()_+]+$/; export class RegisterAdminRequestDto { @ApiProperty({ - example: 'minseokjo', + example: 'test', description: '관리자 로그인 아이디를 입력해주세요.', }) @IsString({ @@ -17,7 +17,7 @@ export class RegisterAdminRequestDto { loginId: string; @ApiProperty({ - example: 'heisgoat123!', + example: 'test1234!', description: '패스워드를 입력해주세요. (최소 6자, 영문/숫자/특수문자로 이루어질 수 있으며 특수문자 1개 이상 포함)', }) diff --git a/server/src/feed/api-docs/searchFeedList.api-docs.ts b/server/src/feed/api-docs/searchFeedList.api-docs.ts index 287e331..c98f56c 100644 --- a/server/src/feed/api-docs/searchFeedList.api-docs.ts +++ b/server/src/feed/api-docs/searchFeedList.api-docs.ts @@ -17,7 +17,7 @@ export function ApiSearchFeedList() { required: true, type: String, description: '검색어', - example: '데나무', + example: 'test', }), ApiQuery({ name: 'type', @@ -96,7 +96,7 @@ export function ApiSearchFeedList() { { id: 1, blogName: '블로그 이름', - title: '데나무', + title: 'test', path: 'https://test.com/1', createdAt: '2024-10-27T02:08:55.000Z', }, diff --git a/server/src/feed/dto/request/feed-update.dto.ts b/server/src/feed/dto/request/feed-update.dto.ts index 3582a11..1a8d268 100644 --- a/server/src/feed/dto/request/feed-update.dto.ts +++ b/server/src/feed/dto/request/feed-update.dto.ts @@ -4,7 +4,7 @@ import { IsInt } from 'class-validator'; export class FeedViewUpdateRequestDto { @ApiProperty({ - example: 10, + example: 1, description: '조회할 ID 입력', }) @IsInt({ diff --git a/server/src/rss/dto/request/rss-register.dto.ts b/server/src/rss/dto/request/rss-register.dto.ts index 9e92cf1..a9066b8 100644 --- a/server/src/rss/dto/request/rss-register.dto.ts +++ b/server/src/rss/dto/request/rss-register.dto.ts @@ -16,7 +16,7 @@ export class RssRegisterRequestDto { blog: string; @ApiProperty({ - example: 'J235_조민석', + example: 'test', description: '실명을 입력해주세요.', }) @Length(2, 50, { message: '이름 길이가 올바르지 않습니다.' }) @@ -29,7 +29,7 @@ export class RssRegisterRequestDto { name: string; @ApiProperty({ - example: 'seok3765@naver.com', + example: 'test@test.com', description: '이메일을 입력해주세요.', }) @IsEmail( @@ -44,7 +44,7 @@ export class RssRegisterRequestDto { email: string; @ApiProperty({ - example: 'https://v2.velog.io/rss/@seok3765', + example: 'https://test.com/rss', description: 'RSS 주소를 입력해주세요.', }) @IsUrl( From 23d3a08e60c35d5a4476412b0ecca99b17ad06a3 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sat, 11 Jan 2025 18:04:05 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20result,=20item,=20d?= =?UTF-8?q?ata=20=EC=B2=98=EB=9F=BC=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=99=94=EB=90=98=EC=96=B4=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EA=B5=AC=EC=B2=B4=ED=99=94=20?= =?UTF-8?q?(=EA=B0=80=EB=8F=85=EC=84=B1=20=ED=96=A5=EC=83=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/repository/feed.repository.ts | 8 ++++---- .../feed/dto/response/feed-pagination.dto.ts | 8 ++++++-- server/src/feed/service/feed.service.ts | 20 +++++++++++-------- server/src/rss/service/rss.service.ts | 20 +++++++++---------- .../statistic/service/statistic.service.ts | 6 +++--- server/test/feed/e2e/trend.e2e-spec.ts | 8 ++++---- .../test/rss/e2e/history/accept.e2e-spec.ts | 4 +++- .../test/rss/e2e/history/reject.e2e-spec.ts | 4 +++- server/test/statistic/e2e/all.e2e-spec.ts | 4 ++-- server/test/statistic/e2e/today.e2e-spec.ts | 4 ++-- 10 files changed, 49 insertions(+), 37 deletions(-) diff --git a/feed-crawler/src/repository/feed.repository.ts b/feed-crawler/src/repository/feed.repository.ts index da2419b..094fab6 100644 --- a/feed-crawler/src/repository/feed.repository.ts +++ b/feed-crawler/src/repository/feed.repository.ts @@ -34,16 +34,16 @@ export class FeedRepository { const promiseResults = await Promise.all(insertPromises); const insertedFeeds = promiseResults - .map((result: any, index) => { - if (result) { - const insertId = result.insertId; + .map((feed: any, index) => { + if (feed) { + const insertId = feed.insertId; return { ...resultData[index], id: insertId, }; } }) - .filter((result) => result); + .filter((feed) => feed); logger.info( `[MySQL] ${insertedFeeds.length}개의 피드 데이터가 성공적으로 데이터베이스에 삽입되었습니다.`, diff --git a/server/src/feed/dto/response/feed-pagination.dto.ts b/server/src/feed/dto/response/feed-pagination.dto.ts index 3c7dff6..2bfe053 100644 --- a/server/src/feed/dto/response/feed-pagination.dto.ts +++ b/server/src/feed/dto/response/feed-pagination.dto.ts @@ -39,8 +39,12 @@ export class FeedPaginationResponseDto { private hasMore: boolean, ) {} - static toResponseDto(result: FeedResult[], lastId: number, hasMore: boolean) { - return new FeedPaginationResponseDto(result, lastId, hasMore); + static toResponseDto( + feedPagination: FeedResult[], + lastId: number, + hasMore: boolean, + ) { + return new FeedPaginationResponseDto(feedPagination, lastId, hasMore); } } diff --git a/server/src/feed/service/feed.service.ts b/server/src/feed/service/feed.service.ts index 11e9c88..daf8a70 100644 --- a/server/src/feed/service/feed.service.ts +++ b/server/src/feed/service/feed.service.ts @@ -46,8 +46,12 @@ export class FeedService { if (hasMore) feedList.pop(); const lastId = this.getLastIdFromFeedList(feedList); const newCheckFeedList = await this.checkNewFeeds(feedList); - const result = FeedResult.toResultDtoArray(newCheckFeedList); - return FeedPaginationResponseDto.toResponseDto(result, lastId, hasMore); + const feedPagination = FeedResult.toResultDtoArray(newCheckFeedList); + return FeedPaginationResponseDto.toResponseDto( + feedPagination, + lastId, + hasMore, + ); } private existNextFeed(feedList: FeedView[], limit: number) { @@ -62,8 +66,8 @@ export class FeedService { const newFeedIds = ( await this.redisService.keys(redisKeys.FEED_RECENT_ALL_KEY) ).map((key) => { - const id = key.match(/feed:recent:(\d+)/); - return parseInt(id[1]); + const feedId = key.match(/feed:recent:(\d+)/); + return parseInt(feedId[1]); }); return feedList.map((feed): FeedPaginationResult => { @@ -98,14 +102,14 @@ export class FeedService { throw new BadRequestException('검색 타입이 잘못되었습니다.'); } - const [result, totalCount] = await this.feedRepository.searchFeedList( + const [searchResult, totalCount] = await this.feedRepository.searchFeedList( find, limit, type, offset, ); - const feeds = SearchFeedResult.toResultDtoArray(result); + const feeds = SearchFeedResult.toResultDtoArray(searchResult); const totalPages = Math.ceil(totalCount / limit); return SearchFeedResponseDto.toResponseDto( @@ -195,13 +199,13 @@ export class FeedService { return []; } - const result = await this.redisService.executePipeline((pipeline) => { + const recentFeeds = await this.redisService.executePipeline((pipeline) => { for (const key of recentKeys) { pipeline.hgetall(key); } }); - let recentFeedList: FeedRecentRedis[] = result.map( + let recentFeedList: FeedRecentRedis[] = recentFeeds.map( ([, feed]: [any, FeedRecentRedis]) => { return { ...feed, isNew: true }; }, diff --git a/server/src/rss/service/rss.service.ts b/server/src/rss/service/rss.service.ts index 250d224..c5fb8c2 100644 --- a/server/src/rss/service/rss.service.ts +++ b/server/src/rss/service/rss.service.ts @@ -69,20 +69,20 @@ export class RssService { const blogPlatform = this.identifyPlatformFromRssUrl(rss.rssUrl); - const [newRssAccept, feeds] = await this.dataSource.transaction( + const [rssAccept, feeds] = await this.dataSource.transaction( async (manager) => { - const [newRssAccept] = await Promise.all([ + const [rssAccept] = await Promise.all([ manager.save(RssAccept.fromRss(rss, blogPlatform)), manager.delete(Rss, id), ]); const feeds = await this.feedCrawlerService.loadRssFeeds( - newRssAccept.rssUrl, + rssAccept.rssUrl, ); - return [newRssAccept, feeds]; + return [rssAccept, feeds]; }, ); - await this.feedCrawlerService.saveRssFeeds(feeds, newRssAccept); - this.emailService.sendMail(newRssAccept, true); + await this.feedCrawlerService.saveRssFeeds(feeds, rssAccept); + this.emailService.sendMail(rssAccept, true); } async rejectRss(id: number, description: string) { @@ -94,17 +94,17 @@ export class RssService { throw new NotFoundException('존재하지 않는 rss 입니다.'); } - const result = await this.dataSource.transaction(async (manager) => { - const [transactionResult] = await Promise.all([ + const rejectRss = await this.dataSource.transaction(async (manager) => { + const [rejectRss] = await Promise.all([ manager.remove(rss), manager.save(RssReject, { ...rss, description, }), ]); - return transactionResult; + return rejectRss; }); - this.emailService.sendMail(result, false, description); + this.emailService.sendMail(rejectRss, false, description); } async readAcceptHistory() { diff --git a/server/src/statistic/service/statistic.service.ts b/server/src/statistic/service/statistic.service.ts index 875e52b..62d62c3 100644 --- a/server/src/statistic/service/statistic.service.ts +++ b/server/src/statistic/service/statistic.service.ts @@ -23,7 +23,7 @@ export class StatisticService { limit - 1, 'WITHSCORES', ); - const result: Partial[] = []; + const todayFeedViews: Partial[] = []; for (let i = 0; i < ranking.length; i += 2) { const feedId = parseInt(ranking[i]); @@ -34,14 +34,14 @@ export class StatisticService { relations: ['blog'], }); - result.push({ + todayFeedViews.push({ id: feedData.id, title: feedData.title, viewCount: score, }); } - return StatisticTodayResponseDto.toResponseDtoArray(result); + return StatisticTodayResponseDto.toResponseDtoArray(todayFeedViews); } async readAllStatistic(limit: number) { diff --git a/server/test/feed/e2e/trend.e2e-spec.ts b/server/test/feed/e2e/trend.e2e-spec.ts index 96d2ea0..83ae3da 100644 --- a/server/test/feed/e2e/trend.e2e-spec.ts +++ b/server/test/feed/e2e/trend.e2e-spec.ts @@ -41,8 +41,8 @@ describe('SSE /api/trend/sse E2E Test', () => { es.onmessage = (event) => { try { const response = JSON.parse(event.data); - const data = response.data; - const idList = data.map((item) => item.id); + const feedList = response.data; + const idList = feedList.map((feed) => feed.id); es.close(); resolve(idList); } catch (error) { @@ -77,8 +77,8 @@ describe('SSE /api/trend/sse E2E Test', () => { es.onmessage = (event) => { try { const response = JSON.parse(event.data); - const data = response.data; - const idList = data.map((item) => item.id); + const feedList = response.data; + const idList = feedList.map((feed) => feed.id); es.close(); resolve(idList); } catch (error) { diff --git a/server/test/rss/e2e/history/accept.e2e-spec.ts b/server/test/rss/e2e/history/accept.e2e-spec.ts index 5ad55c4..2116818 100644 --- a/server/test/rss/e2e/history/accept.e2e-spec.ts +++ b/server/test/rss/e2e/history/accept.e2e-spec.ts @@ -43,6 +43,8 @@ describe('GET /api/rss/history/accept E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([2, 1]); + expect(response.body.data.map((acceptRss) => acceptRss.id)).toStrictEqual([ + 2, 1, + ]); }); }); diff --git a/server/test/rss/e2e/history/reject.e2e-spec.ts b/server/test/rss/e2e/history/reject.e2e-spec.ts index 1fdf64c..688cb56 100644 --- a/server/test/rss/e2e/history/reject.e2e-spec.ts +++ b/server/test/rss/e2e/history/reject.e2e-spec.ts @@ -43,6 +43,8 @@ describe('GET /api/rss/history/reject E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([2, 1]); + expect(response.body.data.map((rejectRss) => rejectRss.id)).toStrictEqual([ + 2, 1, + ]); }); }); diff --git a/server/test/statistic/e2e/all.e2e-spec.ts b/server/test/statistic/e2e/all.e2e-spec.ts index ac19f04..95d4910 100644 --- a/server/test/statistic/e2e/all.e2e-spec.ts +++ b/server/test/statistic/e2e/all.e2e-spec.ts @@ -31,7 +31,7 @@ describe('GET /api/statistic/all E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([2, 1]); + expect(response.body.data.map((feed) => feed.id)).toStrictEqual([2, 1]); }); it('양수를 입력하면 제한된 개수의 통계 결과를 응답한다.', async () => { // when @@ -41,6 +41,6 @@ describe('GET /api/statistic/all E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([2]); + expect(response.body.data.map((feed) => feed.id)).toStrictEqual([2]); }); }); diff --git a/server/test/statistic/e2e/today.e2e-spec.ts b/server/test/statistic/e2e/today.e2e-spec.ts index f1f645b..1cdbc8b 100644 --- a/server/test/statistic/e2e/today.e2e-spec.ts +++ b/server/test/statistic/e2e/today.e2e-spec.ts @@ -34,7 +34,7 @@ describe('GET /api/statistic/today E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([1, 2]); + expect(response.body.data.map((feed) => feed.id)).toStrictEqual([1, 2]); }); it('양수를 입력하면 제한된 개수의 통계 결과를 응답한다.', async () => { // when @@ -44,6 +44,6 @@ describe('GET /api/statistic/today E2E Test', () => { // then expect(response.status).toBe(200); - expect(response.body.data.map((item) => item.id)).toStrictEqual([1]); + expect(response.body.data.map((feed) => feed.id)).toStrictEqual([1]); }); }); From 68a339a4d9e9a42d6106dff4ed28f7a6338d6a31 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Sun, 12 Jan 2025 23:41:46 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20validation=20Pipe?= =?UTF-8?q?=20=EA=B8=80=EB=A1=9C=EB=B2=8C=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/controller/admin.controller.ts | 4 ---- server/src/feed/controller/feed.controller.ts | 5 ----- server/src/main.ts | 2 ++ server/src/rss/controller/rss.controller.ts | 5 ----- .../src/statistic/controller/statistic.controller.ts | 10 +--------- server/test/jest.setup.ts | 5 +++-- 6 files changed, 6 insertions(+), 25 deletions(-) diff --git a/server/src/admin/controller/admin.controller.ts b/server/src/admin/controller/admin.controller.ts index 952c476..f3a5fce 100644 --- a/server/src/admin/controller/admin.controller.ts +++ b/server/src/admin/controller/admin.controller.ts @@ -8,8 +8,6 @@ import { Req, Res, UseGuards, - UsePipes, - ValidationPipe, } from '@nestjs/common'; import { Request, Response } from 'express'; import { AdminService } from '../service/admin.service'; @@ -31,7 +29,6 @@ export class AdminController { @ApiLoginAdmin() @Post('/login') @HttpCode(HttpStatus.OK) - @UsePipes(ValidationPipe) async loginAdmin( @Body() loginAdminDto: LoginAdminRequestDto, @Res({ passthrough: true }) response: Response, @@ -60,7 +57,6 @@ export class AdminController { @ApiCreateAdmin() @UseGuards(CookieAuthGuard) @Post('/register') - @UsePipes(ValidationPipe) async createAdmin(@Body() registerAdminDto: RegisterAdminRequestDto) { await this.adminService.createAdmin(registerAdminDto); return ApiResponse.responseWithNoContent( diff --git a/server/src/feed/controller/feed.controller.ts b/server/src/feed/controller/feed.controller.ts index 96876ca..53e1277 100644 --- a/server/src/feed/controller/feed.controller.ts +++ b/server/src/feed/controller/feed.controller.ts @@ -11,8 +11,6 @@ import { Req, Res, Sse, - UsePipes, - ValidationPipe, } from '@nestjs/common'; import { FeedService } from '../service/feed.service'; import { FeedPaginationRequestDto } from '../dto/request/feed-pagination.dto'; @@ -39,7 +37,6 @@ export class FeedController { @ApiReadFeedPagination() @Get('') @HttpCode(HttpStatus.OK) - @UsePipes(new ValidationPipe({ transform: true })) async readFeedPagination(@Query() queryFeedDto: FeedPaginationRequestDto) { return ApiResponse.responseWithData( '피드 조회 완료', @@ -78,7 +75,6 @@ export class FeedController { @ApiSearchFeedList() @Get('search') @HttpCode(HttpStatus.OK) - @UsePipes(new ValidationPipe({ transform: true })) async searchFeedList(@Query() searchFeedReq: SearchFeedRequestDto) { return ApiResponse.responseWithData( '검색 결과 조회 완료', @@ -89,7 +85,6 @@ export class FeedController { @ApiUpdateFeedViewCount() @Post('/:feedId') @HttpCode(HttpStatus.OK) - @UsePipes(new ValidationPipe({ transform: true })) async updateFeedViewCount( @Param() params: FeedViewUpdateRequestDto, @Req() request: Request, diff --git a/server/src/main.ts b/server/src/main.ts index ca25d07..24d1df2 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -6,6 +6,7 @@ import * as cookieParser from 'cookie-parser'; import { InternalExceptionsFilter } from './common/filters/internal-exceptions.filter'; import { LoggingInterceptor } from './common/logger/logger.interceptor'; import { WinstonLoggerService } from './common/logger/logger.service'; +import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -17,6 +18,7 @@ async function bootstrap() { new InternalExceptionsFilter(logger), new HttpExceptionsFilter(), ); + app.useGlobalPipes(new ValidationPipe({ transform: true })); app.enableCors({ origin: [ 'http://localhost:5173', diff --git a/server/src/rss/controller/rss.controller.ts b/server/src/rss/controller/rss.controller.ts index 3673eeb..1ccc438 100644 --- a/server/src/rss/controller/rss.controller.ts +++ b/server/src/rss/controller/rss.controller.ts @@ -5,8 +5,6 @@ import { HttpCode, Param, Post, - UsePipes, - ValidationPipe, UseGuards, } from '@nestjs/common'; import { CookieAuthGuard } from '../../common/guard/auth.guard'; @@ -30,7 +28,6 @@ export class RssController { @ApiCreateRss() @Post() - @UsePipes(ValidationPipe) async createRss(@Body() rssRegisterDto: RssRegisterRequestDto) { await this.rssService.createRss(rssRegisterDto); return ApiResponse.responseWithNoContent('신청이 완료되었습니다.'); @@ -48,7 +45,6 @@ export class RssController { @ApiAcceptRss() @UseGuards(CookieAuthGuard) - @UsePipes(new ValidationPipe({ transform: true })) @Post('accept/:id') @HttpCode(201) async acceptRss(@Param() params: RssManagementRequestDto) { @@ -57,7 +53,6 @@ export class RssController { } @ApiRejectRss() - @UsePipes(ValidationPipe) @UseGuards(CookieAuthGuard) @Post('reject/:id') @HttpCode(201) diff --git a/server/src/statistic/controller/statistic.controller.ts b/server/src/statistic/controller/statistic.controller.ts index 7a0f21c..d1c7354 100644 --- a/server/src/statistic/controller/statistic.controller.ts +++ b/server/src/statistic/controller/statistic.controller.ts @@ -1,10 +1,4 @@ -import { - Controller, - Get, - Query, - UsePipes, - ValidationPipe, -} from '@nestjs/common'; +import { Controller, Get, Query } from '@nestjs/common'; import { StatisticService } from '../service/statistic.service'; import { ApiResponse } from '../../common/response/common.response'; import { ApiTags } from '@nestjs/swagger'; @@ -19,7 +13,6 @@ export class StatisticController { @ApiStatistic('today') @Get('today') - @UsePipes(new ValidationPipe({ transform: true })) async readTodayStatistic(@Query() queryObj: StatisticRequestDto) { return ApiResponse.responseWithData( '금일 조회수 통계 조회 완료', @@ -29,7 +22,6 @@ export class StatisticController { @ApiStatistic('all') @Get('all') - @UsePipes(new ValidationPipe({ transform: true })) async readAllStatistic(@Query() queryObj: StatisticRequestDto) { return ApiResponse.responseWithData( '전체 조회수 통계 조회 완료', diff --git a/server/test/jest.setup.ts b/server/test/jest.setup.ts index 8fbf91e..1cc43f0 100644 --- a/server/test/jest.setup.ts +++ b/server/test/jest.setup.ts @@ -1,5 +1,5 @@ -import { INestApplication } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication, ValidationPipe } from '@nestjs/common'; +import { Test } from '@nestjs/testing'; import { AppModule } from '../src/app.module'; import { WinstonLoggerService } from '../src/common/logger/logger.service'; import { InternalExceptionsFilter } from '../src/common/filters/internal-exceptions.filter'; @@ -20,6 +20,7 @@ beforeAll(async () => { new InternalExceptionsFilter(logger), new HttpExceptionsFilter(), ); + app.useGlobalPipes(new ValidationPipe({ transform: true })); await app.init(); global.testApp = app; });