Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧼 clean: μ½”λ“œ 일관성 ν–₯상 #11

Merged
merged 8 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
8 changes: 4 additions & 4 deletions feed-crawler/src/repository/feed.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}개의 ν”Όλ“œ 데이터가 μ„±κ³΅μ μœΌλ‘œ λ°μ΄ν„°λ² μ΄μŠ€μ— μ‚½μž…λ˜μ—ˆμŠ΅λ‹ˆλ‹€.`,
Expand Down
1 change: 0 additions & 1 deletion server/src/admin/controller/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 μž…λ‹ˆλ‹€.');
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/admin/dto/request/login-admin.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiProperty } from '@nestjs/swagger';

export class LoginAdminRequestDto {
@ApiProperty({
example: 'minseokjo',
example: 'test',
description: 'κ΄€λ¦¬μž 둜그인 아이디λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@IsNotEmpty({
Expand All @@ -15,7 +15,7 @@ export class LoginAdminRequestDto {
loginId: string;

@ApiProperty({
example: 'heisgoat123!',
example: 'test1234!',
description: 'νŒ¨μŠ€μ›Œλ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@IsNotEmpty({
Expand Down
4 changes: 2 additions & 2 deletions server/src/admin/dto/request/register-admin.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const PASSWORD_REG = /^(?=.*[!@#$%^&*()_+])[A-Za-z0-9!@#$%^&*()_+]+$/;

export class RegisterAdminRequestDto {
@ApiProperty({
example: 'minseokjo',
example: 'test',
description: 'κ΄€λ¦¬μž 둜그인 아이디λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@IsString({
Expand All @@ -17,7 +17,7 @@ export class RegisterAdminRequestDto {
loginId: string;

@ApiProperty({
example: 'heisgoat123!',
example: 'test1234!',
description:
'νŒ¨μŠ€μ›Œλ“œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”. (μ΅œμ†Œ 6자, 영문/숫자/특수문자둜 μ΄λ£¨μ–΄μ§ˆ 수 있으며 특수문자 1개 이상 포함)',
})
Expand Down
4 changes: 2 additions & 2 deletions server/src/feed/api-docs/searchFeedList.api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function ApiSearchFeedList() {
required: true,
type: String,
description: '검색어',
example: 'λ°λ‚˜λ¬΄',
example: 'test',
}),
ApiQuery({
name: 'type',
Expand Down Expand Up @@ -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',
},
Expand Down
8 changes: 0 additions & 8 deletions server/src/feed/api-docs/updateFeedViewCount.api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ import {
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
} from '@nestjs/swagger';

export function ApiUpdateFeedViewCount() {
return applyDecorators(
ApiOperation({
summary: `ν”Όλ“œ 쑰회수 μ—…λ°μ΄νŠΈ API`,
}),
ApiParam({
name: 'feedId',
required: true,
type: Number,
description: 'ν΄λ¦­ν•œ ν”Όλ“œμ˜ id',
example: 1,
}),
ApiOkResponse({
description: 'Ok',
schema: {
Expand Down
28 changes: 13 additions & 15 deletions server/src/feed/controller/feed.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -38,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(
'ν”Όλ“œ 쑰회 μ™„λ£Œ',
Expand Down Expand Up @@ -81,27 +78,28 @@ 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) {
const data = await this.feedService.searchFeedList(searchFeedReq);
return ApiResponse.responseWithData('검색 κ²°κ³Ό 쑰회 μ™„λ£Œ', data);
return ApiResponse.responseWithData(
'검색 κ²°κ³Ό 쑰회 μ™„λ£Œ',
await this.feedService.searchFeedList(searchFeedReq),
);
}

@ApiUpdateFeedViewCount()
@Post('/:feedId')
@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(
'μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μ²˜λ¦¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
);
Expand Down
15 changes: 15 additions & 0 deletions server/src/feed/dto/request/feed-update.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsInt } from 'class-validator';

export class FeedViewUpdateRequestDto {
@ApiProperty({
example: 1,
description: 'μ‘°νšŒν•  ID μž…λ ₯',
})
@IsInt({
message: 'μ •μˆ˜λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@Type(() => Number)
feedId: number;
}
8 changes: 6 additions & 2 deletions server/src/feed/dto/response/feed-pagination.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
20 changes: 12 additions & 8 deletions server/src/feed/service/feed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 };
},
Expand Down
7 changes: 2 additions & 5 deletions server/src/rss/controller/rss.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Get,
HttpCode,
Param,
ParseIntPipe,
Post,
UsePipes,
ValidationPipe,
Expand Down Expand Up @@ -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('승인이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.');
}

Expand All @@ -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('거절이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.');
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/rss/dto/request/rss-register.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class RssRegisterRequestDto {
blog: string;

@ApiProperty({
example: 'J235_쑰민석',
example: 'test',
description: 'μ‹€λͺ…을 μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@Length(2, 50, { message: '이름 길이가 μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.' })
Expand All @@ -29,7 +29,7 @@ export class RssRegisterRequestDto {
name: string;

@ApiProperty({
example: 'seok3765@naver.com',
example: 'test@test.com',
description: '이메일을 μž…λ ₯ν•΄μ£Όμ„Έμš”.',
})
@IsEmail(
Expand All @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions server/src/rss/service/rss.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Loading
Loading