Created
September 20, 2022 16:33
-
-
Save newerton/fc3bff87518b9efed6df2903f4a66d4f to your computer and use it in GitHub Desktop.
Revisions
-
newerton created this gist
Sep 20, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import { Controller, Post, Body } from '@nestjs/common'; import { CreateBookDto, CreateBookResponseDto } from '../core/dtos'; import { BookServices, BookFactoryService } from '../services/use-cases/book'; @Controller('api/book') export class BookController { constructor( private bookServices: BookServices, private bookFactoryService: BookFactoryService, ) {} @Post() async createBook(@Body() bookDto: CreateBookDto) { const createBookResponse = new CreateBookResponseDto(); try { const book = this.bookFactoryService.createNewBook(bookDto); const createdBook = await this.bookServices.createBook(book); createBookResponse.success = true; createBookResponse.createdBook = createdBook; } catch (error) { // report and log error createBookResponse.success = false; } return createBookResponse; } }