浏览代码

move controllers to interfaces

Richard Köhl 2 年之前
父节点
当前提交
b04dc0db60

+ 4 - 10
deno.jsonc

@@ -3,6 +3,7 @@
     "app/": "./src/application/",
     "domain/": "./src/domain/",
     "infra/": "./src/infrastructure/",
+    "if/": "./src/interfaces/",
     "std/": "https://deno.land/std@0.191.0/"
   },
   "tasks": {
@@ -11,21 +12,14 @@
   },
   "lint": {
     "files": {
-      "include": [
-        "src/"
-      ]
+      "include": ["src/"]
     },
     "rules": {
-      "tags": [
-        "recommended"
-      ]
+      "tags": ["recommended"]
     }
   },
   "fmt": {
-    "include": [
-      "src/",
-      "test/"
-    ],
+    "include": ["src/", "test/"],
     "useTabs": false,
     "lineWidth": 80,
     "indentWidth": 2,

+ 0 - 4
src/application/controllers/index.ts

@@ -1,4 +0,0 @@
-import rootController from 'app/controllers/root.controller.ts';
-import notFoundController from 'app/controllers/not-found.controller.ts';
-
-export default [rootController, notFoundController];

+ 0 - 7
src/application/controllers/not-found.controller.ts

@@ -1,7 +0,0 @@
-export default {
-  path: '*',
-  method: '*',
-  handler: (_req: Request) => {
-    return new Response('Not Found', { status: 404 });
-  },
-};

+ 0 - 8
src/application/controllers/root.controller.ts

@@ -1,8 +0,0 @@
-export default {
-  path: '/',
-  method: 'GET',
-  handler: (_req: Request) => {
-    const body = new TextEncoder().encode(Deno.env.get('GREETING'));
-    return new Response(body);
-  },
-};

+ 0 - 0
src/application/.gitkeep → src/application/services/.gitkeep


+ 0 - 0
src/domain/entities/.gitkeep → src/domain/models/entities/.gitkeep


+ 0 - 0
src/domain/value_objects/.gitkeep → src/domain/models/value_objects/.gitkeep


+ 7 - 0
src/interfaces/controllers/controller.class.ts

@@ -0,0 +1,7 @@
+export default class Controller {
+  constructor(
+    public path: string,
+    public method: string,
+    public handler: (req: Request) => Response | Promise<Response>,
+  ) {}
+}

+ 4 - 0
src/interfaces/controllers/index.ts

@@ -0,0 +1,4 @@
+import rootController from 'if/controllers/root.controller.ts';
+import notFoundController from 'if/controllers/not-found.controller.ts';
+
+export default [rootController, notFoundController];

+ 9 - 0
src/interfaces/controllers/not-found.controller.ts

@@ -0,0 +1,9 @@
+import Controller from 'if/controllers/controller.class.ts';
+
+export default new Controller(
+  '*',
+  '*',
+  (_req: Request) => {
+    return new Response('Not Found', { status: 404 });
+  },
+);

+ 10 - 0
src/interfaces/controllers/root.controller.ts

@@ -0,0 +1,10 @@
+import Controller from 'if/controllers/controller.class.ts';
+
+export default new Controller(
+  '/',
+  'GET',
+  (_req: Request) => {
+    const body = new TextEncoder().encode(Deno.env.get('GREETING'));
+    return new Response(body);
+  },
+);

+ 1 - 1
src/application/router.ts → src/interfaces/router.ts

@@ -1,4 +1,4 @@
-import controllers from './controllers/index.ts';
+import controllers from 'if/controllers/index.ts';
 
 export const router = (req: Request) => {
   const url = new URL(req.url);

+ 1 - 1
src/main.ts

@@ -1,5 +1,5 @@
 import { serve } from './deps.ts';
-import { router } from 'app/router.ts';
+import { router } from 'if/router.ts';
 
 if (import.meta.main) {
   serve(router, { port: 1993 });