diff --git a/README.md b/README.md index 87b83c1..8f9ed76 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Repository for studying architeture model and the [Deno](https://deno.land/) runtime. -## Requisitos +## Requirements - [Docker](https://docs.docker.com/install/) - [Docker Compose](https://docs.docker.com/compose/install/) diff --git a/app/Interactors/Tasks/Create/Create.ts b/app/Interactors/Tasks/Create/Create.ts new file mode 100644 index 0000000..60ddcf0 --- /dev/null +++ b/app/Interactors/Tasks/Create/Create.ts @@ -0,0 +1,8 @@ +import Input from './Input.ts' + +interface Create +{ + createTask(input: Input): Promise +} + +export default Create diff --git a/app/Interactors/Tasks/Create/Input.ts b/app/Interactors/Tasks/Create/Input.ts new file mode 100644 index 0000000..fafdde9 --- /dev/null +++ b/app/Interactors/Tasks/Create/Input.ts @@ -0,0 +1,7 @@ +interface Input +{ + title: string + description: string +} + +export default Input diff --git a/app/Interactors/Tasks/Create/UseCase.ts b/app/Interactors/Tasks/Create/UseCase.ts new file mode 100644 index 0000000..fe67f50 --- /dev/null +++ b/app/Interactors/Tasks/Create/UseCase.ts @@ -0,0 +1,39 @@ +import Input from './Input.ts' +import Create from './Create.ts' +import Task from './../../../Entities/Task.ts' +import Repository from './../Repository.ts' +import DataAccess from './../DataAccess.ts' + +export default class implements Create +{ + private repository: Repository + + public constructor(repository: Repository) + { + this.repository = repository + } + + public createTask(input: Input): Promise + { + const task = this.buildTask(input) + const dataAccess = this.convertTaskToDataAccess(task) + + return this.repository.save(dataAccess) + } + + private buildTask(input: Input): Task + { + const task = new Task(input.title) + task.setDescription(input.description) + return task + } + + private convertTaskToDataAccess(task: Task): DataAccess + { + return { + 'title': task.getTitle(), + 'description': task.getDescription(), + 'createdAt': task.getCreatedAt(), + } + } +} diff --git a/app/Interactors/Tasks/DataAccess.ts b/app/Interactors/Tasks/DataAccess.ts new file mode 100644 index 0000000..2e82f28 --- /dev/null +++ b/app/Interactors/Tasks/DataAccess.ts @@ -0,0 +1,8 @@ +interface DataAccess +{ + title: String + description: String + createdAt: Date +} + +export default DataAccess diff --git a/app/Interactors/Tasks/Repository.ts b/app/Interactors/Tasks/Repository.ts new file mode 100644 index 0000000..17cd0b8 --- /dev/null +++ b/app/Interactors/Tasks/Repository.ts @@ -0,0 +1,8 @@ +import DataAccess from './DataAccess.ts' + +interface Repository +{ + save(data: DataAccess): Promise +} + +export default Repository diff --git a/app/Views/error404.html b/app/Views/error404.html new file mode 100644 index 0000000..4ac9dcc --- /dev/null +++ b/app/Views/error404.html @@ -0,0 +1,11 @@ + + + + + + Error 404 + + +

Error 404

+ + diff --git a/app/Views/form.html b/app/Views/form.html new file mode 100644 index 0000000..95f3373 --- /dev/null +++ b/app/Views/form.html @@ -0,0 +1,16 @@ + + + + + + Tasks + + +

Tasks

+

Create

+
+ + +
+ + diff --git a/app/server.ts b/app/server.ts index 055e821..5a5b22e 100644 --- a/app/server.ts +++ b/app/server.ts @@ -1,4 +1,4 @@ -import { serve } from 'https://deno.land/std/http/server.ts' +import { serve, ServerRequest } from 'https://deno.land/std/http/server.ts' import { readFileStr } from "https://deno.land/std/fs/mod.ts"; const server = serve({port: 80}) @@ -6,9 +6,27 @@ console.log('Server start') for await (const request of server) { - readFileStr('./Views/index.html').then((html: string) => { - request.respond({ - body: html - }) + let fileRead: Promise + + switch(request.url){ + case '/': + fileRead = readFileStr('./Views/index.html') + break + case '/create/': + fileRead = readFileStr('./Views/form.html') + break + default: + fileRead = readFileStr('./Views/error404.html') + } + + fileRead.then((fileContent: string) => { + response(request, fileContent) + }) +} + +function response(request: ServerRequest, body: string): void +{ + request.respond({ + body: body }) }