swager documentation
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
||||||
import {StoreService} from './store.service';
|
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')
|
@Controller('store')
|
||||||
export class StoreController {
|
export class StoreController {
|
||||||
@ -9,17 +10,32 @@ export class StoreController {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Список всех пар ключ-значение',
|
||||||
|
type: [StoreResponse],
|
||||||
|
})
|
||||||
async findAll(): Promise<Store[]> {
|
async findAll(): Promise<Store[]> {
|
||||||
return this.storeService.findAll();
|
return this.storeService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':key?')
|
@Get(':key?')
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Возвращает пару ключ-значение по ключу',
|
||||||
|
type: StoreResponse,
|
||||||
|
})
|
||||||
async findOne(@Param() {key}: {key: string}): Promise<Store> {
|
async findOne(@Param() {key}: {key: string}): Promise<Store> {
|
||||||
return this.storeService.findOne(key);
|
return this.storeService.findOne(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@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);
|
return this.storeService.create(createStoreClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,27 @@
|
|||||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||||
import { Document } from 'mongoose';
|
import { Document } from 'mongoose';
|
||||||
|
import {ApiProperty} from '@nestjs/swagger';
|
||||||
|
|
||||||
export class StoreParams {
|
export class StoreRequest {
|
||||||
|
@ApiProperty()
|
||||||
key: string;
|
key: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
value: any;
|
value: any;
|
||||||
}
|
}
|
||||||
|
export class StoreResponse {
|
||||||
|
@ApiProperty()
|
||||||
|
key: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
value: any;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
_id: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
__v: number;
|
||||||
|
}
|
||||||
|
|
||||||
@Schema()
|
@Schema()
|
||||||
export class Store extends Document {
|
export class Store extends Document {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import {Model} from 'mongoose';
|
import {Model} from 'mongoose';
|
||||||
import {Injectable} from '@nestjs/common';
|
import {Injectable} from '@nestjs/common';
|
||||||
import {InjectModel} from '@nestjs/mongoose';
|
import {InjectModel} from '@nestjs/mongoose';
|
||||||
import {Store, StoreParams} from './store.schema';
|
import {Store, StoreRequest} from './store.schema';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -12,7 +12,7 @@ export class StoreService {
|
|||||||
return this.storeModel.find().exec();
|
return this.storeModel.find().exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(store: StoreParams): Promise<Store> {
|
async create(store: StoreRequest): Promise<Store> {
|
||||||
const searchStore = await this.findOne(store.key);
|
const searchStore = await this.findOne(store.key);
|
||||||
|
|
||||||
if (searchStore) {
|
if (searchStore) {
|
||||||
|
|||||||
Reference in New Issue
Block a user