-
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 lists & policy into domain model and refactor modules and a…
…pps to conform to new spec. Also decouple domain models from interactor request/response interfaces
- Loading branch information
Showing
36 changed files
with
460 additions
and
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mxfile host="Electron" modified="2021-04-25T09:23:17.868Z" agent="5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.5.1 Chrome/89.0.4389.82 Electron/12.0.1 Safari/537.36" etag="jGKru9uW8Jtk9Hhmri8f" version="14.5.1" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7Vttc9o4EP41zLQ3Q8cvQMjHAHm5HtejJWnaj8IWRo1scbYIkF/flS1jG9lgqCENZYaZWGt5Le3z7Eq7Vmpm113c+mg6+ZfZmNYMzV7UzF7NMHS93YI/QrKMJC1NjwSOT2zZKREMyQuWQk1KZ8TGQaYjZ4xyMs0KLeZ52OIZGfJ9Ns92GzOafesUOVgRDC1EVekjsfkkkraNi0R+h4kzid+sty6jOy6KO8uZBBNks3lKZF7XzK7PGI+u3EUXU2G82C6Pfy8faf+pdfvxc/A/euj8c//paz1SdrPLI6sp+Njje6t+eRrf3H1t/Pg2Hdx8nmu3V6OPdfmI9ozoTNqrTwIu58uXsRGDOXEp8qDVGTOPD+UdMEEHUeJ4cG3B2LAPgmfscwL2v5I3OJuC1JoQavfRks3EDAKOrKe41Zkwn7yAWkThlg4CuO1zSSWjlekxFE+CWAOpjwPoM4jNoq9EfRRw2cdilKJpQEbhgEUXF/kO8TqMc+bGitjMs7EtWyucwwb32dOKOeL5kmBI0IQ18CJFRQnOLWYu5v4SuqxcTYIhHU2PeTdPaKu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4/wNzvpSwoBln2e0fXhD+TTwOYTRqfY9XD7juLdKNZWYPvRag91sq8rOXkktFQYW/8si/VuItCNhV0SD+VrjRg4Xx+8IZs2hu/SCw2ryvhwB1t13gfMV+msa/mOAbFvKLi7g+KU0fnyTZF9HD+6yu5lzq0niCYNW1D22j0cqi9Yvh9whoKWBtOIx0Piq7/t1tS9WkOOaXPirbKFtEaWtbafXGT8qqgcVFC/GBOFCY+taz/Aord8Vu/1t8lMsd3vnYXPWglv7c1tgZVGgm/yoSeXvyDzfm9U8=</diagram></mxfile> |
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,93 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "fbfcbd94-f3ab-4fb0-bcb4-d0134177a3d7", | ||
"name": "clean-arch-todos", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "ListTodos", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/lists/{{listName}}/todos?limit={{limit}}", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"lists", | ||
"{{listName}}", | ||
"todos" | ||
], | ||
"query": [ | ||
{ | ||
"key": "limit", | ||
"value": "{{limit}}" | ||
}, | ||
{ | ||
"key": "marker", | ||
"value": "3060961b-6afc-466b-9032-715ea52dc199", | ||
"disabled": true | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "CreateTodo", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"description\": \"{{description}}\",\n \"start\": \"{{due}}\",\n \"end\": \"{{due}}\"\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{url}}/lists/{{listName}}/todos", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"lists", | ||
"{{listName}}", | ||
"todos" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "DeleteTodo", | ||
"request": { | ||
"method": "DELETE", | ||
"header": [], | ||
"url": { | ||
"raw": "{{url}}/lists/{{listName}}/todos/:id", | ||
"host": [ | ||
"{{url}}" | ||
], | ||
"path": [ | ||
"lists", | ||
"{{listName}}", | ||
"todos", | ||
":id" | ||
], | ||
"variable": [ | ||
{ | ||
"key": "id", | ||
"value": "3060961b-6afc-466b-9032-715ea52dc199" | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
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
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
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,4 @@ | ||
export default { | ||
host: String(process.env.HOST), | ||
port: Number(process.env.PORT) | ||
} |
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,8 +1,11 @@ | ||
export interface ReadableGateway<T> { | ||
find(query: any): Promise<T[]>; | ||
count(query: any): Promise<number>; | ||
} | ||
|
||
export interface WritableGateway<T> { | ||
save(item: T): Promise<T>; | ||
delete(id: string): Promise<T>; | ||
delete(list: string, id: string): Promise<T>; | ||
} | ||
|
||
export interface Gateway<T> extends ReadableGateway<T>, WritableGateway<T> {} |
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,3 @@ | ||
describe("[ListPolicy] Test Cases", () => { | ||
xit("should create a list policy successfully", () => {}) | ||
}) |
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 List from "./list"; | ||
|
||
export default class ListPolicy { | ||
constructor(private maxTodos: number = 10) {} | ||
|
||
public isAllowedToAdd(list: List): boolean { | ||
return this.maxTodos > list.getSize(); | ||
} | ||
} |
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 @@ | ||
describe("[List] Test Cases", () => { | ||
xit("should create a list successfully", () => {}) | ||
}) |
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,28 @@ | ||
import ListPolicy from "./list-policy"; | ||
import Todo from "./todo"; | ||
|
||
export default class List { | ||
|
||
constructor( | ||
public readonly name: string, | ||
private size: number = 0, | ||
private policy: ListPolicy = new ListPolicy(10), | ||
) {} | ||
|
||
add(todo: Todo) { | ||
if (!this.policy.isAllowedToAdd(this)) throw new Error("ListError: List has maximum number of allowed todos"); | ||
if (todo.isExpired) throw new Error("ListError: Can't add an expired todo to list"); | ||
|
||
// TODO: find a way to persist the todos w/o detailing method | ||
this.size += 1; | ||
} | ||
|
||
remove(todo: Todo) { | ||
// TODO: implement | ||
this.size -= 1; | ||
} | ||
|
||
getSize(): number { | ||
return this.size; | ||
} | ||
} |
Oops, something went wrong.