Skip to content

Commit

Permalink
Merge pull request #80 from asn6878/feat/rss-get-api
Browse files Browse the repository at this point in the history
✨ feat: RSS 전체 조회 API 구현
  • Loading branch information
asn6878 authored Nov 14, 2024
2 parents 5d4b74d + 75bf4b9 commit bb5a26f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 55 deletions.
108 changes: 54 additions & 54 deletions server/src/rss/dto/rss-register.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString, IsUrl, Length } from 'class-validator';

export class RssRegisterDto {
@ApiProperty({
example: 'seok3765.log',
description: '블로그 이름을 입력해주세요.',
})
@IsString({
message: '문자열로 입력해주세요.',
})
@IsNotEmpty({
message: '블로그 이름이 없습니다.',
})
blog: string;
@ApiProperty({
example: 'seok3765.log',
description: '블로그 이름을 입력해주세요.',
})
@IsString({
message: '문자열로 입력해주세요.',
})
@IsNotEmpty({
message: '블로그 이름이 없습니다.',
})
blog: string;

@ApiProperty({
example: 'J235_조민석',
description: '실명을 입력해주세요.',
})
@Length(2, 50, { message: '이름 길이가 올바르지 않습니다.' })
@IsString({
message: '문자열로 입력해주세요.',
})
@IsNotEmpty({
message: '실명이 없습니다.',
})
name: string;
@ApiProperty({
example: 'J235_조민석',
description: '실명을 입력해주세요.',
})
@Length(2, 50, { message: '이름 길이가 올바르지 않습니다.' })
@IsString({
message: '문자열로 입력해주세요.',
})
@IsNotEmpty({
message: '실명이 없습니다.',
})
name: string;

@ApiProperty({
example: '[email protected]',
description: '이메일을 입력해주세요.',
})
@IsEmail(
{},
{
message: '이메일 주소 형식에 맞춰서 작성해주세요.',
},
)
@IsNotEmpty({
message: '이메일이 없습니다.',
})
email: string;
@ApiProperty({
example: '[email protected]',
description: '이메일을 입력해주세요.',
})
@IsEmail(
{},
{
message: '이메일 주소 형식에 맞춰서 작성해주세요.',
},
)
@IsNotEmpty({
message: '이메일이 없습니다.',
})
email: string;

@ApiProperty({
example: 'https://v2.velog.io/rss/@seok3765',
description: 'RSS 주소를 입력해주세요.',
})
@IsUrl(
{
require_protocol: true,
protocols: ['http', 'https'],
},
{
message: 'http, https 프로토콜과 URL 형식을 맞춰주세요.',
},
)
@IsNotEmpty({
message: 'RSS URL이 없습니다.',
})
rssURL: string;
@ApiProperty({
example: 'https://v2.velog.io/rss/@seok3765',
description: 'RSS 주소를 입력해주세요.',
})
@IsUrl(
{
require_protocol: true,
protocols: ['http', 'https'],
},
{
message: 'http, https 프로토콜과 URL 형식을 맞춰주세요.',
},
)
@IsNotEmpty({
message: 'RSS URL이 없습니다.',
})
rssURL: string;
}
20 changes: 20 additions & 0 deletions server/src/rss/rss.api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@ export function ApiPostRegisterRss() {
}),
);
}

export function ApiGetRss() {
return applyDecorators(
ApiOperation({
summary: 'RSS 전체 조회 API',
}),
ApiCreatedResponse({
description: 'OK',
schema: {
example: {
id: 1,
name: '안성윤',
userName: '성윤',
email: '[email protected]',
rssURL: 'url',
},
},
}),
);
}
14 changes: 13 additions & 1 deletion server/src/rss/rss.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
Body,
Controller,
Get,
HttpCode,
Inject,
Post,
UsePipes,
Expand All @@ -10,7 +12,7 @@ import { ApiTags } from '@nestjs/swagger';
import { RssService } from './rss.service';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { RssRegisterDto } from './dto/rss-register.dto';
import { ApiPostRegisterRss } from './rss.api-docs';
import { ApiPostRegisterRss, ApiGetRss } from './rss.api-docs';
import { Logger } from 'winston';
import { ApiResponse } from '../common/response/common.response';

Expand All @@ -31,4 +33,14 @@ export class RssController {
await this.rssService.registerRss(rssRegisterDto);
return ApiResponse.responseWithNoContent('신청이 완료되었습니다.');
}

@ApiGetRss()
@Get()
@HttpCode(200)
async getRss() {
return ApiResponse.responseWithData(
'Rss 조회 완료',
await this.rssService.getAllRss(),
);
}
}
4 changes: 4 additions & 0 deletions server/src/rss/rss.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ export class RssService {

await this.rssRepository.insertNewRss(rssRegisterDto);
}

async getAllRss() {
return await this.rssRepository.find();
}
}

0 comments on commit bb5a26f

Please sign in to comment.