Skip to content

Commit

Permalink
feat: init notification service
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 19, 2024
1 parent 3b01705 commit 3797fc2
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 2 deletions.
32 changes: 32 additions & 0 deletions apps/notification/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM oven/bun:latest AS development

WORKDIR /usr/src/app

COPY package.json ./
COPY bun.lockb ./
COPY tsconfig.json tsconfig.json
COPY nest-cli.json nest-cli.json

COPY apps/notification apps/notification
COPY libs libs
COPY proto proto

RUN bun install
RUN bun build:notification

FROM oven/bun:latest AS production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY package.json ./
COPY bun.lockb ./

RUN bun install --production

COPY --from=development /usr/src/app/dist ./dist
COPY --from=development /usr/src/app/proto ./proto

CMD ["sh", "-c", "bun run dist/apps/notification/main.js"]
8 changes: 8 additions & 0 deletions apps/notification/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { NotificationModule } from './notification.module';

async function bootstrap() {
const app = await NestFactory.create(NotificationModule);
await app.listen(process.env.port ?? 3000);
}
bootstrap();
24 changes: 24 additions & 0 deletions apps/notification/src/notification.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { NotificationController } from './notification.controller';
import { NotificationService } from './notification.service';

describe('NotificationController', () => {
let notificationController: NotificationController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [NotificationController],
providers: [NotificationService],
}).compile();

notificationController = app.get<NotificationController>(
NotificationController,
);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(notificationController.getHello()).toBe('Hello World!');
});
});
});
12 changes: 12 additions & 0 deletions apps/notification/src/notification.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { NotificationService } from './notification.service';

@Controller()
export class NotificationController {
constructor(private readonly notificationService: NotificationService) {}

@Get()
getHello(): string {
return this.notificationService.getHello();
}
}
10 changes: 10 additions & 0 deletions apps/notification/src/notification.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { NotificationController } from './notification.controller';
import { NotificationService } from './notification.service';

@Module({
imports: [],
controllers: [NotificationController],
providers: [NotificationService],
})
export class NotificationModule {}
8 changes: 8 additions & 0 deletions apps/notification/src/notification.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class NotificationService {
getHello(): string {
return 'Hello World!';
}
}
24 changes: 24 additions & 0 deletions apps/notification/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { NotificationModule } from './../src/notification.module';

describe('NotificationController (e2e)', () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [NotificationModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
9 changes: 9 additions & 0 deletions apps/notification/test/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
9 changes: 9 additions & 0 deletions apps/notification/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/notification"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
5 changes: 4 additions & 1 deletion apps/swap/src/fx/fx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export class FxService {
baseCurrency: Currency,
targetCurrency: Currency,
) {
const rate = await this.getExchangeRate(mapToSupportedCurrency(baseCurrency), mapToSupportedCurrency(targetCurrency));
const rate = await this.getExchangeRate(
mapToSupportedCurrency(baseCurrency),
mapToSupportedCurrency(targetCurrency),
);
return 1 / rate;
}
}
22 changes: 22 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ services:
volumes:
- .:/usr/src/app

notification:
container_name: notification
build:
context: .
dockerfile: ./apps/notification/Dockerfile
target: development
command: [
"sh",
"-c",
"bun dev notification"
]
restart: always
depends_on:
- mongodb
- redis
env_file:
- ./apps/notification/.env
ports:
- '4050:4050'
volumes:
- .:/usr/src/app

mongodb:
image: mongo:7.0-jammy
container_name: mongodb
Expand Down
13 changes: 12 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"compilerOptions": {
"deleteOutDir": true,
"webpack": true,
"assets": ["**/*.proto"],
"assets": [
"**/*.proto"
],
"watchAssets": true
},
"projects": {
Expand Down Expand Up @@ -35,6 +37,15 @@
"compilerOptions": {
"tsConfigPath": "apps/swap/tsconfig.app.json"
}
},
"notification": {
"type": "application",
"root": "apps/notification",
"entryFile": "main",
"sourceRoot": "apps/notification/src",
"compilerOptions": {
"tsConfigPath": "apps/notification/tsconfig.app.json"
}
}
},
"monorepo": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "nest build",
"build:api": "bun run build api",
"build:swap": "bun run build swap",
"build:notification": "bun run build notification",
"format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"",
"lint": "bun run eslint \"{apps,libs,test}/**/*.ts\" --fix",
"test": "bun test",
Expand Down

0 comments on commit 3797fc2

Please sign in to comment.