-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add book model and title, image value object
- Loading branch information
1 parent
5a0c2f9
commit aab517e
Showing
8 changed files
with
118 additions
and
70 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface FindBookResponse { | ||
authors: string[] | ||
id: string | ||
image: string | ||
title: string | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Image from '@/core/book/domain/model/image.value-object' | ||
import Tittle from '@/core/book/domain/model/tittle.value-object' | ||
|
||
export default class Book { | ||
constructor( | ||
private _id: string, | ||
private _tittle: Tittle, | ||
private _authors: string[], | ||
private _image: Image, | ||
) {} | ||
|
||
static create( | ||
id: string, | ||
authors: string[], | ||
tittle: string, | ||
image: string, | ||
): Book { | ||
const tittleObj = Tittle.create(tittle) | ||
const imageObj = Image.create(image) | ||
|
||
return new Book(id, tittleObj, authors, imageObj) | ||
} | ||
|
||
get id(): string { | ||
return this._id | ||
} | ||
|
||
get tittle(): string { | ||
return this._tittle.value | ||
} | ||
|
||
set tittle(tittle: string) { | ||
this._tittle = Tittle.create(tittle) | ||
} | ||
|
||
get authors(): string[] { | ||
return this._authors.map((author) => author) | ||
} | ||
|
||
get image(): string { | ||
return this._image.value | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default class Image { | ||
constructor(public readonly value: string) {} | ||
|
||
static create(name: string): Image { | ||
if (!name.trim()) { | ||
return new Image('') | ||
} | ||
|
||
try { | ||
new URL(name) | ||
} catch (error) { | ||
throw new Error('Invalid URL') | ||
} | ||
|
||
return new Image(name) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default class Name { | ||
constructor(public readonly value: string) {} | ||
|
||
static create(name: string): Name { | ||
const trimmedName = name.trim() | ||
|
||
if (!trimmedName) { | ||
throw new Error('Name cannot be empty') | ||
} | ||
|
||
return new Name(trimmedName) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import User from '@/core/user/domain/model/user.entity' | ||
|
||
export default interface Users { | ||
// Finds a user by email | ||
findByEmail(email: string): Promise<User | null> | ||
|
||
// Saves a user | ||
save(user: User): Promise<void> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { FindBookResponse } from '../application/types' | ||
|
||
export async function findBooks(): Promise<FindBookResponse[] | null> { | ||
return null | ||
} |
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