Created
April 15, 2021 18:48
-
-
Save saeedhajinasiri/a15ac1dc9146db2dacf2829135d6b22a to your computer and use it in GitHub Desktop.
This file contains 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 characters
import { Controller, Get, Param, Post, Body, Query, Delete } from '@nestjs/common'; | |
import { BooksService } from './books.service'; | |
import { CreateBookDTO } from './dto/create-book.dto'; | |
@Controller('books') | |
export class BooksController { | |
constructor(private booksService: BooksService) { } | |
@Get() | |
async getBooks() { | |
const books = await this.booksService.getBooks(); | |
return books; | |
} | |
@Get(':bookID') | |
async getBook(@Param('bookID') bookID) { | |
const book = await this.booksService.getBook(bookID); | |
return book; | |
} | |
@Post() | |
async addBook(@Body() createBookDTO: CreateBookDTO) { | |
const book = await this.booksService.addBook(createBookDTO); | |
return book; | |
} | |
@Delete() | |
async deleteBook(@Query() query) { | |
const books = await this.booksService.deleteBook(query.bookID); | |
return books; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment