Files
storage-service/src/store/store.controller.ts
2020-07-03 21:27:18 +03:00

46 lines
1.4 KiB
TypeScript

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