From 420117e4322c59c57a1984fbfc29e79bb6b26abf Mon Sep 17 00:00:00 2001 From: Anas Abbal Date: Wed, 19 Jun 2024 14:10:56 +0100 Subject: [PATCH] change nuber-app to gateway --- apps/gateway/src/gateway.controller.spec.ts | 22 ++++++++ apps/gateway/src/gateway.controller.ts | 12 +++++ apps/gateway/src/gateway.module.ts | 10 ++++ .../src/gateway.service.ts} | 2 +- apps/{nuber-app => gateway}/src/main.ts | 6 +-- .../src/rest/auth.controller.ts | 0 .../src/rest/driver.controller.ts | 0 .../src/rest/metric.controller.ts | 0 .../src/rest/user.controller.ts | 0 .../src/services/driver-service.ts | 0 .../src/services/metric.service.ts | 0 .../src/services/user-service.ts | 0 .../test/app.e2e-spec.ts | 6 +-- .../{nuber-app => gateway}/test/jest-e2e.json | 0 apps/{nuber-app => gateway}/tsconfig.app.json | 2 +- apps/nuber-app/src/app.controller.spec.ts | 22 -------- apps/nuber-app/src/app.module.ts | 51 ------------------- nest-cli.json | 18 +++---- package.json | 2 +- 19 files changed, 61 insertions(+), 92 deletions(-) create mode 100644 apps/gateway/src/gateway.controller.spec.ts create mode 100644 apps/gateway/src/gateway.controller.ts create mode 100644 apps/gateway/src/gateway.module.ts rename apps/{nuber-app/src/app.service.ts => gateway/src/gateway.service.ts} (79%) rename apps/{nuber-app => gateway}/src/main.ts (81%) rename apps/{nuber-app => gateway}/src/rest/auth.controller.ts (100%) rename apps/{nuber-app => gateway}/src/rest/driver.controller.ts (100%) rename apps/{nuber-app => gateway}/src/rest/metric.controller.ts (100%) rename apps/{nuber-app => gateway}/src/rest/user.controller.ts (100%) rename apps/{nuber-app => gateway}/src/services/driver-service.ts (100%) rename apps/{nuber-app => gateway}/src/services/metric.service.ts (100%) rename apps/{nuber-app => gateway}/src/services/user-service.ts (100%) rename apps/{nuber-app => gateway}/test/app.e2e-spec.ts (79%) rename apps/{nuber-app => gateway}/test/jest-e2e.json (100%) rename apps/{nuber-app => gateway}/tsconfig.app.json (81%) delete mode 100644 apps/nuber-app/src/app.controller.spec.ts delete mode 100644 apps/nuber-app/src/app.module.ts diff --git a/apps/gateway/src/gateway.controller.spec.ts b/apps/gateway/src/gateway.controller.spec.ts new file mode 100644 index 0000000..4eb6472 --- /dev/null +++ b/apps/gateway/src/gateway.controller.spec.ts @@ -0,0 +1,22 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GatewayController } from './gateway.controller'; +import { GatewayService } from './gateway.service'; + +describe('GatewayController', () => { + let gatewayController: GatewayController; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [GatewayController], + providers: [GatewayService], + }).compile(); + + gatewayController = app.get(GatewayController); + }); + + describe('root', () => { + it('should return "Hello World!"', () => { + expect(gatewayController.getHello()).toBe('Hello World!'); + }); + }); +}); diff --git a/apps/gateway/src/gateway.controller.ts b/apps/gateway/src/gateway.controller.ts new file mode 100644 index 0000000..2b8f6d7 --- /dev/null +++ b/apps/gateway/src/gateway.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { GatewayService } from './gateway.service'; + +@Controller() +export class GatewayController { + constructor(private readonly gatewayService: GatewayService) {} + + @Get() + getHello(): string { + return this.gatewayService.getHello(); + } +} diff --git a/apps/gateway/src/gateway.module.ts b/apps/gateway/src/gateway.module.ts new file mode 100644 index 0000000..74c7c63 --- /dev/null +++ b/apps/gateway/src/gateway.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { GatewayController } from './gateway.controller'; +import { GatewayService } from './gateway.service'; + +@Module({ + imports: [], + controllers: [GatewayController], + providers: [GatewayService], +}) +export class GatewayModule {} diff --git a/apps/nuber-app/src/app.service.ts b/apps/gateway/src/gateway.service.ts similarity index 79% rename from apps/nuber-app/src/app.service.ts rename to apps/gateway/src/gateway.service.ts index 927d7cc..37b71c8 100644 --- a/apps/nuber-app/src/app.service.ts +++ b/apps/gateway/src/gateway.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; @Injectable() -export class AppService { +export class GatewayService { getHello(): string { return 'Hello World!'; } diff --git a/apps/nuber-app/src/main.ts b/apps/gateway/src/main.ts similarity index 81% rename from apps/nuber-app/src/main.ts rename to apps/gateway/src/main.ts index 2e730a3..11909cc 100644 --- a/apps/nuber-app/src/main.ts +++ b/apps/gateway/src/main.ts @@ -1,11 +1,9 @@ import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; +import { GatewayModule } from './gateway.module'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; - - async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(GatewayModule); // Swagger configuration const config = new DocumentBuilder() diff --git a/apps/nuber-app/src/rest/auth.controller.ts b/apps/gateway/src/rest/auth.controller.ts similarity index 100% rename from apps/nuber-app/src/rest/auth.controller.ts rename to apps/gateway/src/rest/auth.controller.ts diff --git a/apps/nuber-app/src/rest/driver.controller.ts b/apps/gateway/src/rest/driver.controller.ts similarity index 100% rename from apps/nuber-app/src/rest/driver.controller.ts rename to apps/gateway/src/rest/driver.controller.ts diff --git a/apps/nuber-app/src/rest/metric.controller.ts b/apps/gateway/src/rest/metric.controller.ts similarity index 100% rename from apps/nuber-app/src/rest/metric.controller.ts rename to apps/gateway/src/rest/metric.controller.ts diff --git a/apps/nuber-app/src/rest/user.controller.ts b/apps/gateway/src/rest/user.controller.ts similarity index 100% rename from apps/nuber-app/src/rest/user.controller.ts rename to apps/gateway/src/rest/user.controller.ts diff --git a/apps/nuber-app/src/services/driver-service.ts b/apps/gateway/src/services/driver-service.ts similarity index 100% rename from apps/nuber-app/src/services/driver-service.ts rename to apps/gateway/src/services/driver-service.ts diff --git a/apps/nuber-app/src/services/metric.service.ts b/apps/gateway/src/services/metric.service.ts similarity index 100% rename from apps/nuber-app/src/services/metric.service.ts rename to apps/gateway/src/services/metric.service.ts diff --git a/apps/nuber-app/src/services/user-service.ts b/apps/gateway/src/services/user-service.ts similarity index 100% rename from apps/nuber-app/src/services/user-service.ts rename to apps/gateway/src/services/user-service.ts diff --git a/apps/nuber-app/test/app.e2e-spec.ts b/apps/gateway/test/app.e2e-spec.ts similarity index 79% rename from apps/nuber-app/test/app.e2e-spec.ts rename to apps/gateway/test/app.e2e-spec.ts index 50cda62..5f42b20 100644 --- a/apps/nuber-app/test/app.e2e-spec.ts +++ b/apps/gateway/test/app.e2e-spec.ts @@ -1,14 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; -import { AppModule } from './../src/app.module'; +import { GatewayModule } from '../src/gateway.module'; -describe('AppController (e2e)', () => { +describe('GatewayController (e2e)', () => { let app: INestApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], + imports: [GatewayModule], }).compile(); app = moduleFixture.createNestApplication(); diff --git a/apps/nuber-app/test/jest-e2e.json b/apps/gateway/test/jest-e2e.json similarity index 100% rename from apps/nuber-app/test/jest-e2e.json rename to apps/gateway/test/jest-e2e.json diff --git a/apps/nuber-app/tsconfig.app.json b/apps/gateway/tsconfig.app.json similarity index 81% rename from apps/nuber-app/tsconfig.app.json rename to apps/gateway/tsconfig.app.json index f27ed5f..4955d6a 100644 --- a/apps/nuber-app/tsconfig.app.json +++ b/apps/gateway/tsconfig.app.json @@ -2,7 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "declaration": false, - "outDir": "../../dist/apps/nuber-app" + "outDir": "../../dist/apps/gateway" }, "include": ["src/**/*"], "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] diff --git a/apps/nuber-app/src/app.controller.spec.ts b/apps/nuber-app/src/app.controller.spec.ts deleted file mode 100644 index d22f389..0000000 --- a/apps/nuber-app/src/app.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/apps/nuber-app/src/app.module.ts b/apps/nuber-app/src/app.module.ts deleted file mode 100644 index 400865a..0000000 --- a/apps/nuber-app/src/app.module.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; -import { ClientsModule, Transport } from '@nestjs/microservices'; -import { UserService } from './services/user-service'; -import { UserController } from './rest/user.controller'; -import { AuthController } from './rest/auth.controller'; -import { DriversController } from './rest/driver.controller'; -import { DriverService } from './services/driver-service'; -import { WinstonModule } from 'nest-winston'; -import * as winston from 'winston'; -import { PrometheusModule } from '@willsoto/nestjs-prometheus'; - -@Module({ - imports: [ - PrometheusModule.register({ - path: '/metrics', - }), - ConfigModule.forRoot(), - ClientsModule.register([ - { - name: 'USER_SERVICE', - transport: Transport.TCP, - options: { - host: 'localhost', - port: 3001, // port of user-service - }, - }, - { - name: 'DRIVER_SERVICE', - transport: Transport.TCP, - options: { - host: 'localhost', - port: 3002, // port of user-service - }, - }, - ]), - WinstonModule.forRoot({ - transports: [ - new winston.transports.Console({ - format: winston.format.combine( - winston.format.timestamp(), - winston.format.simple(), - ), - }) - ], - }), - ], - controllers: [AuthController, UserController, DriversController], - providers: [UserService, DriverService] -}) -export class AppModule {} diff --git a/nest-cli.json b/nest-cli.json index 590dcca..ae8a537 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -10,15 +10,6 @@ "monorepo": true, "root": "apps/nuber-app", "projects": { - "nuber-app": { - "type": "application", - "root": "apps/nuber-app", - "entryFile": "main", - "sourceRoot": "apps/nuber-app/src", - "compilerOptions": { - "tsConfigPath": "apps/nuber-app/tsconfig.app.json" - } - }, "user-service": { "type": "application", "root": "apps/user-service", @@ -81,6 +72,15 @@ "compilerOptions": { "tsConfigPath": "libs/database/tsconfig.lib.json" } + }, + "gateway": { + "type": "application", + "root": "apps/gateway", + "entryFile": "main", + "sourceRoot": "apps/gateway/src", + "compilerOptions": { + "tsConfigPath": "apps/gateway/tsconfig.app.json" + } } } } \ No newline at end of file diff --git a/package.json b/package.json index 2858472..0e6e730 100644 --- a/package.json +++ b/package.json @@ -98,4 +98,4 @@ "^@app/database(|/.*)$": "/libs/database/src/$1" } } -} +} \ No newline at end of file