From 8efa9ead5caad5b38f1f8314e7147a3d8357f1cb Mon Sep 17 00:00:00 2001 From: Johnny Saymon Date: Sat, 27 Jun 2020 18:43:40 -0300 Subject: [PATCH 1/2] Adding a simple router --- README.md | 4 ++-- app/Views/error404.html | 11 +++++++++++ app/Views/form.html | 16 ++++++++++++++++ app/server.ts | 28 +++++++++++++++++++++++----- 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 app/Views/error404.html create mode 100644 app/Views/form.html diff --git a/README.md b/README.md index 7cfb3ef..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/) @@ -15,4 +15,4 @@ sudo docker-compose up -d www Access: http://localhost:8000 ## Tests -sudo docker-compose run tests \ No newline at end of file +sudo docker-compose run tests 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 }) } From fa0a404a2639779c7c3e1add3059eb5ec77d2a0e Mon Sep 17 00:00:00 2001 From: Johnny Saymon Date: Mon, 6 Jul 2020 10:15:44 -0300 Subject: [PATCH 2/2] Basic interactor for Task create --- app/Interactors/Tasks/Create/Create.ts | 8 +++++ app/Interactors/Tasks/Create/Input.ts | 7 +++++ app/Interactors/Tasks/Create/UseCase.ts | 39 +++++++++++++++++++++++++ app/Interactors/Tasks/DataAccess.ts | 8 +++++ app/Interactors/Tasks/Repository.ts | 8 +++++ 5 files changed, 70 insertions(+) create mode 100644 app/Interactors/Tasks/Create/Create.ts create mode 100644 app/Interactors/Tasks/Create/Input.ts create mode 100644 app/Interactors/Tasks/Create/UseCase.ts create mode 100644 app/Interactors/Tasks/DataAccess.ts create mode 100644 app/Interactors/Tasks/Repository.ts 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