src/application/controller/papers.controller.ts
papers
/papers/ route controller
Methods |
getByContext | ||||
getByContext(query)
|
||||
Decorators :
@ApiOperation({summary: 'Finds papers by context based on the query.'})
|
||||
Request handler for: GET /papers/search
Parameters :
Returns :
object
a response with a set of matching papers |
getByID | ||||||
getByID(uuid: string)
|
||||||
Decorators :
@ApiOperation({summary: 'Finds paper by its UUID.'})
|
||||||
Request handler for GET /papers/{uuid}
Parameters :
Returns :
object
a response with a requested object |
import { Controller, Get, HttpCode, HttpException, Next, Param, ParseUUIDPipe, Put, Query, Req, Res, UseInterceptors } from "@nestjs/common";
import { SearchService } from "../../core/services/common/search.service";
import { Response } from "express";
import { PageInterceptor } from "src/core/interceptors/page.interceptor";
import { LoggerInterceptor } from "src/core/interceptors";
import { SearchResultDto } from "src/core/domain/dtos/search-result.dto";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
import { SearchQueryDto } from "src/core/domain/dtos";
/**
* /papers/ route controller
*/
@Controller('papers')
export class PapersController {
constructor(private searchService: SearchService) {}
/**
* Request handler for: GET /papers/search
* @param query
* @param response
* @returns a response with a set of matching papers
*/
@ApiOperation({ summary: 'Finds papers by context based on the query.' })
@ApiResponse({
status: 200,
description: 'Returns back acquired papers.',
type: SearchResultDto,
})
@Get('search')
@UseInterceptors(PageInterceptor)
@HttpCode(200)
getByContext(@Query() query): object {
return this.searchService.findByContext(query.query).then(
(response: SearchResultDto) => {
return response.data;
},
(error: SearchResultDto) => {
throw new HttpException(error.data, error.statusCode);
}
);
}
/**
* Request handler for GET /papers/{uuid}
* @param uuid
* @param response
* @returns a response with a requested object
*/
@ApiOperation({ summary: 'Finds paper by its UUID.' })
@ApiResponse({
status: 200,
description: 'Returns back acquired paper.',
type: SearchResultDto,
})
@Get(':uuid')
@UseInterceptors(PageInterceptor)
@HttpCode(200)
getByID(@Param('uuid', ParseUUIDPipe) uuid: string): object {
return this.searchService.findByID(uuid).then(
(response) => {
return response.data;
},
(error) => {
throw new HttpException(error.data, error.status);
}
);
}
}