From 610225929580b0f6b8decbbacc0ba54757d70643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Sun, 24 Dec 2023 11:08:36 +0100 Subject: [PATCH] Create api folder #73 --- .../dependencyInjection}/commandHandlers.ts | 0 src/api/dependencyInjection/controllers.ts | 27 +++++++++++++++++ .../dependencyInjection}/eventHandlers.ts | 0 .../projectionHandlers.ts | 0 .../dependencyInjection}/queryHandlers.ts | 0 .../dependencyInjection}/readLayers.ts | 0 .../dependencyInjection}/repositories.ts | 12 ++++---- src/api/dependencyInjection/services.ts | 13 ++++++++ .../nestjs => api}/filters/errorFilter.ts | 2 +- .../nestjs => api}/guards/jwtAuthGuard.ts | 4 +-- .../api/serializers/apiExceptionSerializer.ts | 0 .../sse/notificationsSseController.ts} | 4 +-- .../sse.service.ts => api/sse/sseService.ts} | 0 .../sse/unhandledExceptionsBusService.ts} | 4 +-- .../controllers/auth/loginPostController.ts | 0 .../api/v1/controllers/auth/loginPostDto.ts | 0 .../controllers/auth/loginPostResponseDto.ts | 0 .../v1/controllers/auth/meGetController.ts | 2 +- .../v1/controllers/auth/meGetResponseDto.ts | 0 .../auth/refreshTokenPostController.ts | 0 .../controllers/auth/refreshTokenPostDto.ts | 0 .../auth/refreshTokenPostResponseDto.ts | 0 .../countries/countriesGetController.ts | 2 +- .../countries/countryGetController.ts | 2 +- .../countries/countryGetResponse.ts | 0 .../countries/countryPostController.ts | 2 +- .../controllers/countries/countryPostDto.ts | 0 .../expressions/expressionPostController.ts | 2 +- .../expressions/expressionPostDto.ts | 0 .../terms/findSuggestionsTermController.ts | 2 +- .../terms/searchTermsGetController.ts | 2 +- .../api/v1/controllers/terms/termResponse.ts | 0 .../api/v1/controllers/terms/termsResponse.ts | 0 .../v1/controllers/user/userPutController.ts | 4 +-- .../api/v1/controllers/user/userPutDto.ts | 0 .../controllers/words/wordPostController.ts | 2 +- .../api/v1/controllers/words/wordPostDto.ts | 0 src/app.module.ts | 4 +-- .../infrastructure/nestjs/controllers.ts | 25 ---------------- .../infrastructure/nestjs/language.module.ts | 16 ---------- .../infrastructure/nestjs/services.ts | 9 ------ src/languages/language.module.ts | 16 ++++++++++ .../strategies/jwtStrategy.ts | 0 .../{nestjs => }/buses/nestCommandBus.ts | 0 .../{nestjs => }/buses/nestEventBus.ts | 0 .../{nestjs => }/buses/nestProjectionBus.ts | 0 .../{nestjs => }/buses/nestQueryBus.ts | 0 .../logger/logger.ts => logger/nestLogger.ts} | 4 +-- .../persistDomainEventsSuscriber.ts} | 4 +-- .../nestjs => }/shared.module.ts | 30 ++++++++----------- 50 files changed, 96 insertions(+), 98 deletions(-) rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/commandHandlers.ts (100%) create mode 100644 src/api/dependencyInjection/controllers.ts rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/eventHandlers.ts (100%) rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/projectionHandlers.ts (100%) rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/queryHandlers.ts (100%) rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/readLayers.ts (100%) rename src/{languages/infrastructure/nestjs => api/dependencyInjection}/repositories.ts (57%) create mode 100644 src/api/dependencyInjection/services.ts rename src/{shared/infrastructure/nestjs => api}/filters/errorFilter.ts (91%) rename src/{shared/infrastructure/nestjs => api}/guards/jwtAuthGuard.ts (89%) rename src/{shared/infrastructure => }/api/serializers/apiExceptionSerializer.ts (100%) rename src/{shared/infrastructure/sse/sse.controller.ts => api/sse/notificationsSseController.ts} (86%) rename src/{shared/infrastructure/sse/sse.service.ts => api/sse/sseService.ts} (100%) rename src/{shared/infrastructure/nestjs/buses/errors/unhandledExceptionsBusHandler.ts => api/sse/unhandledExceptionsBusService.ts} (87%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/loginPostController.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/loginPostDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/loginPostResponseDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/meGetController.ts (92%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/meGetResponseDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/refreshTokenPostController.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/refreshTokenPostDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/auth/refreshTokenPostResponseDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/countries/countriesGetController.ts (92%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/countries/countryGetController.ts (92%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/countries/countryGetResponse.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/countries/countryPostController.ts (94%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/countries/countryPostDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/expressions/expressionPostController.ts (94%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/expressions/expressionPostDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/terms/findSuggestionsTermController.ts (93%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/terms/searchTermsGetController.ts (92%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/terms/termResponse.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/terms/termsResponse.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/user/userPutController.ts (86%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/user/userPutDto.ts (100%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/words/wordPostController.ts (94%) rename src/{languages/infrastructure/ui => }/api/v1/controllers/words/wordPostDto.ts (100%) delete mode 100644 src/languages/infrastructure/nestjs/controllers.ts delete mode 100644 src/languages/infrastructure/nestjs/language.module.ts delete mode 100644 src/languages/infrastructure/nestjs/services.ts create mode 100644 src/languages/language.module.ts rename src/shared/infrastructure/{nestjs => auth}/strategies/jwtStrategy.ts (100%) rename src/shared/infrastructure/{nestjs => }/buses/nestCommandBus.ts (100%) rename src/shared/infrastructure/{nestjs => }/buses/nestEventBus.ts (100%) rename src/shared/infrastructure/{nestjs => }/buses/nestProjectionBus.ts (100%) rename src/shared/infrastructure/{nestjs => }/buses/nestQueryBus.ts (100%) rename src/shared/infrastructure/{nestjs/logger/logger.ts => logger/nestLogger.ts} (84%) rename src/shared/infrastructure/{nestjs/buses/events/persistEventsHandler.ts => subscribers/persistDomainEventsSuscriber.ts} (89%) rename src/shared/{infrastructure/nestjs => }/shared.module.ts (62%) diff --git a/src/languages/infrastructure/nestjs/commandHandlers.ts b/src/api/dependencyInjection/commandHandlers.ts similarity index 100% rename from src/languages/infrastructure/nestjs/commandHandlers.ts rename to src/api/dependencyInjection/commandHandlers.ts diff --git a/src/api/dependencyInjection/controllers.ts b/src/api/dependencyInjection/controllers.ts new file mode 100644 index 00000000..dea8087a --- /dev/null +++ b/src/api/dependencyInjection/controllers.ts @@ -0,0 +1,27 @@ +import LoginPostController from '@src/api/v1/controllers/auth/loginPostController'; +import RefreshTokenPostController from '@src/api/v1/controllers/auth/refreshTokenPostController'; +import MeGetController from '@src/api/v1/controllers/auth/meGetController'; +import SearchTermsGetController from '@src/api/v1/controllers/terms/searchTermsGetController'; +import FindSuggestionsTermController from '@src/api/v1/controllers/terms/findSuggestionsTermController'; +import WordPostController from '@src/api/v1/controllers/words/wordPostController'; +import ExpressionPostController from '@src/api/v1/controllers/expressions/expressionPostController'; +import CountriesGetController from '@src/api/v1/controllers/countries/countriesGetController'; +import CountryGetController from '@src/api/v1/controllers/countries/countryGetController'; +import CountryPostController from '@src/api/v1/controllers/countries/countryPostController'; +import UserPutController from '@src/api/v1/controllers/user/userPutController'; +import { NotificationsSseController } from '@src/api/sse/notificationsSseController'; + +export const controllers = [ + NotificationsSseController, + LoginPostController, + RefreshTokenPostController, + MeGetController, + SearchTermsGetController, + FindSuggestionsTermController, + WordPostController, + ExpressionPostController, + CountriesGetController, + CountryGetController, + CountryPostController, + UserPutController, +]; diff --git a/src/languages/infrastructure/nestjs/eventHandlers.ts b/src/api/dependencyInjection/eventHandlers.ts similarity index 100% rename from src/languages/infrastructure/nestjs/eventHandlers.ts rename to src/api/dependencyInjection/eventHandlers.ts diff --git a/src/languages/infrastructure/nestjs/projectionHandlers.ts b/src/api/dependencyInjection/projectionHandlers.ts similarity index 100% rename from src/languages/infrastructure/nestjs/projectionHandlers.ts rename to src/api/dependencyInjection/projectionHandlers.ts diff --git a/src/languages/infrastructure/nestjs/queryHandlers.ts b/src/api/dependencyInjection/queryHandlers.ts similarity index 100% rename from src/languages/infrastructure/nestjs/queryHandlers.ts rename to src/api/dependencyInjection/queryHandlers.ts diff --git a/src/languages/infrastructure/nestjs/readLayers.ts b/src/api/dependencyInjection/readLayers.ts similarity index 100% rename from src/languages/infrastructure/nestjs/readLayers.ts rename to src/api/dependencyInjection/readLayers.ts diff --git a/src/languages/infrastructure/nestjs/repositories.ts b/src/api/dependencyInjection/repositories.ts similarity index 57% rename from src/languages/infrastructure/nestjs/repositories.ts rename to src/api/dependencyInjection/repositories.ts index 469021fd..3a85491d 100644 --- a/src/languages/infrastructure/nestjs/repositories.ts +++ b/src/api/dependencyInjection/repositories.ts @@ -1,13 +1,13 @@ import { AUTH_SESSION_REPOSITORY } from '@src/languages/domain/auth/authSessionRepository'; -import TypeOrmAuthSessionRepository from '../persistence/typeOrm/repositories/typeOrmAuthSessionRepository'; +import TypeOrmAuthSessionRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmAuthSessionRepository'; import { COUNTRY_REPOSITORY } from '@src/languages/domain/country/countryRepository'; -import TypeOrmCountryRepository from '../persistence/typeOrm/repositories/typeOrmCountryRepository'; +import TypeOrmCountryRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmCountryRepository'; import { EXPRESSION_REPOSITORY } from '@src/languages/domain/expression/expressionRepository'; -import TypeOrmExpressionRepository from '../persistence/typeOrm/repositories/typeOrmExpressionRepository'; -import TypeOrmWordRepository from '../persistence/typeOrm/repositories/typeOrmWordRepository'; -import TypeOrmUserRepository from '../persistence/typeOrm/repositories/typeOrmUserRepository'; +import TypeOrmExpressionRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmExpressionRepository'; +import TypeOrmWordRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmWordRepository'; +import TypeOrmUserRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmUserRepository'; import { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository'; -import MongoTermRepository from '../persistence/mongo/repositories/mongoTermRepository'; +import MongoTermRepository from '../../languages/infrastructure/persistence/mongo/repositories/mongoTermRepository'; import { USER_REPOSITORY } from '@src/languages/domain/user/userRepository'; import { WORD_REPOSITORY } from '@src/languages/domain/word/wordRepository'; diff --git a/src/api/dependencyInjection/services.ts b/src/api/dependencyInjection/services.ts new file mode 100644 index 00000000..793f9c43 --- /dev/null +++ b/src/api/dependencyInjection/services.ts @@ -0,0 +1,13 @@ +import { SOCIAL_AUTHENTICATOR } from '@src/languages/domain/auth/socialAuthenticator'; +import GoogleSocialAuthenticator from '../../languages/infrastructure/oauth/googleSocialAuthenticator'; +import { SseService } from '@src/api/sse/sseService'; +import { UnhandledExceptionsBusService } from '@src/api/sse/unhandledExceptionsBusService'; + +export const services = [ + SseService, + UnhandledExceptionsBusService, + { + provide: SOCIAL_AUTHENTICATOR, + useClass: GoogleSocialAuthenticator, + }, +]; diff --git a/src/shared/infrastructure/nestjs/filters/errorFilter.ts b/src/api/filters/errorFilter.ts similarity index 91% rename from src/shared/infrastructure/nestjs/filters/errorFilter.ts rename to src/api/filters/errorFilter.ts index be63c6ec..8ac9dd8c 100644 --- a/src/shared/infrastructure/nestjs/filters/errorFilter.ts +++ b/src/api/filters/errorFilter.ts @@ -1,6 +1,6 @@ import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common'; import { Response } from 'express'; -import ApiExceptionSerializer from '../../api/serializers/apiExceptionSerializer'; +import ApiExceptionSerializer from '@src/api/serializers/apiExceptionSerializer'; import DomainException from '@src/shared/domain/exceptions/domainException'; @Catch(Error) diff --git a/src/shared/infrastructure/nestjs/guards/jwtAuthGuard.ts b/src/api/guards/jwtAuthGuard.ts similarity index 89% rename from src/shared/infrastructure/nestjs/guards/jwtAuthGuard.ts rename to src/api/guards/jwtAuthGuard.ts index 95ce6136..e8122600 100644 --- a/src/shared/infrastructure/nestjs/guards/jwtAuthGuard.ts +++ b/src/api/guards/jwtAuthGuard.ts @@ -14,11 +14,9 @@ export class JwtAuthGuard implements CanActivate { } try { - const payload = await this.jwtService.verifyAsync(token, { + request['user'] = await this.jwtService.verifyAsync(token, { secret: process.env.JWT_SECRET, }); - - request['user'] = payload; } catch { throw new UnauthorizedException(); } diff --git a/src/shared/infrastructure/api/serializers/apiExceptionSerializer.ts b/src/api/serializers/apiExceptionSerializer.ts similarity index 100% rename from src/shared/infrastructure/api/serializers/apiExceptionSerializer.ts rename to src/api/serializers/apiExceptionSerializer.ts diff --git a/src/shared/infrastructure/sse/sse.controller.ts b/src/api/sse/notificationsSseController.ts similarity index 86% rename from src/shared/infrastructure/sse/sse.controller.ts rename to src/api/sse/notificationsSseController.ts index 7819207f..139e0132 100644 --- a/src/shared/infrastructure/sse/sse.controller.ts +++ b/src/api/sse/notificationsSseController.ts @@ -1,10 +1,10 @@ import { Controller, ForbiddenException, Req, Sse } from '@nestjs/common'; import { Observable } from 'rxjs'; -import { SseService } from './sse.service'; +import { SseService } from './sseService'; import { Request } from 'express'; @Controller('sse') -export class SseController { +export class NotificationsSseController { constructor(private readonly sseService: SseService) {} @Sse('notifications') diff --git a/src/shared/infrastructure/sse/sse.service.ts b/src/api/sse/sseService.ts similarity index 100% rename from src/shared/infrastructure/sse/sse.service.ts rename to src/api/sse/sseService.ts diff --git a/src/shared/infrastructure/nestjs/buses/errors/unhandledExceptionsBusHandler.ts b/src/api/sse/unhandledExceptionsBusService.ts similarity index 87% rename from src/shared/infrastructure/nestjs/buses/errors/unhandledExceptionsBusHandler.ts rename to src/api/sse/unhandledExceptionsBusService.ts index 7a454882..02ced7ff 100644 --- a/src/shared/infrastructure/nestjs/buses/errors/unhandledExceptionsBusHandler.ts +++ b/src/api/sse/unhandledExceptionsBusService.ts @@ -1,10 +1,10 @@ import { Injectable } from '@nestjs/common'; import { UnhandledExceptionBus } from '@nestjs/cqrs'; -import { SseService } from '@src/shared/infrastructure/sse/sse.service'; +import { SseService } from '@src/api/sse/sseService'; import { Subject, takeUntil } from 'rxjs'; @Injectable() -export class UnhandledExceptionsBusHandler { +export class UnhandledExceptionsBusService { private destroy$ = new Subject(); constructor(private readonly unhandledExceptionsBus: UnhandledExceptionBus, private readonly sseService: SseService) { diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostController.ts b/src/api/v1/controllers/auth/loginPostController.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostController.ts rename to src/api/v1/controllers/auth/loginPostController.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostDto.ts b/src/api/v1/controllers/auth/loginPostDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostDto.ts rename to src/api/v1/controllers/auth/loginPostDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostResponseDto.ts b/src/api/v1/controllers/auth/loginPostResponseDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/loginPostResponseDto.ts rename to src/api/v1/controllers/auth/loginPostResponseDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/meGetController.ts b/src/api/v1/controllers/auth/meGetController.ts similarity index 92% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/meGetController.ts rename to src/api/v1/controllers/auth/meGetController.ts index 54ae28d8..dc00ea0b 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/auth/meGetController.ts +++ b/src/api/v1/controllers/auth/meGetController.ts @@ -1,7 +1,7 @@ import { Request } from 'express'; import FindUserQuery from '@src/languages/application/user/query/find/findUserQuery'; import { Controller, Get, HttpCode, Inject, Req, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import MeGetResponseDto from './meGetResponseDto'; import { ApiBadRequestResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/meGetResponseDto.ts b/src/api/v1/controllers/auth/meGetResponseDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/meGetResponseDto.ts rename to src/api/v1/controllers/auth/meGetResponseDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostController.ts b/src/api/v1/controllers/auth/refreshTokenPostController.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostController.ts rename to src/api/v1/controllers/auth/refreshTokenPostController.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostDto.ts b/src/api/v1/controllers/auth/refreshTokenPostDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostDto.ts rename to src/api/v1/controllers/auth/refreshTokenPostDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostResponseDto.ts b/src/api/v1/controllers/auth/refreshTokenPostResponseDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/auth/refreshTokenPostResponseDto.ts rename to src/api/v1/controllers/auth/refreshTokenPostResponseDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/countries/countriesGetController.ts b/src/api/v1/controllers/countries/countriesGetController.ts similarity index 92% rename from src/languages/infrastructure/ui/api/v1/controllers/countries/countriesGetController.ts rename to src/api/v1/controllers/countries/countriesGetController.ts index 41ffbd8e..ca4ea5a4 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/countries/countriesGetController.ts +++ b/src/api/v1/controllers/countries/countriesGetController.ts @@ -1,6 +1,6 @@ import FindCountriesQuery from '@src/languages/application/country/query/findAll/findCountriesQuery'; import { Controller, Get, HttpCode, Inject, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import CountryGetResponseDto from './countryGetResponse'; import { ApiBadRequestResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryGetController.ts b/src/api/v1/controllers/countries/countryGetController.ts similarity index 92% rename from src/languages/infrastructure/ui/api/v1/controllers/countries/countryGetController.ts rename to src/api/v1/controllers/countries/countryGetController.ts index fd1dff6a..66cb618c 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryGetController.ts +++ b/src/api/v1/controllers/countries/countryGetController.ts @@ -1,6 +1,6 @@ import FindCountryQuery from '@src/languages/application/country/query/find/findCountryQuery'; import { Controller, Get, HttpCode, Inject, Param, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import CountryGetResponseDto from './countryGetResponse'; import { ApiBadRequestResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryGetResponse.ts b/src/api/v1/controllers/countries/countryGetResponse.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/countries/countryGetResponse.ts rename to src/api/v1/controllers/countries/countryGetResponse.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryPostController.ts b/src/api/v1/controllers/countries/countryPostController.ts similarity index 94% rename from src/languages/infrastructure/ui/api/v1/controllers/countries/countryPostController.ts rename to src/api/v1/controllers/countries/countryPostController.ts index eb514067..d4ec8536 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryPostController.ts +++ b/src/api/v1/controllers/countries/countryPostController.ts @@ -2,7 +2,7 @@ import CreateCountryCommand from '@src/languages/application/country/command/cre import { LanguagePrimitives } from '@src/languages/domain/country/valueObjects/language'; import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common'; import CountryPostDto from './countryPostDto'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiCreatedResponse, ApiBadRequestResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/countries/countryPostDto.ts b/src/api/v1/controllers/countries/countryPostDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/countries/countryPostDto.ts rename to src/api/v1/controllers/countries/countryPostDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/expressions/expressionPostController.ts b/src/api/v1/controllers/expressions/expressionPostController.ts similarity index 94% rename from src/languages/infrastructure/ui/api/v1/controllers/expressions/expressionPostController.ts rename to src/api/v1/controllers/expressions/expressionPostController.ts index 306ab6b1..c6ee2dd8 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/expressions/expressionPostController.ts +++ b/src/api/v1/controllers/expressions/expressionPostController.ts @@ -2,7 +2,7 @@ import CreateExpressionCommand from '@src/languages/application/expression/comma import { ExpressionTermPrimitives } from '@src/languages/domain/expression/valueObjects/expressionTerm'; import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common'; import ExpressionPostDto from './expressionPostDto'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiBadRequestResponse, ApiCreatedResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/expressions/expressionPostDto.ts b/src/api/v1/controllers/expressions/expressionPostDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/expressions/expressionPostDto.ts rename to src/api/v1/controllers/expressions/expressionPostDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/terms/findSuggestionsTermController.ts b/src/api/v1/controllers/terms/findSuggestionsTermController.ts similarity index 93% rename from src/languages/infrastructure/ui/api/v1/controllers/terms/findSuggestionsTermController.ts rename to src/api/v1/controllers/terms/findSuggestionsTermController.ts index 511cf880..e4e1afd0 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/terms/findSuggestionsTermController.ts +++ b/src/api/v1/controllers/terms/findSuggestionsTermController.ts @@ -1,6 +1,6 @@ import { Request } from 'express'; import { Controller, Get, HttpCode, Inject, Req, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/terms/searchTermsGetController.ts b/src/api/v1/controllers/terms/searchTermsGetController.ts similarity index 92% rename from src/languages/infrastructure/ui/api/v1/controllers/terms/searchTermsGetController.ts rename to src/api/v1/controllers/terms/searchTermsGetController.ts index 2b10e01c..1d04111d 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/terms/searchTermsGetController.ts +++ b/src/api/v1/controllers/terms/searchTermsGetController.ts @@ -1,6 +1,6 @@ import SearchTermQuery from '@src/languages/application/term/query/search/searchTermQuery'; import { Controller, Get, HttpCode, Inject, Param, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/terms/termResponse.ts b/src/api/v1/controllers/terms/termResponse.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/terms/termResponse.ts rename to src/api/v1/controllers/terms/termResponse.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/terms/termsResponse.ts b/src/api/v1/controllers/terms/termsResponse.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/terms/termsResponse.ts rename to src/api/v1/controllers/terms/termsResponse.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/user/userPutController.ts b/src/api/v1/controllers/user/userPutController.ts similarity index 86% rename from src/languages/infrastructure/ui/api/v1/controllers/user/userPutController.ts rename to src/api/v1/controllers/user/userPutController.ts index c2fa2206..a374eda8 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/user/userPutController.ts +++ b/src/api/v1/controllers/user/userPutController.ts @@ -1,5 +1,5 @@ import { Body, Controller, HttpCode, HttpStatus, Inject, Put, Req, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiBadRequestResponse, ApiInternalServerErrorResponse, @@ -8,9 +8,9 @@ import { ApiUnauthorizedResponse, } from '@nestjs/swagger'; import { COMMAND_BUS, CommandBus } from '@src/shared/domain/buses/commandBus/commandBus'; -import UserPutDto from '@src/languages/infrastructure/ui/api/v1/controllers/user/userPutDto'; import { Request } from 'express'; import UpdateUserCommand from '@src/languages/application/user/command/update/updateUserCommand'; +import UserPutDto from '@src/api/v1/controllers/user/userPutDto'; @ApiTags('User') @Controller() diff --git a/src/languages/infrastructure/ui/api/v1/controllers/user/userPutDto.ts b/src/api/v1/controllers/user/userPutDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/user/userPutDto.ts rename to src/api/v1/controllers/user/userPutDto.ts diff --git a/src/languages/infrastructure/ui/api/v1/controllers/words/wordPostController.ts b/src/api/v1/controllers/words/wordPostController.ts similarity index 94% rename from src/languages/infrastructure/ui/api/v1/controllers/words/wordPostController.ts rename to src/api/v1/controllers/words/wordPostController.ts index b82b28fb..19dbda0d 100644 --- a/src/languages/infrastructure/ui/api/v1/controllers/words/wordPostController.ts +++ b/src/api/v1/controllers/words/wordPostController.ts @@ -2,7 +2,7 @@ import CreateWordCommand from '@src/languages/application/word/command/create/cr import { WordTermPrimitives } from '@src/languages/domain/word/valueObjects/wordTerm'; import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common'; import WordPostDto from './wordPostDto'; -import { JwtAuthGuard } from '@src/shared/infrastructure/nestjs/guards/jwtAuthGuard'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; import { ApiCreatedResponse, ApiBadRequestResponse, diff --git a/src/languages/infrastructure/ui/api/v1/controllers/words/wordPostDto.ts b/src/api/v1/controllers/words/wordPostDto.ts similarity index 100% rename from src/languages/infrastructure/ui/api/v1/controllers/words/wordPostDto.ts rename to src/api/v1/controllers/words/wordPostDto.ts diff --git a/src/app.module.ts b/src/app.module.ts index b2995416..cd8a602e 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common'; -import { LanguageModule } from './languages/infrastructure/nestjs/language.module'; -import { SharedModule } from './shared/infrastructure/nestjs/shared.module'; +import { LanguageModule } from './languages/language.module'; +import { SharedModule } from './shared/shared.module'; @Module({ imports: [SharedModule, LanguageModule], diff --git a/src/languages/infrastructure/nestjs/controllers.ts b/src/languages/infrastructure/nestjs/controllers.ts deleted file mode 100644 index a7d3c73a..00000000 --- a/src/languages/infrastructure/nestjs/controllers.ts +++ /dev/null @@ -1,25 +0,0 @@ -import LoginPostController from '../ui/api/v1/controllers/auth/loginPostController'; -import MeGetController from '../ui/api/v1/controllers/auth/meGetController'; -import SearchTermsGetController from '../ui/api/v1/controllers/terms/searchTermsGetController'; -import WordPostController from '../ui/api/v1/controllers/words/wordPostController'; -import ExpressionPostController from '../ui/api/v1/controllers/expressions/expressionPostController'; -import CountriesGetController from '../ui/api/v1/controllers/countries/countriesGetController'; -import CountryGetController from '../ui/api/v1/controllers/countries/countryGetController'; -import CountryPostController from '../ui/api/v1/controllers/countries/countryPostController'; -import RefreshTokenPostController from '../ui/api/v1/controllers/auth/refreshTokenPostController'; -import FindSuggestionsTermController from '@src/languages/infrastructure/ui/api/v1/controllers/terms/findSuggestionsTermController'; -import UserPutController from '@src/languages/infrastructure/ui/api/v1/controllers/user/userPutController'; - -export const controllers = [ - LoginPostController, - RefreshTokenPostController, - MeGetController, - SearchTermsGetController, - FindSuggestionsTermController, - WordPostController, - ExpressionPostController, - CountriesGetController, - CountryGetController, - CountryPostController, - UserPutController, -]; diff --git a/src/languages/infrastructure/nestjs/language.module.ts b/src/languages/infrastructure/nestjs/language.module.ts deleted file mode 100644 index 672206e7..00000000 --- a/src/languages/infrastructure/nestjs/language.module.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Module } from '@nestjs/common'; -import { controllers } from './controllers'; -import { services } from './services'; -import { repositories } from './repositories'; -import { commands } from './commandHandlers'; -import { queries } from './queryHandlers'; -import { events } from './eventHandlers'; -import { projections } from '@src/languages/infrastructure/nestjs/projectionHandlers'; -import { readLayers } from '@src/languages/infrastructure/nestjs/readLayers'; - -@Module({ - imports: [], - controllers, - providers: [...services, ...commands, ...queries, ...events, ...projections, ...repositories, ...readLayers], -}) -export class LanguageModule {} diff --git a/src/languages/infrastructure/nestjs/services.ts b/src/languages/infrastructure/nestjs/services.ts deleted file mode 100644 index a5a19b4c..00000000 --- a/src/languages/infrastructure/nestjs/services.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SOCIAL_AUTHENTICATOR } from '@src/languages/domain/auth/socialAuthenticator'; -import GoogleSocialAuthenticator from '../oauth/googleSocialAuthenticator'; - -export const services = [ - { - provide: SOCIAL_AUTHENTICATOR, - useClass: GoogleSocialAuthenticator, - }, -]; diff --git a/src/languages/language.module.ts b/src/languages/language.module.ts new file mode 100644 index 00000000..ab4e86db --- /dev/null +++ b/src/languages/language.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { controllers } from '../api/dependencyInjection/controllers'; +import { services } from '../api/dependencyInjection/services'; +import { repositories } from '../api/dependencyInjection/repositories'; +import { commands } from '../api/dependencyInjection/commandHandlers'; +import { queries } from '../api/dependencyInjection/queryHandlers'; +import { events } from '../api/dependencyInjection/eventHandlers'; +import { projections } from '@src/api/dependencyInjection/projectionHandlers'; +import { readLayers } from '@src/api/dependencyInjection/readLayers'; + +@Module({ + imports: [], + controllers, + providers: [...services, ...commands, ...queries, ...events, ...projections, ...repositories, ...readLayers], +}) +export class LanguageModule {} diff --git a/src/shared/infrastructure/nestjs/strategies/jwtStrategy.ts b/src/shared/infrastructure/auth/strategies/jwtStrategy.ts similarity index 100% rename from src/shared/infrastructure/nestjs/strategies/jwtStrategy.ts rename to src/shared/infrastructure/auth/strategies/jwtStrategy.ts diff --git a/src/shared/infrastructure/nestjs/buses/nestCommandBus.ts b/src/shared/infrastructure/buses/nestCommandBus.ts similarity index 100% rename from src/shared/infrastructure/nestjs/buses/nestCommandBus.ts rename to src/shared/infrastructure/buses/nestCommandBus.ts diff --git a/src/shared/infrastructure/nestjs/buses/nestEventBus.ts b/src/shared/infrastructure/buses/nestEventBus.ts similarity index 100% rename from src/shared/infrastructure/nestjs/buses/nestEventBus.ts rename to src/shared/infrastructure/buses/nestEventBus.ts diff --git a/src/shared/infrastructure/nestjs/buses/nestProjectionBus.ts b/src/shared/infrastructure/buses/nestProjectionBus.ts similarity index 100% rename from src/shared/infrastructure/nestjs/buses/nestProjectionBus.ts rename to src/shared/infrastructure/buses/nestProjectionBus.ts diff --git a/src/shared/infrastructure/nestjs/buses/nestQueryBus.ts b/src/shared/infrastructure/buses/nestQueryBus.ts similarity index 100% rename from src/shared/infrastructure/nestjs/buses/nestQueryBus.ts rename to src/shared/infrastructure/buses/nestQueryBus.ts diff --git a/src/shared/infrastructure/nestjs/logger/logger.ts b/src/shared/infrastructure/logger/nestLogger.ts similarity index 84% rename from src/shared/infrastructure/nestjs/logger/logger.ts rename to src/shared/infrastructure/logger/nestLogger.ts index bb2f949a..7a318a17 100644 --- a/src/shared/infrastructure/nestjs/logger/logger.ts +++ b/src/shared/infrastructure/logger/nestLogger.ts @@ -1,9 +1,9 @@ -import LoggerInterface from '../../../domain/loggerInterface'; +import LoggerInterface from '../../domain/loggerInterface'; import { Injectable, Logger as NestJsLogger } from '@nestjs/common'; import * as winston from 'winston'; @Injectable() -export default class Logger extends NestJsLogger implements LoggerInterface { +export default class NestLogger extends NestJsLogger implements LoggerInterface { private readonly logger: winston.Logger; constructor() { diff --git a/src/shared/infrastructure/nestjs/buses/events/persistEventsHandler.ts b/src/shared/infrastructure/subscribers/persistDomainEventsSuscriber.ts similarity index 89% rename from src/shared/infrastructure/nestjs/buses/events/persistEventsHandler.ts rename to src/shared/infrastructure/subscribers/persistDomainEventsSuscriber.ts index c8fa2d59..98aa61db 100644 --- a/src/shared/infrastructure/nestjs/buses/events/persistEventsHandler.ts +++ b/src/shared/infrastructure/subscribers/persistDomainEventsSuscriber.ts @@ -7,7 +7,7 @@ import { mongoTransactionalOperation } from '@src/shared/infrastructure/persiste import { Subject, takeUntil } from 'rxjs'; @Injectable() -export class PersistEventsHandler { +export class PersistDomainEventsSuscriber { private destroy$ = new Subject(); constructor( @@ -15,7 +15,7 @@ export class PersistEventsHandler { @Inject(EVENT_STORE_REPOSITORY) private eventStoreRepository: EventStoreRepository, ) { this.eventBus.pipe(takeUntil(this.destroy$)).subscribe((event) => { - mongoTransactionalOperation(async (event: DomainEvent) => { + void mongoTransactionalOperation(async (event: DomainEvent) => { void this.eventStoreRepository.save(event); }, event as DomainEvent); }); diff --git a/src/shared/infrastructure/nestjs/shared.module.ts b/src/shared/shared.module.ts similarity index 62% rename from src/shared/infrastructure/nestjs/shared.module.ts rename to src/shared/shared.module.ts index 1e32539e..c1921496 100644 --- a/src/shared/infrastructure/nestjs/shared.module.ts +++ b/src/shared/shared.module.ts @@ -1,25 +1,22 @@ import { Global, Module } from '@nestjs/common'; import { COMMAND_BUS } from '@src/shared/domain/buses/commandBus/commandBus'; import { LOGGER_INTERFACE } from '@src/shared/domain/loggerInterface'; -import NestCommandBus from './buses/nestCommandBus'; -import NestEventBus from './buses/nestEventBus'; +import NestCommandBus from '@src/shared/infrastructure/buses/nestCommandBus'; +import NestEventBus from '@src/shared/infrastructure/buses/nestEventBus'; import { EVENT_BUS } from '@src/shared/domain/buses/eventBus/eventBus'; -import Logger from './logger/logger'; -import { JwtAuthGuard } from './guards/jwtAuthGuard'; -import { JwtStrategy } from './strategies/jwtStrategy'; +import NestLogger from '@src/shared/infrastructure/logger/nestLogger'; +import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard'; +import { JwtStrategy } from '@src/shared/infrastructure/auth/strategies/jwtStrategy'; import { JwtModule } from '@nestjs/jwt'; import { APP_FILTER } from '@nestjs/core'; -import { ErrorFilter } from './filters/errorFilter'; +import { ErrorFilter } from '@src/api/filters/errorFilter'; import { CqrsModule } from '@nestjs/cqrs'; import { QUERY_BUS } from '@src/shared/domain/buses/queryBus/queryBus'; -import NestQueryBusBus from './buses/nestQueryBus'; -import { SseService } from '../sse/sse.service'; -import { SseController } from '../sse/sse.controller'; -import { UnhandledExceptionsBusHandler } from './buses/errors/unhandledExceptionsBusHandler'; +import NestQueryBusBus from '@src/shared/infrastructure/buses/nestQueryBus'; import { EVENT_STORE_REPOSITORY } from '@src/shared/domain/eventStore/eventStoreRepository'; -import MongoEventStoreRepository from '../persistence/mongo/repositories/mongoEventStoreRepository'; -import { PersistEventsHandler } from './buses/events/persistEventsHandler'; -import NestProjectionBus from '@src/shared/infrastructure/nestjs/buses/nestProjectionBus'; +import MongoEventStoreRepository from './infrastructure/persistence/mongo/repositories/mongoEventStoreRepository'; +import { PersistDomainEventsSuscriber } from '@src/shared/infrastructure/subscribers/persistDomainEventsSuscriber'; +import NestProjectionBus from '@src/shared/infrastructure/buses/nestProjectionBus'; import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectionBus'; @Global() @@ -31,10 +28,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio }), CqrsModule, ], - controllers: [SseController], providers: [ - SseService, - UnhandledExceptionsBusHandler, JwtAuthGuard, JwtStrategy, { @@ -43,7 +37,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio }, { provide: LOGGER_INTERFACE, - useClass: Logger, + useClass: NestLogger, }, { provide: COMMAND_BUS, @@ -65,7 +59,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio provide: EVENT_STORE_REPOSITORY, useClass: MongoEventStoreRepository, }, - PersistEventsHandler, + PersistDomainEventsSuscriber, ], exports: [ JwtAuthGuard,