Skip to content

Commit

Permalink
feat: add find books use case
Browse files Browse the repository at this point in the history
  • Loading branch information
joseandrestrujillo committed Nov 22, 2023
1 parent c02982e commit 51ea75f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/core/book/application/find-books.use-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Books from '@/core/book/domain/services/book.repository'

import { FindBookResponse } from './types'

export default class FindBooksUseCase {
constructor(private readonly booksRepository: Books) {}

async with(): Promise<FindBookResponse[]> {
const books = await this.booksRepository.findAll()

return books.map((book) => ({
authors: book.authors,
id: book.id,
image: book.image,
title: book.tittle,
}))
}
}
3 changes: 3 additions & 0 deletions src/core/book/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ export interface FindBookResponse {
image: string
title: string
}
export class FindBooksCommand {
constructor() {}
}
2 changes: 1 addition & 1 deletion src/core/book/domain/services/book.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Book from '@/core/book/domain/model/book.entity'

export default interface Books {
// Finds a user by email
findAll(): Promise<Book[] | null>
findAll(): Promise<Book[]>

// Saves a user
save(user: Book): Promise<void>
Expand Down

0 comments on commit 51ea75f

Please sign in to comment.