Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create api folder #73 #74

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/api/dependencyInjection/controllers.ts
Original file line number Diff line number Diff line change
@@ -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,
];
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 '../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';

Expand Down
13 changes: 13 additions & 0 deletions src/api/dependencyInjection/services.ts
Original file line number Diff line number Diff line change
@@ -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,
},
];
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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<void>();

constructor(private readonly unhandledExceptionsBus: UnhandledExceptionBus, private readonly sseService: SseService) {
Expand Down
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import MeGetResponseDto from './meGetResponseDto';
import {
ApiBadRequestResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import CountryGetResponseDto from './countryGetResponse';
import {
ApiBadRequestResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import CountryGetResponseDto from './countryGetResponse';
import {
ApiBadRequestResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiCreatedResponse,
ApiBadRequestResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiBadRequestResponse,
ApiCreatedResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiBadRequestResponse,
ApiInternalServerErrorResponse,
Expand All @@ -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()
Expand Down
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/shared/infrastructure/nestjs/guards/jwtAuthGuard';
import { JwtAuthGuard } from '@src/api/guards/jwtAuthGuard';
import {
ApiCreatedResponse,
ApiBadRequestResponse,
Expand Down
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
25 changes: 0 additions & 25 deletions src/languages/infrastructure/nestjs/controllers.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/languages/infrastructure/nestjs/language.module.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/languages/infrastructure/nestjs/services.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/languages/language.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { mongoTransactionalOperation } from '@src/shared/infrastructure/persiste
import { Subject, takeUntil } from 'rxjs';

@Injectable()
export class PersistEventsHandler {
export class PersistDomainEventsSuscriber {
private destroy$ = new Subject<void>();

constructor(
private eventBus: EventBus,
@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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -31,10 +28,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio
}),
CqrsModule,
],
controllers: [SseController],
providers: [
SseService,
UnhandledExceptionsBusHandler,
JwtAuthGuard,
JwtStrategy,
{
Expand All @@ -43,7 +37,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio
},
{
provide: LOGGER_INTERFACE,
useClass: Logger,
useClass: NestLogger,
},
{
provide: COMMAND_BUS,
Expand All @@ -65,7 +59,7 @@ import { PROJECTION_BUS } from '@src/shared/domain/buses/projectionBus/projectio
provide: EVENT_STORE_REPOSITORY,
useClass: MongoEventStoreRepository,
},
PersistEventsHandler,
PersistDomainEventsSuscriber,
],
exports: [
JwtAuthGuard,
Expand Down
Loading