Skip to content

Commit

Permalink
Merge branch 'release/3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Mar 16, 2022
2 parents 061f059 + 6ebeff8 commit dc81e99
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.2.0](https://github.com/allohamora/chepi-back/compare/v3.1.1...v3.2.0) (2022-03-16)

### Features

- add get pizza by id route ([2da9a95](https://github.com/allohamora/chepi-back/commits/2da9a95188710cf35d4c8ff570168e6c3fcc550b))

### [3.1.1](https://github.com/allohamora/chepi-back/compare/v3.1.0...v3.1.1) (2022-03-16)

### Features
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chepi-back",
"version": "3.1.1",
"version": "3.2.0",
"description": "back-end for chepi",
"author": "https://github.com/allohamora",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions src/exceptions/entity-not-found.exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NotFoundException } from '@nestjs/common';

export class EntityNotFoundException extends NotFoundException {}
19 changes: 10 additions & 9 deletions src/pizza/pizza.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Get, HttpCode, Param, Post } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get, HttpCode, Post, Query } from '@nestjs/common';
import { ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { GetPizzaByIdDto, GetPizzaByIdResultDto } from './dto/getPizzaById.dto';
import { GetPizzaResultDto, GetPizzasDto } from './dto/getPizzas.dto';
import { GetPizzasByIdsDto, GetPizzasByIdsResultDto } from './dto/getPizzasByIds.dto';
Expand All @@ -19,6 +19,14 @@ export class PizzaController {
return await this.pizzaService.getPizzas(getPizzasDto);
}

@ApiOperation({ summary: 'Get pizza by id' })
@ApiOkResponse({ description: 'Return pizza by id or null', type: GetPizzaByIdResultDto })
@ApiNotFoundResponse({ description: 'Pizza not found' })
@Get('/')
public async getPizzaById(@Query() { id }: GetPizzaByIdDto): Promise<GetPizzaByIdResultDto> {
return await this.pizzaService.getPizzaById(id);
}

@ApiOperation({ summary: 'Get pizzas by ids' })
@ApiOkResponse({
description: 'Return found pizzas by ids. For not found id return nothing',
Expand All @@ -30,13 +38,6 @@ export class PizzaController {
return await this.pizzaService.getPizzasByIds(ids);
}

@ApiOperation({ summary: 'Get pizza by id' })
@ApiOkResponse({ description: 'Return pizza by id or null', type: GetPizzaByIdResultDto })
@Get('/id/:id')
public async getPizzaById(@Param() { id }: GetPizzaByIdDto): Promise<GetPizzaByIdResultDto> {
return await this.pizzaService.getPizzaById(id);
}

@ApiOperation({ summary: 'Get pizzas stats' })
@ApiOkResponse({ description: 'Return pizzas.json stats', type: PizzasStatsResultDto })
@Get('/stats')
Expand Down
6 changes: 5 additions & 1 deletion src/pizza/pizza.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common';
import { GetPizzasDto } from './dto/getPizzas.dto';
import { Pizza } from './entities/pizza.entity';
import { ElasticsearchService } from '@nestjs/elasticsearch';
Expand Down Expand Up @@ -158,6 +158,10 @@ export class PizzaService implements OnModuleInit {

const value = hits.map(({ _source }) => _source)[0];

if (value === undefined) {
throw new NotFoundException();
}

return { value };
}

Expand Down

0 comments on commit dc81e99

Please sign in to comment.