-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: remove unnused classes * chore: added types
- Loading branch information
Showing
20 changed files
with
134 additions
and
24 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
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 @@ | ||
export default class DomainError extends Error {} |
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,25 @@ | ||
import DomainError from '@/src/shared/domain/error/DomainError'; | ||
// @ts-ignore | ||
import { v4 } from 'uuid'; | ||
|
||
class UuidIsInvalid extends DomainError { | ||
constructor(value: string) { | ||
super(`Uuid ${value} is invalid`); | ||
} | ||
} | ||
|
||
export default abstract class Uuid { | ||
readonly value: string; | ||
|
||
protected constructor(private value: string) { | ||
Uuid.ensureIsValidUuid(value); | ||
|
||
this.value = value; | ||
} | ||
|
||
private static ensureIsValidUuid(value: string) { | ||
if (!v4().validate(value)) { | ||
throw new UuidIsInvalid(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,3 @@ | ||
export default interface UuidGenerator { | ||
generate(): 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export const SYMBOLS = { | ||
TodoRepository: Symbol('TodoRepository'), | ||
TodoCreate: Symbol('TodoCreate'), | ||
TodoList: Symbol('TodoList'), | ||
TODO_REPOSITORY: Symbol('TODO_REPOSITORY'), | ||
TODO_CREATE: Symbol('TODO_CREATE'), | ||
TODO_LIST: Symbol('TODO_LIST'), | ||
STORE: Symbol('Store'), | ||
UUID_GENERATOR: Symbol('UUID_GENERATOR'), | ||
}; |
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,10 @@ | ||
import UuidGenerator from '@/src/shared/domain/uuid/UuidGenerator'; | ||
import { injectable } from 'inversify'; | ||
import { v4 } from 'uuid'; | ||
|
||
@injectable() | ||
export default class V4UuidGenerator implements UuidGenerator { | ||
generate(): string { | ||
return v4(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import CommandHandler from '@/src/shared/domain/use-case/command/CommandHandler'; | ||
import UuidGenerator from '@/src/shared/domain/uuid/UuidGenerator'; | ||
import { SYMBOLS } from '@/src/shared/infrastructure/container/Types'; | ||
import CreateCommand from '@/src/todo/application/create/CreateCommand'; | ||
import Todo from '@/src/todo/domain/Todo'; | ||
import TodoBody from '@/src/todo/domain/TodoBody'; | ||
import TodoId from '@/src/todo/domain/TodoId'; | ||
import TodoRepository from '@/src/todo/domain/TodoRepository'; | ||
import { inject, injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class Create implements CommandHandler { | ||
constructor( | ||
@inject(SYMBOLS.TodoRepository) | ||
private readonly todoRepository: TodoRepository | ||
@inject(SYMBOLS.TODO_REPOSITORY) | ||
private readonly todoRepository: TodoRepository, | ||
@inject(SYMBOLS.UUID_GENERATOR) | ||
private readonly uuidGenerator: UuidGenerator | ||
) {} | ||
|
||
dispatch(command: CreateCommand): Promise<void> { | ||
return this.todoRepository.add(command.todo); | ||
const todoId = new TodoId(this.uuidGenerator.generate()); | ||
const todoBody = new TodoBody(command.todoBody); | ||
const todo = Todo.create(todoId, todoBody); | ||
|
||
return this.todoRepository.add(todo); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Command from '@/src/shared/domain/use-case/command/Command'; | ||
|
||
export default class CreateCommand implements Command { | ||
constructor(readonly todo: string) {} | ||
constructor(readonly todoBody: 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
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,23 @@ | ||
import TodoId from '@/src/todo/domain/TodoId'; | ||
import TodoBody from '@/src/todo/domain/TodoBody'; | ||
import TodoCreatedAt from '@/src/todo/domain/TodoCreatedAt'; | ||
|
||
export default class Todo { | ||
constructor( | ||
private readonly _id: TodoId, | ||
private readonly _body: TodoBody, | ||
private readonly _createdAt: TodoCreatedAt | ||
) {} | ||
|
||
get body(): TodoBody { | ||
return this._body; | ||
} | ||
|
||
get createdAt(): TodoCreatedAt { | ||
return this._createdAt; | ||
} | ||
|
||
static create(todoId: TodoId, todoBody: TodoBody) { | ||
return new Todo(todoId, todoBody, Date.now()); | ||
} | ||
} |
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,7 @@ | ||
export default class TodoBody { | ||
constructor(private readonly _value: string) {} | ||
|
||
get value(): string { | ||
return this._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,3 @@ | ||
export default class TodoCreatedAt { | ||
constructor(value: Date) {} | ||
} |
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,7 @@ | ||
export default class TodoId { | ||
constructor(private readonly _value: string) {} | ||
|
||
get value(): string { | ||
return this._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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import Todo from '@/src/todo/domain/Todo'; | ||
|
||
export default interface TodoRepository { | ||
getAll(): string[]; | ||
add(task: string): Promise<void>; | ||
getAll(): Todo[]; | ||
add(todo: Todo): 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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import Todo from '@/src/todo/domain/Todo'; | ||
import { injectable } from 'inversify'; | ||
import TodoRepository from '@/src/todo/domain/TodoRepository'; | ||
|
||
@injectable() | ||
export class InMemoryTodoRepository implements TodoRepository { | ||
private static _todos: string[] = []; | ||
private static _todos: Todo[] = []; | ||
|
||
add(task: string): Promise<void> { | ||
InMemoryTodoRepository._todos.push(task); | ||
add(todo: Todo): Promise<void> { | ||
InMemoryTodoRepository._todos.push(todo); | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
getAll(): string[] { | ||
getAll(): Todo[] { | ||
return InMemoryTodoRepository._todos; | ||
} | ||
} |
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