Created
September 16, 2024 19:26
-
-
Save PCreations/e1fdc05030fe159c79d798bdf91b66a5 to your computer and use it in GitHub Desktop.
773446c2c89c.diff
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
-0,0 +1,47 @@ | |
+import * as elements from 'typed-html'; | |
+import { Body, Controller, Get, Post } from '@nestjs/common'; | |
+import { AddBookUseCase } from './add-book.usecase'; | |
+import { Layout } from './components/layout'; | |
+import { AddBookForm } from './components/add-book-form'; | |
+ | |
+@Controller() | |
+export class AppController { | |
+ constructor(private readonly addBookUseCase: AddBookUseCase) {} | |
+ | |
+ @Get() | |
+ index(): string { | |
+ return ( | |
+ <Layout> | |
+ <AddBookForm inputPlaceholder="Enter book title" /> | |
+ </Layout> | |
+ ); | |
+ } | |
+ | |
+ @Post() | |
+ async addBook(@Body() body: { title: string }) { | |
+ try { | |
+ await this.addBookUseCase.execute({ title: body.title }); | |
+ return ( | |
+ <AddBookForm | |
+ inputPlaceholder="Enter book title" | |
+ toast={{ | |
+ type: 'success', | |
+ title: 'Book added', | |
+ message: 'The book has been added to the list', | |
+ }} | |
+ /> | |
+ ); | |
+ } catch (error) { | |
+ return ( | |
+ <AddBookForm | |
+ inputPlaceholder="Enter book title" | |
+ toast={{ | |
+ type: 'error', | |
+ title: 'Book not added', | |
+ message: (error as any).message, | |
+ }} | |
+ /> | |
+ ); | |
+ } | |
+ } | |
+} | |
diff --git a/src/components/add-book-form.tsx b/src/components/add-book-form.tsx | |
new file mode 100644 | |
index 0000000..65b2765 | |
--- /dev/null | |
+++ b/src/components/add-book-form.tsx | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment