From 1d7b0e1d8dc132332a36ce1a9f6d5c99b2308027 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sat, 7 Jul 2018 19:33:06 +0300 Subject: [PATCH] services vs controllers refactoring --- server/src/config.ts | 2 +- .../{alerts_service.ts => alerts_controller.ts} | 8 ++++---- .../{analytics_service.ts => analytics_controller.ts} | 6 +++--- .../src/controllers/{metrics.ts => metrics_controler.ts} | 2 +- .../controllers/{segments.ts => segments_controller.ts} | 2 +- server/src/index.ts | 2 +- server/src/models/analytic_unit.ts | 2 +- server/src/routes/alerts_router.ts | 2 +- server/src/routes/analytic_units_router.ts | 4 ++-- server/src/routes/segments_router.ts | 4 ++-- .../analytics_service.ts} | 0 .../src/{controllers/data.ts => services/data_service.ts} | 0 .../src/{controllers/json.ts => services/json_service.ts} | 0 .../src/{controllers => services}/notification_service.ts | 0 14 files changed, 17 insertions(+), 17 deletions(-) rename server/src/controllers/{alerts_service.ts => alerts_controller.ts} (85%) rename server/src/controllers/{analytics_service.ts => analytics_controller.ts} (94%) rename server/src/controllers/{metrics.ts => metrics_controler.ts} (89%) rename server/src/controllers/{segments.ts => segments_controller.ts} (95%) rename server/src/{controllers/analytics_connection.ts => services/analytics_service.ts} (100%) rename server/src/{controllers/data.ts => services/data_service.ts} (100%) rename server/src/{controllers/json.ts => services/json_service.ts} (100%) rename server/src/{controllers => services}/notification_service.ts (100%) diff --git a/server/src/config.ts b/server/src/config.ts index 126f4c7..ccd731b 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import * as fs from 'fs'; -import { getJsonDataSync } from './controllers/json'; +import { getJsonDataSync } from './services/json_service'; let configFile = path.join(__dirname, '../../config.json'); diff --git a/server/src/controllers/alerts_service.ts b/server/src/controllers/alerts_controller.ts similarity index 85% rename from server/src/controllers/alerts_service.ts rename to server/src/controllers/alerts_controller.ts index d5c3390..e3ce0cd 100644 --- a/server/src/controllers/alerts_service.ts +++ b/server/src/controllers/alerts_controller.ts @@ -1,8 +1,8 @@ -import { getJsonDataSync, writeJsonDataSync } from './json'; +import { getJsonDataSync, writeJsonDataSync } from '../services/json_service'; import { AnalyticUnitId } from '../models/analytic_unit'; -import { runPredict } from './analytics_service'; -import { sendNotification } from './notification_service'; -import { getLabeledSegments } from './segments'; +import { runPredict } from './analytics_controller'; +import { sendNotification } from '../services/notification_service'; +import { getLabeledSegments } from './segments_controller'; import { ANALYTIC_UNITS_PATH } from '../config'; diff --git a/server/src/controllers/analytics_service.ts b/server/src/controllers/analytics_controller.ts similarity index 94% rename from server/src/controllers/analytics_service.ts rename to server/src/controllers/analytics_controller.ts index 2da99ef..56a72ed 100644 --- a/server/src/controllers/analytics_service.ts +++ b/server/src/controllers/analytics_controller.ts @@ -5,9 +5,9 @@ import { setPredictionTime, setStatus } from '../models/analytic_unit' -import { getTarget } from './metrics'; -import { getLabeledSegments, insertSegments, removeSegments } from './segments' -import { AnalyticsConnection } from './analytics_connection' +import { getTarget } from './metrics_controler'; +import { getLabeledSegments, insertSegments, removeSegments } from './segments_controller' +import { AnalyticsConnection } from '../services/analytics_service' const taskMap = {}; diff --git a/server/src/controllers/metrics.ts b/server/src/controllers/metrics_controler.ts similarity index 89% rename from server/src/controllers/metrics.ts rename to server/src/controllers/metrics_controler.ts index 5bbe72b..7cf5d45 100644 --- a/server/src/controllers/metrics.ts +++ b/server/src/controllers/metrics_controler.ts @@ -1,4 +1,4 @@ -import { getJsonDataSync, writeJsonDataSync } from './json'; +import { getJsonDataSync, writeJsonDataSync } from '../services/json_service'; import { METRICS_PATH } from '../config'; import * as crypto from 'crypto'; diff --git a/server/src/controllers/segments.ts b/server/src/controllers/segments_controller.ts similarity index 95% rename from server/src/controllers/segments.ts rename to server/src/controllers/segments_controller.ts index dccf5a5..358b0b7 100644 --- a/server/src/controllers/segments.ts +++ b/server/src/controllers/segments_controller.ts @@ -1,4 +1,4 @@ -import { getJsonDataSync, writeJsonDataSync } from './json'; +import { getJsonDataSync, writeJsonDataSync } from '../services/json_service'; import { AnalyticUnitId, findById, save } from '../models/analytic_unit'; import { SEGMENTS_PATH } from '../config'; diff --git a/server/src/index.ts b/server/src/index.ts index 8d2e146..4599d4f 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -2,7 +2,7 @@ import { router as anomaliesRouter } from './routes/analytic_units_router'; import { router as segmentsRouter } from './routes/segments_router'; import { router as alertsRouter } from './routes/alerts_router'; -import * as Data from './controllers/data'; +import * as Data from './services/data_service'; import { HASTIC_PORT } from './config'; diff --git a/server/src/models/analytic_unit.ts b/server/src/models/analytic_unit.ts index 6ce2472..d4d3ef5 100644 --- a/server/src/models/analytic_unit.ts +++ b/server/src/models/analytic_unit.ts @@ -1,4 +1,4 @@ -import { getJsonDataSync, writeJsonDataSync } from '../controllers/json' +import { getJsonDataSync, writeJsonDataSync } from '../services/json_service' import { ANALYTIC_UNITS_PATH } from '../config' import * as crypto from 'crypto'; diff --git a/server/src/routes/alerts_router.ts b/server/src/routes/alerts_router.ts index 036f454..ca4d27a 100644 --- a/server/src/routes/alerts_router.ts +++ b/server/src/routes/alerts_router.ts @@ -1,5 +1,5 @@ import * as AnalyticUnit from '../models/analytic_unit'; -import { getAlertsAnomalies, saveAlertsAnomalies } from '../controllers/alerts_service'; +import { getAlertsAnomalies, saveAlertsAnomalies } from '../controllers/alerts_controller'; import * as Router from 'koa-router'; diff --git a/server/src/routes/analytic_units_router.ts b/server/src/routes/analytic_units_router.ts index fc8c1ca..84d3e76 100644 --- a/server/src/routes/analytic_units_router.ts +++ b/server/src/routes/analytic_units_router.ts @@ -2,8 +2,8 @@ import * as Router from 'koa-router'; import * as AnalyticUnit from '../models/analytic_unit'; -import { runLearning } from '../controllers/analytics_service' -import { saveTargets } from '../controllers/metrics'; +import { runLearning } from '../controllers/analytics_controller' +import { saveTargets } from '../controllers/metrics_controler'; async function sendStatus(ctx: Router.IRouterContext) { try { diff --git a/server/src/routes/segments_router.ts b/server/src/routes/segments_router.ts index 25c3111..16308db 100644 --- a/server/src/routes/segments_router.ts +++ b/server/src/routes/segments_router.ts @@ -4,10 +4,10 @@ import { getLabeledSegments, insertSegments, removeSegments, -} from '../controllers/segments'; +} from '../controllers/segments_controller'; import { AnalyticUnitId } from '../models/analytic_unit'; -import { runLearning } from '../controllers/analytics_service'; +import { runLearning } from '../controllers/analytics_controller'; async function sendSegments(ctx: Router.IRouterContext) { diff --git a/server/src/controllers/analytics_connection.ts b/server/src/services/analytics_service.ts similarity index 100% rename from server/src/controllers/analytics_connection.ts rename to server/src/services/analytics_service.ts diff --git a/server/src/controllers/data.ts b/server/src/services/data_service.ts similarity index 100% rename from server/src/controllers/data.ts rename to server/src/services/data_service.ts diff --git a/server/src/controllers/json.ts b/server/src/services/json_service.ts similarity index 100% rename from server/src/controllers/json.ts rename to server/src/services/json_service.ts diff --git a/server/src/controllers/notification_service.ts b/server/src/services/notification_service.ts similarity index 100% rename from server/src/controllers/notification_service.ts rename to server/src/services/notification_service.ts