From 4a634c87c5069cdf0522e75ed1b174b4a9813960 Mon Sep 17 00:00:00 2001 From: adeiskandarzulkarnaen Date: Sat, 7 Dec 2024 15:34:30 +0700 Subject: [PATCH] refactor code --- .dockerignore | 13 +++++++ .github/workflows/bunhono_ci.yml | 8 ++-- Dockerfile | 21 ++++++++++ bun.lockb | Bin 50841 -> 54950 bytes package.json | 4 +- src/Applications/cache/CacheServer.ts | 7 ++++ src/Applications/use_case/UserLoginUseCase.ts | 2 +- .../authentications/{ => entities}/NewAuth.ts | 0 .../{ => entities}/_test/NewAuth.test.ts | 0 .../cache/redis/RedisCacheServer.ts | 36 ++++++++++++++++++ src/Infrastructures/email/NodeMailer.ts | 0 src/Infrastructures/logger/WinstonLogger.ts | 0 src/Infrastructures/storage/LocalStorage.ts | 34 +++++++++++++++++ .../{bearerMiddleware.ts => bearerAuth.ts} | 9 ++--- 14 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 src/Applications/cache/CacheServer.ts rename src/Domains/authentications/{ => entities}/NewAuth.ts (100%) rename src/Domains/authentications/{ => entities}/_test/NewAuth.test.ts (100%) create mode 100644 src/Infrastructures/cache/redis/RedisCacheServer.ts create mode 100644 src/Infrastructures/email/NodeMailer.ts create mode 100644 src/Infrastructures/logger/WinstonLogger.ts create mode 100644 src/Infrastructures/storage/LocalStorage.ts rename src/Interfaces/http/middlewares/{bearerMiddleware.ts => bearerAuth.ts} (74%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b3d8a79 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +coverage* +node_modules +dist +Dockerfile* +docker-compose* +.dockerignore +.editorconfig +.env +.git +.gitignore +.DS_Store +.vscode +.idea diff --git a/.github/workflows/bunhono_ci.yml b/.github/workflows/bunhono_ci.yml index daa5cda..cfb95a0 100644 --- a/.github/workflows/bunhono_ci.yml +++ b/.github/workflows/bunhono_ci.yml @@ -23,7 +23,7 @@ jobs: bun run lint bun run test env: - APP_PORT: ${{ variables.APP_PORT }} - DATABASE_URL: ${{ secrets.DATABASE_URL }} - ACCESS_TOKEN_AGE: ${{ variables.ACCESS_TOKEN_AGE }} - ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }} + APP_PORT: ${{ variables.TEST_APP_PORT }} + DATABASE_URL: ${{ variables.TEST_DATABASE_URL }} + ACCESS_TOKEN_AGE: ${{ variables.TEST_ACCESS_TOKEN_AGE }} + ACCESS_TOKEN_SECRET: ${{ variables.TEST_ACCESS_TOKEN_SECRET }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9125d6b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM oven/bun:alpine + +ENV PORT= +ENV DATABASE_URL= +ENV ACCESS_TOKEN_AGE= +ENV ACCESS_TOKEN_SECRET= + +LABEL maintainer="adeiskandarzulkarnaen@gmail.com" +LABEL description="A Docker image for a Bun HONO application" +LABEL version="1.0" + +WORKDIR /app + +COPY . . + +RUN bun install +RUN bunx prisma generate + +EXPOSE $APP_PORT/tcp + +CMD ["sh", "-c", "bun run migrate:up && bun run start:dev"] diff --git a/bun.lockb b/bun.lockb index 97397304860bb14f6cc6991967833e2d518fce04..8f86fd1ed6b2252a8d496c4d5dee556c037478c8 100755 GIT binary patch delta 11431 zcmeHNdwfjS_CMz&6PdguLNl36B#}e~88UfHB#gwH34%lz27}f7)e*IjYOB8)LIiT-zDA%N)D%ZDE;fbJEyTMQd{(TlK=%2i~3B`hoWZ zxvXf+3aNQ(xk8k`UV>0t>6lXJ1U(P50Y41s4OuM;f-httBd9n(wsg2QV2 zPF3!Q)T4ij!%-d$Q!~L^gQuzO2iz4N1SKBN8n(K^)tp&rtSv?G6$!d^nPHvHGzVIEm5&SA7{?}Gl7Dg9gs`Bd6 znUl+=I3B}voH>gi`TA+ z+>&A;x3Zu-x6p(?*0?8BB!8(pd0aiB`aW!Ea)^mqsgJ%Z`LOaMCu7VJV zHK;v@3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W}0<_X785 zoXd3Hjr=Cy0YzdZY(}Q02Y--0-b?@RXd*rH=zOv~Ha~`^8xHwj@g6w$Z@IJODmy9A@tHdo75jdU+=R> z%A{E6SNp<3!bBU+5uBC&OJ;KJw^;QD)ipUgx3<6gYqlaool5l4vA@BpKaA!@eY7k4 zLJ(WQp@J27D!sAaX4RiY=TCd($j9xS z98TMzaEH|bh3E+S@PI{1iJ+SYY|;sdruJK;(~&f%|EzR9ioWl+N!mL20WSeh+N79K zbpMldo3KD@O*UD>f-c>+hgngv5>>{y>5aH5@cpd)h*8qX(@P$?QqW0! zzwmYO)5rZ$4lH4uh6o-e#{XJ%>K}q1dhQW)kd}gdfio60_djG zHv@H%s^^BJY<0ee}Ae!nA z#ai{3*WM52iD!mt9=v@=7HLroS&k=31LBUu0eV=3&Y#j3w0 z2Q0RgzY}=kbtq)0HcT5wvya-O39+={XtDLrO<_~{TJUKseSFlCsXrz=#ucr&dxuNb zEP}0nEh;qUShV%dLDklVI!8`@&hOmmZNDkXGE|n0KHI^1Pc0Lu__$5FK7stlEmr-h zI@I^PWpmQTW=Z6u2U8-9j3?^}i&cN)o^fi{tT5>ztn!Jt@W4&Hc5@F}N0O>udS`Y0 z@%x^ujqhxY_+q>yrtycsj+-p5ihR8FPFwPD;; + abstract get(key: string): Promise; + abstract delete(key:string): Promise; +}; + +export default CacheServer; diff --git a/src/Applications/use_case/UserLoginUseCase.ts b/src/Applications/use_case/UserLoginUseCase.ts index 14a699b..a8600a1 100644 --- a/src/Applications/use_case/UserLoginUseCase.ts +++ b/src/Applications/use_case/UserLoginUseCase.ts @@ -1,4 +1,4 @@ -import { eNewAuth, NewAuth } from '@domains/authentications/NewAuth'; +import { eNewAuth, NewAuth } from '@domains/authentications/entities/NewAuth'; import { eUserLogin, UserLogin } from '@domains/users/entities/UserLogin'; import type UserRepository from '@domains/users/UserRepository'; import type PasswordHash from '@applications/security/PasswordHash'; diff --git a/src/Domains/authentications/NewAuth.ts b/src/Domains/authentications/entities/NewAuth.ts similarity index 100% rename from src/Domains/authentications/NewAuth.ts rename to src/Domains/authentications/entities/NewAuth.ts diff --git a/src/Domains/authentications/_test/NewAuth.test.ts b/src/Domains/authentications/entities/_test/NewAuth.test.ts similarity index 100% rename from src/Domains/authentications/_test/NewAuth.test.ts rename to src/Domains/authentications/entities/_test/NewAuth.test.ts diff --git a/src/Infrastructures/cache/redis/RedisCacheServer.ts b/src/Infrastructures/cache/redis/RedisCacheServer.ts new file mode 100644 index 0000000..a6534ac --- /dev/null +++ b/src/Infrastructures/cache/redis/RedisCacheServer.ts @@ -0,0 +1,36 @@ +import { createClient, RedisClientType } from 'redis'; +import CacheServer from '@applications/cache/CacheServer'; + + + +class RedisCacheServer implements CacheServer{ + private client: RedisClientType; + constructor() { + this.client = createClient({ + socket: { + host: process.env.REDIS_HOST, + } + }); + + this.client.on('error', (error) => console.error(error)); + this.client.connect(); + } + + public async set(key: string, value: string, expirationInSecond = 1800) : Promise { + await this.client.set(key, value, { + EX: expirationInSecond, + }); + } + + public async get(key: string): Promise { + const result = await this.client.get(key); + if (!result) throw new Error('Cache tidak ditemukan'); + return result; + } + + public async delete(key: string): Promise { + return this.client.del(key); + } +}; + +export default RedisCacheServer; diff --git a/src/Infrastructures/email/NodeMailer.ts b/src/Infrastructures/email/NodeMailer.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/Infrastructures/logger/WinstonLogger.ts b/src/Infrastructures/logger/WinstonLogger.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/Infrastructures/storage/LocalStorage.ts b/src/Infrastructures/storage/LocalStorage.ts new file mode 100644 index 0000000..2a90331 --- /dev/null +++ b/src/Infrastructures/storage/LocalStorage.ts @@ -0,0 +1,34 @@ +// const fs = require('fs'); + +// class StorageService { +// constructor(folder) { +// this._folder = folder; + +// if (!fs.existsSync(folder)) { +// fs.mkdirSync(folder, { recursive: true }); +// } +// } + +// writeFile(file, meta) { +// const filename = +new Date() + meta.filename; +// const path = `${this._folder}/${filename}`; + +// const fileStream = fs.createWriteStream(path); + +// return new Promise((resolve, reject) => { +// fileStream.on('error', (error) => reject(error)); +// file.pipe(fileStream); +// file.on('end', () => resolve(filename)); +// }); +// } + +// deleteFile(url) { +// const filename = url.split('/').pop(); +// const path = `${this._folder}/${filename}`; +// fs.unlink(path, () => { +// console.log('gagal menghapus, file tidak ditemukan'); +// }); +// } +// } + +// module.exports = StorageService; diff --git a/src/Interfaces/http/middlewares/bearerMiddleware.ts b/src/Interfaces/http/middlewares/bearerAuth.ts similarity index 74% rename from src/Interfaces/http/middlewares/bearerMiddleware.ts rename to src/Interfaces/http/middlewares/bearerAuth.ts index 5ff3e40..f48fdc2 100644 --- a/src/Interfaces/http/middlewares/bearerMiddleware.ts +++ b/src/Interfaces/http/middlewares/bearerAuth.ts @@ -1,15 +1,15 @@ -import { bearerAuth } from 'hono/bearer-auth'; +import { bearerAuth as bearerAuthMiddleware } from 'hono/bearer-auth'; import { MiddlewareHandler } from 'hono'; -function bearerMiddleware(): MiddlewareHandler { +function bearerAuth(): MiddlewareHandler { const token: string | undefined = process.env.BEARER_TOKEN; if (!token) { throw new Error('Environment variable BEARER_TOKEN is not set'); } - return bearerAuth({ + return bearerAuthMiddleware({ token, noAuthenticationHeaderMessage: { status: 'fail', @@ -26,5 +26,4 @@ function bearerMiddleware(): MiddlewareHandler { }); }; -export default bearerMiddleware; - +export default bearerAuth;