Skip to content

Commit

Permalink
feat: add Id and Title value object
Browse files Browse the repository at this point in the history
  • Loading branch information
Salsedini committed Nov 22, 2023
1 parent 51ea75f commit 3cc2098
Show file tree
Hide file tree
Showing 8 changed files with 27,399 additions and 2,189 deletions.
25,240 changes: 25,240 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react-hot-toast": "^2.4.1",
"server-only": "^0.0.1",
"sharp": "^0.32.6",
"uuid": "^9.0.1",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -61,6 +62,7 @@
"@types/nodemailer": "^6.4.14",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"autoprefixer": "^10.4.16",
Expand Down
12 changes: 9 additions & 3 deletions src/core/book/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export interface FindBookResponse {
image: string
title: string
}
export class FindBooksCommand {
constructor() {}
}

export class CreateBookCommand {
constructor(
public readonly id: string,
public readonly title: string,
public readonly authors: string[],
public readonly image: string,
) {}
}
13 changes: 13 additions & 0 deletions src/core/book/domain/model/book_Id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { v4 as uuid } from 'uuid'

export default class BookId {
constructor(public readonly value: string) {}

static generate(): BookId {
return new BookId(uuid())
}

public static with(id: string): BookId {
return new BookId(id)
}
}
14 changes: 14 additions & 0 deletions src/core/book/domain/model/book_title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class BookTitle {
constructor(public readonly value: string) {}

public static with(title: string): BookTitle {
if (title === undefined) {
throw Error('Title can not be undefined')
}
if (title.length < 3) {
throw Error('Title is too short')
}

return new BookTitle(title)
}
}
4 changes: 4 additions & 0 deletions src/core/book/domain/services/books.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default interface Books {
// Saves a user
//save(book: Book): Promise<void>
}
13 changes: 13 additions & 0 deletions src/core/book/infraestructure/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
export async function createBook(
title:string,
authors:string[],
image:string,
):
Promise<void>{
const id = BookId.generate();
const result = await container.createBook.with(new CreateBookCommand(id.value,title,authors,image));
}
*/
4,290 changes: 2,104 additions & 2,186 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 3cc2098

Please sign in to comment.