Skip to content

Commit

Permalink
Merge pull request #77 from mapeveri/chore/refactor-consumer
Browse files Browse the repository at this point in the history
Refactor folders
  • Loading branch information
mapeveri authored Jan 2, 2024
2 parents 3837541 + cf99c30 commit 3448ea6
Show file tree
Hide file tree
Showing 44 changed files with 144 additions and 131 deletions.
29 changes: 0 additions & 29 deletions src/api/dependencyInjection/controllers.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/api/dependencyInjection/services.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/languages/_dependencyInjection/controllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import LoginPostController from '@src/languages/infrastructure/api/v1/controllers/auth/loginPostController';
import RefreshTokenPostController from '@src/languages/infrastructure/api/v1/controllers/auth/refreshTokenPostController';
import MeGetController from '@src/languages/infrastructure/api/v1/controllers/auth/meGetController';
import SearchTermsGetController from '@src/languages/infrastructure/api/v1/controllers/terms/searchTermsGetController';
import FindSuggestionsTermController from '@src/languages/infrastructure/api/v1/controllers/terms/findSuggestionsTermController';
import WordPostController from '@src/languages/infrastructure/api/v1/controllers/words/wordPostController';
import ExpressionPostController from '@src/languages/infrastructure/api/v1/controllers/expressions/expressionPostController';
import CountriesGetController from '@src/languages/infrastructure/api/v1/controllers/countries/countriesGetController';
import CountryGetController from '@src/languages/infrastructure/api/v1/controllers/countries/countryGetController';
import CountryPostController from '@src/languages/infrastructure/api/v1/controllers/countries/countryPostController';
import UserPutController from '@src/languages/infrastructure/api/v1/controllers/user/userPutController';

export const controllers = [
LoginPostController,
RefreshTokenPostController,
MeGetController,
SearchTermsGetController,
FindSuggestionsTermController,
WordPostController,
ExpressionPostController,
CountriesGetController,
CountryGetController,
CountryPostController,
UserPutController,
];
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AUTH_SESSION_REPOSITORY } from '@src/languages/domain/auth/authSessionRepository';
import TypeOrmAuthSessionRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmAuthSessionRepository';
import TypeOrmAuthSessionRepository from '../infrastructure/persistence/typeOrm/repositories/typeOrmAuthSessionRepository';
import { COUNTRY_REPOSITORY } from '@src/languages/domain/country/countryRepository';
import TypeOrmCountryRepository from '../../languages/infrastructure/persistence/typeOrm/repositories/typeOrmCountryRepository';
import TypeOrmCountryRepository from '../infrastructure/persistence/typeOrm/repositories/typeOrmCountryRepository';
import { EXPRESSION_REPOSITORY } from '@src/languages/domain/expression/expressionRepository';
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 TypeOrmExpressionRepository from '../infrastructure/persistence/typeOrm/repositories/typeOrmExpressionRepository';
import TypeOrmWordRepository from '../infrastructure/persistence/typeOrm/repositories/typeOrmWordRepository';
import TypeOrmUserRepository from '../infrastructure/persistence/typeOrm/repositories/typeOrmUserRepository';
import { TERM_REPOSITORY } from '@src/languages/domain/term/termRepository';
import MongoTermRepository from '../../languages/infrastructure/persistence/mongo/repositories/mongoTermRepository';
import MongoTermRepository from '../infrastructure/persistence/mongo/repositories/mongoTermRepository';
import { USER_REPOSITORY } from '@src/languages/domain/user/userRepository';
import { WORD_REPOSITORY } from '@src/languages/domain/word/wordRepository';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import MeGetResponseDto from './meGetResponseDto';
import {
ApiBadRequestResponse,
Expand All @@ -23,7 +23,7 @@ export default class MeGetController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Req() req: Request): Promise<MeGetResponseDto> {
const userId = req.user['id'];
const data = await this.queryBus.ask(new FindUserQuery(userId));
Expand Down
Original file line number Diff line number Diff line change
@@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import CountryGetResponseDto from './countryGetResponse';
import {
ApiBadRequestResponse,
Expand All @@ -22,7 +22,7 @@ export default class CountriesGetController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(): Promise<CountryGetResponseDto[]> {
const data = await this.queryBus.ask(new FindCountriesQuery());
return data.content;
Expand Down
Original file line number Diff line number Diff line change
@@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import CountryGetResponseDto from './countryGetResponse';
import {
ApiBadRequestResponse,
Expand All @@ -22,7 +22,7 @@ export default class CountryGetController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Param('id') id: string): Promise<CountryGetResponseDto> {
const data = await this.queryBus.ask(new FindCountryQuery(id));
return data.content || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiCreatedResponse,
ApiBadRequestResponse,
Expand All @@ -23,7 +23,7 @@ export default class CountryPostController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Body() payload: CountryPostDto): Promise<any> {
const languages: Array<LanguagePrimitives> = payload.languages;
await this.commandBus.dispatch(new CreateCountryCommand(payload.id, payload.name, payload.iso, languages));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiBadRequestResponse,
ApiCreatedResponse,
Expand All @@ -23,7 +23,7 @@ export default class ExpressionPostController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Body() payload: ExpressionPostDto): Promise<any> {
const expressionTerms: Array<ExpressionTermPrimitives> = payload.terms;
await this.commandBus.dispatch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request } from 'express';
import { Controller, Get, HttpCode, Inject, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
Expand All @@ -23,7 +23,7 @@ export default class FindSuggestionsTermController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Req() req: Request): Promise<any> {
const userId = req.user['id'];

Expand Down
Original file line number Diff line number Diff line change
@@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
Expand All @@ -22,7 +22,7 @@ export default class SearchTermsGetController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Param('term') term: string): Promise<any> {
return await this.queryBus.ask(new SearchTermQuery(term));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, HttpCode, HttpStatus, Inject, Put, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
Expand All @@ -10,7 +10,7 @@ import {
import { COMMAND_BUS, CommandBus } from '@src/shared/domain/buses/commandBus/commandBus';
import { Request } from 'express';
import UpdateUserCommand from '@src/languages/application/user/command/update/updateUserCommand';
import UserPutDto from '@src/api/v1/controllers/user/userPutDto';
import UserPutDto from '@src/languages/infrastructure/api/v1/controllers/user/userPutDto';

@ApiTags('User')
@Controller()
Expand All @@ -23,7 +23,7 @@ export default class UserPutController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Req() req: Request, @Body() payload: UserPutDto): Promise<any> {
const userId = req.user['id'];
await this.commandBus.dispatch(new UpdateUserCommand(userId, payload.name, payload.photo, payload.interests));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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/api/guards/jwtAuthGuard';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import {
ApiCreatedResponse,
ApiBadRequestResponse,
Expand All @@ -23,7 +23,7 @@ export default class WordPostController {
@ApiBadRequestResponse({ description: 'Bad Request.' })
@ApiUnauthorizedResponse({ description: 'Unauthorized.' })
@ApiInternalServerErrorResponse({ description: 'Internal Server Error.' })
@UseGuards(JwtAuthGuard)
@UseGuards(NestJwtAuthGuard)
async run(@Body() payload: WordPostDto): Promise<any> {
const wordTerms: Array<WordTermPrimitives> = payload.terms;
await this.commandBus.dispatch(
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions src/languages/language.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +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';
import { controllers } from '@src/languages/_dependencyInjection/controllers';
import { services } from '@src/shared/_dependencyInjection/services';
import { repositories } from '@src/languages/_dependencyInjection/repositories';
import { commands } from '@src/languages/_dependencyInjection/commandHandlers';
import { queries } from '@src/languages/_dependencyInjection/queryHandlers';
import { events } from '@src/languages/_dependencyInjection/eventHandlers';
import { projections } from '@src/languages/_dependencyInjection/projectionHandlers';
import { readLayers } from '@src/languages/_dependencyInjection/readLayers';

@Module({
imports: [],
controllers,
controllers: [...controllers],
providers: [...services, ...commands, ...queries, ...events, ...projections, ...repositories, ...readLayers],
})
export class LanguageModule {}
3 changes: 3 additions & 0 deletions src/shared/_dependencyInjection/consumers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DomainEventsConsumerController } from '@src/shared/infrastructure/api/consumers/domainEvents/domainEventsConsumerController';

export const consumers = [DomainEventsConsumerController];
3 changes: 3 additions & 0 deletions src/shared/_dependencyInjection/controllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NotificationsSseController } from '@src/shared/infrastructure/api/sse/notificationsSseController';

export const controllers = [NotificationsSseController];
66 changes: 66 additions & 0 deletions src/shared/_dependencyInjection/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { SOCIAL_AUTHENTICATOR } from '@src/languages/domain/auth/socialAuthenticator';
import { SseService } from '@src/shared/infrastructure/api/sse/sseService';
import { UnhandledExceptionsBusService } from '@src/shared/infrastructure/api/sse/unhandledExceptionsBusService';
import GoogleSocialAuthenticator from '@src/languages/infrastructure/oauth/googleSocialAuthenticator';
import { NestJwtAuthGuard } from '@src/shared/infrastructure/api/guards/nestJwtAuthGuard';
import { JwtStrategy } from '@src/shared/infrastructure/auth/strategies/jwtStrategy';
import { APP_FILTER } from '@nestjs/core';
import { NestErrorFilter } from '@src/shared/infrastructure/api/filters/nestErrorFilter';
import { LOGGER_INTERFACE } from '@src/shared/domain/loggerInterface';
import NestLogger from '@src/shared/infrastructure/logger/nestLogger';
import { COMMAND_BUS } from '@src/shared/domain/buses/commandBus/commandBus';
import NestCommandBus from '@src/shared/infrastructure/bus/nestCommandBus';
import { ASYNC_EVENT_BUS, EVENT_BUS } from '@src/shared/domain/buses/eventBus/eventBus';
import NestEventBus from '@src/shared/infrastructure/bus/nestEventBus';
import { RabbitMqEventBus } from '@src/shared/infrastructure/bus/rabbitMq/rabbitMqEventBus';
import { QUERY_BUS } from '@src/shared/domain/buses/queryBus/queryBus';
import NestQueryBusBus from '@src/shared/infrastructure/bus/nestQueryBus';
import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectionBus';
import NestProjectionBus from '@src/shared/infrastructure/bus/nestProjectionBus';
import { EVENT_STORE_REPOSITORY } from '@src/shared/domain/eventStore/eventStoreRepository';
import MongoEventStoreRepository from '@src/shared/infrastructure/persistence/mongo/repositories/mongoEventStoreRepository';
import { PersistDomainEventsSuscriber } from '@src/shared/infrastructure/subscribers/persistDomainEventsSuscriber';

export const services = [
SseService,
UnhandledExceptionsBusService,
NestJwtAuthGuard,
JwtStrategy,
{
provide: APP_FILTER,
useClass: NestErrorFilter,
},
{
provide: LOGGER_INTERFACE,
useClass: NestLogger,
},
{
provide: COMMAND_BUS,
useClass: NestCommandBus,
},
{
provide: EVENT_BUS,
useClass: NestEventBus,
},
{
provide: ASYNC_EVENT_BUS,
useClass: RabbitMqEventBus,
},
{
provide: QUERY_BUS,
useClass: NestQueryBusBus,
},
{
provide: PROJECTION_BUS,
useClass: NestProjectionBus,
},
{
provide: EVENT_STORE_REPOSITORY,
useClass: MongoEventStoreRepository,
},
PersistDomainEventsSuscriber,
{
provide: SOCIAL_AUTHENTICATOR,
useClass: GoogleSocialAuthenticator,
},
];
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
import { Response } from 'express';
import ApiExceptionSerializer from '@src/api/serializers/apiExceptionSerializer';
import ApiExceptionSerializer from '@src/shared/infrastructure/api/serializers/apiExceptionSerializer';
import DomainException from '@src/shared/domain/exceptions/domainException';

@Catch(Error)
export class ErrorFilter implements ExceptionFilter {
export class NestErrorFilter implements ExceptionFilter {
catch(exception: Error, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JwtService } from '@nestjs/jwt';
import { Request } from 'express';

@Injectable()
export class JwtAuthGuard implements CanActivate {
export class NestJwtAuthGuard implements CanActivate {
constructor(private jwtService: JwtService) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3448ea6

Please sign in to comment.