-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactor create #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Input from './Input.ts' | ||
|
||
interface Create | ||
{ | ||
createTask(input: Input): Promise<boolean> | ||
} | ||
|
||
export default Create |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface Input | ||
{ | ||
title: string | ||
description: string | ||
} | ||
|
||
export default Input |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean> | ||
{ | ||
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(), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface DataAccess | ||
{ | ||
title: String | ||
description: String | ||
createdAt: Date | ||
} | ||
|
||
export default DataAccess |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import DataAccess from './DataAccess.ts' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eu colocaria essa classe fora do diretório Interactors, em: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Você fala do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Estava falando do |
||
|
||
interface Repository | ||
{ | ||
save(data: DataAccess): Promise<boolean> | ||
} | ||
|
||
export default Repository |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Error 404</title> | ||
</head> | ||
<body> | ||
<p>Error 404</p> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="pt-BR"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Tasks</title> | ||
</head> | ||
<body> | ||
<h1>Tasks</h1> | ||
<h2>Create</h2> | ||
<form action="." method="post"> | ||
<input type="text" name="title"/> | ||
<button type="submit">Create</button> | ||
</form> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
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}) | ||
console.log('Server start') | ||
|
||
for await (const request of server) | ||
{ | ||
readFileStr('./Views/index.html').then((html: string) => { | ||
request.respond({ | ||
body: html | ||
}) | ||
let fileRead: Promise<string> | ||
|
||
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 | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O que te motivou a dar esse nome para essa interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Foi a tradução que usei para "Dados de Acesso", mas agora que você questionou, se formos tentar usar a arquitetura limpa talvez eu tenha que nomear a classe que chamei de
Repository
paraDataAccess
e dá outro nome para essa ou extinguir e trabalhar diretamente com entidades, o que acha?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu gosto da nomenclatura
Repository
, mas creio que o nome não fará diferença desde que seja semântico e sigamos um padrãoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Também acho bom, mas não considera que
DataAccess
é ainda mais abstrato?