Skip to content

Commit

Permalink
refactor: split database module to submodules (apitable#152)
Browse files Browse the repository at this point in the history
Submit a pull request for this project.

<!-- If you have an Issue that related to this Pull Request, you can
copy this Issue's description -->

# Why? 
<!-- 
> Related to which issue?
> Why we need this pull request?
> What is the user story for this pull request? 
-->
use multiple feature modules instead of database module
https://github.com/vikadata/vikadata/issues/2659

# What?
<!-- 
> Can you describe this feature in detail?
> Who can benefit from it? 
-->
split Database module into multiple submodules.

```mermaid
graph TD;
         Database-->Application;
        Actuator-->Application;
        Automation-->Application;
        Fusion-->Application;
        Grpc-->Application;
        User-->Application;;
        Unit-->Application;;
        Developer-->Application;;
        Shared-->Database;
        Shared-->Actuator;
        Shared-->Automation;
        Shared-->Fusion;
        Shared-->Grpc;
        Shared-->User;
        Shared-->Unit;
        Shared-->Developer;
        Attachment-->Database;
        Dashboard-->Database;
        Datasheet-->Database;
        Form-->Database;
        Mirror-->Database;
        Resource-->Database;
        Shared-->Attachment;
        Shared-->Dashboard;
        Shared-->Datasheet;
        Shared-->Form;
        Shared-->Mirror;
        Shared-->Resource;
```

# How?
<!-- 
> Do you have a simple description of how this pull request is
implemented?
-->
- [x] split Database module into multiple submodules, such as attachment
module, dashboard module, datasheet module, etc.
  • Loading branch information
Troy(FengJun) authored Jan 6, 2023
1 parent 1e10f51 commit 65edd98
Show file tree
Hide file tree
Showing 172 changed files with 1,069 additions and 484 deletions.
26 changes: 21 additions & 5 deletions packages/room-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@ graph TD;
        Automation-->Application;
        Fusion-->Application;
Grpc-->Application;
Socket-->Application;
Node-->Application;
User-->Application;
Unit-->Application;
Developer-->Application;
Attachment-->Database;
Dashboard-->Database;
Datasheet-->Database;
Form-->Database;
Mirror-->Database;
Resource-->Database;
Shared-->Attachment;
Shared-->Dashboard;
Shared-->Datasheet;
Shared-->Form;
Shared-->Mirror;
Shared-->Resource;
Shared-->Database;
Shared-->Actuator;
Shared-->automation;
Shared-->Automation;
Shared-->Fusion;
Shared-->Grpc;
Shared-->Socket;
Shared-->Node;
Shared-->User;
Shared-->Unit;
Shared-->Developer;
```
TODO(Troy): split `Database module` into multiple submodules.

`shared module` is a shared and global module that other modules depend on in default.
## Description

Expand Down
8 changes: 8 additions & 0 deletions packages/room-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import { FusionApiDynamicModule } from 'fusion/fusion-api.dynamic.module';
import { DatabaseConfigService } from 'shared/services/config/database.config.service';
import { EnvConfigModule } from 'shared/services/config/env.config.module';
import { GrpcModule } from 'grpc/grpc.module';
import { NodeModule } from 'node/node.module';
import { DeveloperModule } from 'developer/developer.module';
import { UnitModule } from 'unit/unit.module';
import { UserModule } from 'user/user.module';

@Module({
imports: [
Expand Down Expand Up @@ -75,6 +79,10 @@ import { GrpcModule } from 'grpc/grpc.module';
ActuatorModule,
FusionApiModule,
DatabaseModule,
NodeModule,
UserModule,
UnitModule,
DeveloperModule,
GrpcModule,
RobotModule,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { Body, Controller, Delete, Headers, Param, Patch, Post } from '@nestjs/common';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';
import { AutomationActionRepository } from '../repositories/automation.action.repository';
import { ActionCreateRo } from '../ros/action.create.ro';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Body, Controller, Get, Headers, Param, Patch, Post, Query } from '@nest
import { isProdMode } from 'app.environment';
import { ActionTypeCreateRo } from '../ros/action.type.create.ro';
import { TriggerTypeUpdateRo } from '../ros/trigger.type.update.ro';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';
import { RobotActionTypeBaseService } from '../services/robot.action.type.base.service';

@Controller('nest/v1/robots/action-types')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { Body, Controller, Delete, Get, Headers, Param, Patch, Post, Query } from '@nestjs/common';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';
import { AutomationRobotRepository } from '../repositories/automation.robot.repository';
import { RobotCreateRo } from '../ros/robot.create.ro';
import { AutomationService } from '../services/automation.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { isProdMode } from 'app.environment';
import { AutomationServiceCreateRo } from '../ros/service.create.ro';
import { AutomationServiceUpdateRo } from '../ros/service.update.ro';
import { AutomationService } from '../services/automation.service';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';

@Controller('nest/v1/robots/actions')
export class RobotServiceController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { Body, Controller, Headers, Param, Patch, Post } from '@nestjs/common';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';
import { AutomationTriggerRepository } from '../repositories/automation.trigger.repository';
import { TriggerCreateRo } from '../ros/trigger.create.ro';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { Body, Controller, Get, Headers, Param, Patch, Post, Query } from '@nestjs/common';
import { isProdMode } from 'app.environment';
import { UserService } from 'database/services/user/user.service';
import { UserService } from 'user/services/user.service';
import { TriggerTypeCreateRo } from '../ros/trigger.type.create.ro';
import { TriggerTypeUpdateRo } from '../ros/trigger.type.update.ro';
import { AutomationService } from '../services/automation.service';
Expand Down
6 changes: 3 additions & 3 deletions packages/room-server/src/automation/robot.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NodeRepository } from 'database/repositories/node.repository';
import { UserRepository } from 'database/repositories/user.repository';
import { UserService } from 'database/services/user/user.service';
import { NodeRepository } from 'node/repositories/node.repository';
import { UserRepository } from 'user/repositories/user.repository';
import { UserService } from 'user/services/user.service';
import { RobotActionController } from './controller/action.controller';
import { RobotActionTypeController } from './controller/action.type.controller';
import { AutomationActionRepository } from './repositories/automation.action.repository';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { AutomationRobotRunner, ConfigConstant, generateRandomString, IActionOutput, IActionType, validateMagicForm } from '@apitable/core';
import { Injectable, Logger } from '@nestjs/common';
import { NodeRepository } from 'database/repositories/node.repository';
import { NodeRepository } from 'node/repositories/node.repository';
import fetch from 'node-fetch';
import { InjectLogger } from 'shared/common';
import { RunHistoryStatusEnum } from 'shared/enums/automation.enum';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { DynamicModule, Module } from '@nestjs/common';
import { DatasheetRecordAlarmBaseService } from 'database/services/alarm/datasheet.record.alarm.base.service';
import { DatasheetRecordAlarmBaseService } from 'database/alarm/datasheet.record.alarm.base.service';
import path from 'path';
import * as fs from 'fs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import { Injectable } from '@nestjs/common';
import { RecordAlarmStatus } from 'shared/enums/record.alarm.enum';
import { DatasheetRecordAlarmEntity } from 'database/entities/datasheet.record.alarm.entity';
import { DatasheetRecordAlarmEntity } from './entities/datasheet.record.alarm.entity';
import { EntityManager } from 'typeorm';
import { ICommonData } from '../ot/ot.interface';
import { ICommonData } from '../ot/interfaces/ot.interface';

@Injectable()
export abstract class DatasheetRecordAlarmBaseService {
Expand Down
33 changes: 33 additions & 0 deletions packages/room-server/src/database/asset/asset.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* APITable <https://github.com/apitable/apitable>
* Copyright (C) 2022 APITable Ltd. <https://apitable.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AssetRepository } from 'database/asset/repositories/asset.repository';

@Module({
imports: [
TypeOrmModule.forFeature([
AssetRepository,
]),
],
providers: [],
controllers: [],
exports: [],
})
export class AssetModule {}
31 changes: 31 additions & 0 deletions packages/room-server/src/database/attachment/attachment.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* APITable <https://github.com/apitable/apitable>
* Copyright (C) 2022 APITable Ltd. <https://apitable.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Module } from '@nestjs/common';
import { NodeModule } from 'node/node.module';
import { ResourceModule } from 'database/resource/resource.module';
import { AttachmentController } from './controllers/attachment.controller';
import { AttachmentService } from './services/attachment.service';

@Module({
imports: [ResourceModule, NodeModule],
controllers: [AttachmentController],
providers: [AttachmentService],
exports: [AttachmentService],
})
export class AttachmentModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
import { ResourceDataInterceptor } from 'database/middleware/resource.data.interceptor';
import { AttachmentService } from 'database/services/attachment/attachment.service';
import { ResourceDataInterceptor } from 'database/resource/middleware/resource.data.interceptor';
import { AttachmentService } from 'database/attachment/services/attachment.service';

@Controller('nest/v1')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { IAuthHeader } from 'shared/interfaces';
import { IFileInterface } from 'shared/interfaces/file.interface';
import { JavaService } from 'shared/services/java/java.service';
import { Logger } from 'winston';
import { AttachmentDto } from '../../dtos/attachment.dto';
import { AttachmentDto } from '../dtos/attachment.dto';

@Injectable()
export class AttachmentService {
Expand Down
27 changes: 27 additions & 0 deletions packages/room-server/src/database/command/command.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* APITable <https://github.com/apitable/apitable>
* Copyright (C) 2022 APITable Ltd. <https://apitable.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Module } from '@nestjs/common';
import { CommandOptionsService } from './services/command.options.service';
import { CommandService } from './services/command.service';

@Module({
providers: [CommandService, CommandOptionsService],
exports: [CommandService, CommandOptionsService],
})
export class CommandModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/

import { Controller, Get, Headers, Param, UseInterceptors } from '@nestjs/common';
import { DashboardService } from 'database/services/dashboard/dashboard.service';
import { NodeService } from 'database/services/node/node.service';
import { NodeShareSettingService } from 'database/services/node/node.share.setting.service';
import { UserService } from 'database/services/user/user.service';
import { DashboardService } from 'database/dashboard/services/dashboard.service';
import { UserService } from 'user/services/user.service';
import { PermissionException, ServerException } from 'shared/exception';
import { ResourceDataInterceptor } from 'database/middleware/resource.data.interceptor';
import { ResourceDataInterceptor } from 'database/resource/middleware/resource.data.interceptor';
import { NodeService } from 'node/services/node.service';
import { NodeShareSettingService } from 'node/services/node.share.setting.service';

/**
* Dashboard Controller
Expand Down
42 changes: 42 additions & 0 deletions packages/room-server/src/database/dashboard/dashboard.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* APITable <https://github.com/apitable/apitable>
* Copyright (C) 2022 APITable Ltd. <https://apitable.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { forwardRef, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NodeModule } from 'node/node.module';
import { ResourceMetaRepository } from 'database/resource/repositories/resource.meta.repository';
import { ResourceModule } from 'database/resource/resource.module';
import { UserModule } from 'user/user.module';
import { DashboardController } from './controllers/dashboard.controller';
import { DashboardService } from './services/dashboard.service';

@Module({
imports: [
NodeModule,
UserModule,
forwardRef(()=>ResourceModule),
TypeOrmModule.forFeature([
// TODO(Troy): stop using other modules's repositories, use service instead, via importing the module
ResourceMetaRepository,
]),
],
controllers: [DashboardController],
providers: [DashboardService],
exports: [DashboardService]
})
export class DashboardModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import { IDashboardLayout, IResourceMeta } from '@apitable/core';
import { Injectable } from '@nestjs/common';
import { NodeService } from 'database/services/node/node.service';
import { NodeService } from 'node/services/node.service';
import { ResourceMetaRepository } from 'database/resource/repositories/resource.meta.repository';
import { ResourceException, ServerException } from 'shared/exception';
import { RestService } from 'shared/services/rest/rest.service';
import { DashboardDataPack, NodeDetailInfo, WidgetMap } from '../../interfaces';
import { ResourceMetaRepository } from '../../repositories/resource.meta.repository';

@Injectable()
export class DashboardService {
Expand Down
Loading

0 comments on commit 65edd98

Please sign in to comment.