-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticles.controller.ts
More file actions
40 lines (34 loc) · 1.21 KB
/
Copy patharticles.controller.ts
File metadata and controls
40 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Controller, Get, NotFoundException, Param } from "@nestjs/common";
import {
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiTags,
} from "@nestjs/swagger";
import { ArticleDetailItemDto } from "./dto/article-detail-item.dto";
import { ArticleListItemDto } from "./dto/article-list-item.dto";
import { ArticlesService } from "./articles.service";
@ApiTags("articles")
@Controller("articles")
export class ArticlesController {
constructor(private readonly articlesService: ArticlesService) {}
@Get()
@ApiOperation({ operationId: "articles" })
@ApiOkResponse({ type: ArticleListItemDto, isArray: true })
async getArticles(): Promise<ArticleListItemDto[]> {
return this.articlesService.getArticles();
}
@Get(":id")
@ApiOperation({ operationId: "articleById" })
@ApiParam({ name: "id", required: true, type: String })
@ApiOkResponse({ type: ArticleDetailItemDto })
@ApiNotFoundResponse({ description: "Article not found" })
async getArticleById(@Param("id") id: string): Promise<ArticleDetailItemDto> {
const article = await this.articlesService.getArticleById(id);
if (!article) {
throw new NotFoundException("Article not found");
}
return article;
}
}