swager documentation

This commit is contained in:
vigdorov
2020-07-02 21:56:52 +03:00
parent 4d34b4a0bb
commit a65e3cd53c
4 changed files with 43 additions and 10 deletions

View File

@ -1,6 +1,7 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import {StoreService} from './store.service';
import {Store, StoreParams} from './store.schema';
import {Store, StoreResponse, StoreRequest} from './store.schema';
import {ApiResponse} from '@nestjs/swagger';
@Controller('store')
export class StoreController {
@ -9,17 +10,32 @@ export class StoreController {
) {}
@Get()
@ApiResponse({
status: 200,
description: 'Список всех пар ключ-значение',
type: [StoreResponse],
})
async findAll(): Promise<Store[]> {
return this.storeService.findAll();
}
@Get(':key?')
@ApiResponse({
status: 200,
description: 'Возвращает пару ключ-значение по ключу',
type: StoreResponse,
})
async findOne(@Param() {key}: {key: string}): Promise<Store> {
return this.storeService.findOne(key);
}
@Post()
async create(@Body() createStoreClass: StoreParams): Promise<Store> {
@ApiResponse({
status: 200,
description: 'Создает новую пару ключ-значение или заменяет существующую по ключу',
type: StoreResponse,
})
async create(@Body() createStoreClass: StoreRequest): Promise<Store> {
return this.storeService.create(createStoreClass);
}
}