Skip to content

Commit

Permalink
Merge pull request #27 from maick05/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
maick05 authored Aug 22, 2022
2 parents 87a9efd + a757cff commit e376d6d
Show file tree
Hide file tree
Showing 166 changed files with 7,192 additions and 346 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ All notable changes to this project will be documented in this file.
- Optimize Neighborhoods by State
- Sort Collections result

## [0.0.6] - 2022-08-03
## [0.0.6] - 2022-08-04

### Added

Expand All @@ -54,3 +54,15 @@ All notable changes to this project will be documented in this file.
- Async Seed Neighborhoods By State Job
- Fix regex filter in mongodb query
- Secrets and docker container process in GitHub Actions

## [0.0.7] - 2022-08-21

### Added

- LogExecution Schema
- LogAction Schema
- Route Request Resolution
- Route Regions By Country
- Route Seed Neighborhoods By Country
- Seed Regions By Puppeteer
- Seed Neighborhoods By State Queue
28 changes: 23 additions & 5 deletions config/yaml/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ repository:
neighborhoods:
guia-mais:
url: 'https://www.guiamais.com.br/bairros'
regions:
citypopulation:
url: 'https://www.citypopulation.de'
database:
mongodb:
connection: 'mongodb+srv://${MONGODB_USER}:${MONGODB_PASSWORD}@${MONGODB_URL_CONNECTION}${MONGODB_DATABASE_NAME}${MONGODB_SUFIX_PARAMS}'
microservices:
rabbitmq:
url: 'amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@${RABBITMQ_HOST}/${RABBITMQ_VHOST}'
queue:
connection: 'places-queue'
messages: 'seed-messages'
success: 'seed-success'
error: 'seed-error'
connection: 'places-connection'
seed:
neighborhoods:
by:
city:
process: 'seed-neighborhoods-by-city-process'
success: 'seed-neighborhoods-by-city-success'
error: 'seed-neighborhoods-by-city-error'
state:
process: 'seed-neighborhoods-by-state-process'
exchange:
seed:
neighborhoods:
Expand All @@ -21,8 +30,17 @@ microservices:
process: 'seed-neighborhoods-by-city-process'
success: 'seed-neighborhoods-by-city-success'
error: 'seed-neighborhoods-by-city-error'
state:
process: 'seed-neighborhoods-by-state-process'
channel:
prefetch-count: 1
seed:
neighborhoods:
by:
city: 'channel-seed-neighborhoods-by-city'
state: 'channel-seed-neighborhoods-by-state'
api:
port: 3000
doc:
version: 0.0.6
version: 0.0.7
name: 'places'
8 changes: 6 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { CountriesModule } from './microservice/adapter/module/countries.module'
import { ExtensionsModule } from './microservice/adapter/helper/extensions/exensions.module';
import { CustomPuppeteerModule } from './microservice/adapter/helper/modules/custom-puppeteer.module';
import { NeighborhoodsModule } from './microservice/adapter/module/neighborhoods.module';
import { SeedModule } from './microservice/adapter/module/seed.module';
import { SeedNeighborhoodsModule } from './microservice/adapter/module/seed/seed-neighborhoods.module';
import { StatesModule } from './microservice/adapter/module/states.module';
import { ResolutionsModule } from './microservice/adapter/module/resolution.module';
import { SeedRegionsModule } from './microservice/adapter/module/seed/seed-regions.module';

@Module({
imports: [
Expand All @@ -31,7 +33,9 @@ import { StatesModule } from './microservice/adapter/module/states.module';
CitiesModule,
StatesModule,
CountriesModule,
SeedModule
SeedNeighborhoodsModule,
ResolutionsModule,
SeedRegionsModule
],
controllers: [],
providers: [
Expand Down
3 changes: 2 additions & 1 deletion src/config/amqp/enum/enum-config-amqp.enumerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum EnumConfigAMQP {
QUEUE = 'microservices.rabbitmq.queue',
EVENT = 'microservices.rabbitmq.event',
EXCHANGE = 'microservices.rabbitmq.exchange'
EXCHANGE = 'microservices.rabbitmq.exchange',
CHANNEL = 'microservices.rabbitmq.channel'
}
35 changes: 35 additions & 0 deletions src/config/amqp/rabbitmq-channels.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ConfigHelper } from '../../microservice/adapter/helper/config/config.helper';
import { EnumConfigAMQP } from './enum/enum-config-amqp.enumerator';

export const CHANNEL_SEED_NEIGHBORHOODS_BY_CITY = ConfigHelper.getConfig(
'seed.neighborhoods.by.city',
EnumConfigAMQP.CHANNEL
);

export const CHANNEL_SEED_NEIGHBORHOODS_BY_STATE = ConfigHelper.getConfig(
'seed.neighborhoods.by.state',
EnumConfigAMQP.CHANNEL
);

const DEFAULT_CHANNEL = CHANNEL_SEED_NEIGHBORHOODS_BY_CITY;

const prefetchCount = ConfigHelper.getConfig(
'prefetch-count',
EnumConfigAMQP.CHANNEL
);

export const channelsConfig = mountChannels([
CHANNEL_SEED_NEIGHBORHOODS_BY_CITY,
CHANNEL_SEED_NEIGHBORHOODS_BY_STATE
]);

function mountChannels(arr) {
const channels = {};
arr.forEach((item) => {
channels[item] = {
prefetchCount,
default: item === DEFAULT_CHANNEL
};
});
return channels;
}
18 changes: 12 additions & 6 deletions src/config/amqp/rabbitmq-exchanges.config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { ConfigHelper } from '../../microservice/adapter/helper/config/config.helper';
import { EnumConfigAMQP } from './enum/enum-config-amqp.enumerator';

export const seedByCityProcess = ConfigHelper.getConfig(
export const seedNeighborhoodsByCityProcess = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.process',
EnumConfigAMQP.EXCHANGE
);

export const seedByCitySuccess = ConfigHelper.getConfig(
export const seedNeighborhoodsByCitySuccess = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.success',
EnumConfigAMQP.EXCHANGE
);

export const seedByCityError = ConfigHelper.getConfig(
export const seedNeighborhoodsByCityError = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.error',
EnumConfigAMQP.EXCHANGE
);

export const seedNeighborhoodsByStateProcess = ConfigHelper.getConfig(
'seed.neighborhoods.by.state.process',
EnumConfigAMQP.EXCHANGE
);

const type = 'topic';
export const arrExchanges = mountExchanges([
seedByCitySuccess,
seedByCityError,
seedByCityProcess
seedNeighborhoodsByCitySuccess,
seedNeighborhoodsByCityError,
seedNeighborhoodsByCityProcess,
seedNeighborhoodsByStateProcess
]);

function mountExchanges(arr) {
Expand Down
22 changes: 22 additions & 0 deletions src/config/amqp/rabbitmq-queues.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ConfigHelper } from '../../microservice/adapter/helper/config/config.helper';
import { EnumConfigAMQP } from './enum/enum-config-amqp.enumerator';

export const QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_CITY = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.process',
EnumConfigAMQP.QUEUE
);

export const QUEUE_SEED_SUCCESS_NEIGHBORHOODS_BY_CITY = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.success',
EnumConfigAMQP.QUEUE
);

export const QUEUE_SEED_ERROR_NEIGHBORHOODS_BY_CITY = ConfigHelper.getConfig(
'seed.neighborhoods.by.city.error',
EnumConfigAMQP.QUEUE
);

export const QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_STATE = ConfigHelper.getConfig(
'seed.neighborhoods.by.state.process',
EnumConfigAMQP.QUEUE
);
54 changes: 30 additions & 24 deletions src/config/amqp/rabbitmq-subscribe.config.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
import { ConfigHelper } from '../../microservice/adapter/helper/config/config.helper';
import { EnumConfigAMQP } from './enum/enum-config-amqp.enumerator';
import {
seedByCityError,
seedByCityProcess,
seedByCitySuccess
CHANNEL_SEED_NEIGHBORHOODS_BY_CITY,
CHANNEL_SEED_NEIGHBORHOODS_BY_STATE
} from './rabbitmq-channels.config';
import {
seedNeighborhoodsByCityError,
seedNeighborhoodsByCityProcess,
seedNeighborhoodsByCitySuccess,
seedNeighborhoodsByStateProcess
} from './rabbitmq-exchanges.config';

const QUEUE_SEED_MESSAGES = ConfigHelper.getConfig(
'messages',
EnumConfigAMQP.QUEUE
);

const QUEUE_SEED_SUCCESS = ConfigHelper.getConfig(
'success',
EnumConfigAMQP.QUEUE
);

const QUEUE_SEED_ERROR = ConfigHelper.getConfig('error', EnumConfigAMQP.QUEUE);
import {
QUEUE_SEED_ERROR_NEIGHBORHOODS_BY_CITY,
QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_CITY,
QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_STATE,
QUEUE_SEED_SUCCESS_NEIGHBORHOODS_BY_CITY
} from './rabbitmq-queues.config';

/* EXPORT */
export const routeKeySub = 'sub-1';

export const subscribeSeedByCityProcess = {
exchange: seedByCityProcess,
exchange: seedNeighborhoodsByCityProcess,
routingKey: routeKeySub,
queue: QUEUE_SEED_MESSAGES,
queue: QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_CITY,
queueOptions: {
channel: 'channel-1'
channel: CHANNEL_SEED_NEIGHBORHOODS_BY_CITY
}
};

export const subscribeSeedByCitySuccess = {
exchange: seedByCitySuccess,
exchange: seedNeighborhoodsByCitySuccess,
routingKey: routeKeySub,
queue: QUEUE_SEED_SUCCESS
queue: QUEUE_SEED_SUCCESS_NEIGHBORHOODS_BY_CITY
};

export const subscribeSeedByCityError = {
exchange: seedByCityError,
exchange: seedNeighborhoodsByCityError,
routingKey: routeKeySub,
queue: QUEUE_SEED_ERROR
queue: QUEUE_SEED_ERROR_NEIGHBORHOODS_BY_CITY
};

export const subscribeSeedByStateProcess = {
exchange: seedNeighborhoodsByStateProcess,
routingKey: routeKeySub,
queue: QUEUE_SEED_MESSAGE_NEIGHBORHOODS_BY_STATE,
queueOptions: {
channel: CHANNEL_SEED_NEIGHBORHOODS_BY_STATE
}
};
11 changes: 11 additions & 0 deletions src/core/error-handling/exception/resolution.exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HttpStatus } from '@nestjs/common';
import { CustomErrorException } from './custom-error.exception';

export class ResolutionException extends CustomErrorException {
constructor(
message: string,
status: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR
) {
super(message, status, 6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Controller, Get, HttpStatus, Param } from '@nestjs/common';
import { GetNeighborhoodsByStateService } from '../../domain/service/neighborhoods/get/get-neighborhoods-by-state.service';
import { NestResponse } from '../../../core/http/nest-response';
import { AbstractController } from '../../domain/controller/abstract-controller';
import { GetNeighborhoodsByCityService } from '../../domain/service/neighborhoods/get/get-neighborhoods-by-city.service';
import { SearchNeighborhoodsDTO } from '../../domain/model/search/neighborhoods/search-neighborhoods-dto.model';
import {
ApiOkResponse,
Expand All @@ -12,12 +11,13 @@ import {
} from '@nestjs/swagger';
import { NeighborhoodByCity } from '../../domain/model/neighborhoods/neighborhood-by-city.model';
import { NeighborhoodsByState } from '../../domain/model/neighborhoods/neighborhoods-by-state.model';
import { NeighborhoodsByCityService } from '../../domain/service/neighborhoods/neighborhoods-by-city.service';

@ApiTags('neighborhoods')
@Controller('neighborhoods')
export class NeighborhoodsController extends AbstractController {
constructor(
private readonly getNeighborhoodsByCityService: GetNeighborhoodsByCityService,
private readonly getNeighborhoodsByCityService: NeighborhoodsByCityService,
private readonly getNeighborhoodsByStateService: GetNeighborhoodsByStateService
) {
super();
Expand Down Expand Up @@ -55,7 +55,7 @@ export class NeighborhoodsController extends AbstractController {
): Promise<NestResponse> {
return this.buildResponse(
HttpStatus.OK,
await this.getNeighborhoodsByCityService.getNeighborhoodsByCity(params)
await this.getNeighborhoodsByCityService.getFindAndSeedElements(params)
);
}

Expand Down
26 changes: 26 additions & 0 deletions src/microservice/adapter/controller/regions.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller, Get, HttpStatus, Param } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { RegionsByCountryService } from '../../domain/service/regions/regions-by-country.service';
import { NestResponse } from '../../../core/http/nest-response';
import { AbstractController } from '../../domain/controller/abstract-controller';
import { SearchRegionsDTO } from '../../domain/model/search/regions/search-regions-dto.model';

@ApiExcludeController()
@Controller('regions')
export class RegionsController extends AbstractController {
constructor(
private readonly getRegionsByCountryService: RegionsByCountryService
) {
super();
}

@Get('/:country')
async getRegionsByCountry(
@Param() params: SearchRegionsDTO
): Promise<NestResponse> {
return this.buildResponse(
HttpStatus.OK,
await this.getRegionsByCountryService.getFindAndSeedElements(params)
);
}
}
24 changes: 24 additions & 0 deletions src/microservice/adapter/controller/resolutions.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Body, Controller, HttpStatus, Post } from '@nestjs/common';
import { NestResponse } from '../../../core/http/nest-response';
import { AbstractController } from '../../domain/controller/abstract-controller';
import { ApiExcludeController } from '@nestjs/swagger';
import { ReferenceResolution } from '../../domain/model/references/reference-resolution.model';
import { ResolutionService } from '../../domain/service/resolution/resolution.service';

@ApiExcludeController()
@Controller('resolutions')
export class ResolutionController extends AbstractController {
constructor(private readonly resolutionService: ResolutionService) {
super();
}

@Post('/request')
async requestResolution(
@Body() msg: ReferenceResolution
): Promise<NestResponse> {
return this.buildResponse(
HttpStatus.OK,
await this.resolutionService.requestResolution(msg)
);
}
}
Loading

0 comments on commit e376d6d

Please sign in to comment.