Skip to content

Commit

Permalink
Merge pull request #22 from maick05/feature/cities-states-countries-r…
Browse files Browse the repository at this point in the history
…outes

Feature/cities states countries routes
  • Loading branch information
maick05 authored Jun 28, 2022
2 parents b348170 + 68fea3e commit 40b8896
Show file tree
Hide file tree
Showing 93 changed files with 2,113 additions and 552 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ All notable changes to this project will be documented in this file.
- Route Neighborhoods By State
- Route Seed Neighborhoods By State
- logSeed Collection

## [0.0.5] - 2022-06-27

### Added

- Route Cities By State
- Route Cities By Country
- Route States By Country
- Route Countries
- Swagger Openapi automation
- Optmize Neighborhoods by State
- Sort Collections result
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

API to get Places by Local Names.

- Only Neighborhoods for now
- Neighborhoods
- Cities
- States
- Countries

## Installation

Expand Down Expand Up @@ -81,8 +84,16 @@ After run the server, make a get in browser, postman or similar
http://localhost:3000/neighborhoods/city/brazil/sc/orleans
## Neighborhoods By State example
http://localhost:3000/neighborhoods/city/brazil/sc
## Cities By State example
http://localhost:3000/cities/brazil/sc
## Cities By Country example
http://localhost:3000/cities/brazil
## States By Country example
http://localhost:3000/states/brazil
## Countries example
http://localhost:3000/countries/
```

[Swagger](https://app.swaggerhub.com/apis/dev-seeder/Places/1.0.0)
[Swagger](https://app.swaggerhub.com/apis/dev-seeder/Places/)

At the moment, it's working only for Brazilians cities and states.
At the moment, it's working only for Brazilians places.
2 changes: 2 additions & 0 deletions config/yaml/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ database:
connection: 'mongodb+srv://dev-seeder-root:hpYpxyjrKExNQviu@devseeder.v6xtv.mongodb.net/places?retryWrites=true&w=majority&ssl=true&wtimeoutMS=0'
api:
port: 3000
doc:
version: 0.0.5
96 changes: 95 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@nestjs/core": "^8.0.0",
"@nestjs/mongoose": "^9.1.0",
"@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1",
"chai": "^4.3.6",
"cheerio": "^1.0.0-rc.10",
"class-transformer": "^0.5.1",
Expand All @@ -45,7 +46,8 @@
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"sinon": "^14.0.0",
"superagent": "^7.1.3"
"superagent": "^7.1.3",
"swagger-ui-express": "^4.4.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
Expand Down
8 changes: 7 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
import { MongooseModule } from '@nestjs/mongoose';
import { FiltersModule } from './core/error-handling/filters.module';
import { TransformResponseInterceptor } from './core/http/transform-response.interceptor';
import { CitiesModule } from './microservice/adapter/cities.module';
import { CountriesModule } from './microservice/adapter/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/neighborhoods.module';
import { StatesModule } from './microservice/adapter/states.module';

@Module({
imports: [
Expand All @@ -23,7 +26,10 @@ import { NeighborhoodsModule } from './microservice/adapter/neighborhoods.module
uri: config.get<string>('database.mongodb.connection')
})
}),
NeighborhoodsModule
NeighborhoodsModule,
CitiesModule,
StatesModule,
CountriesModule
],
controllers: [],
providers: [
Expand Down
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { useContainer } from 'class-validator';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import * as fs from 'fs';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand All @@ -12,7 +14,19 @@ async function bootstrap() {
})
);
useContainer(app.select(AppModule), { fallbackOnErrors: true });

const configService = app.get<ConfigService>(ConfigService);

const docApi = new DocumentBuilder()
.setTitle('Places')
.setDescription('Places API')
.setVersion(configService.get<string>('doc.version'))
.build();

const document = SwaggerModule.createDocument(app, docApi);
fs.writeFileSync('./swagger-spec.json', JSON.stringify(document));
SwaggerModule.setup('api', app, document);

return await app.listen(configService.get<string>('api.port'));
}

Expand Down
33 changes: 33 additions & 0 deletions src/microservice/adapter/cities.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import configuration from '../../config/configuration';
import { MongooseModule } from '@nestjs/mongoose';
import { City, CitySchema } from '../domain/schemas/city.schema';
import { ValidateCityByNameOrAliasService } from '../domain/service/cities/validate-city-by-name-or-alias.service';
import { CitiesMongoose } from './repository/cities/cities-mongoose.repository';
import { ValidateInputParamsService } from '../domain/service/validate/validate-input-params.service';
import { GetCitiesByStateService } from '../domain/service/cities/get/get-cities-by-state.service';
import { CitiesController } from './controller/cities.controller';
import { GetCitiesByCountryService } from '../domain/service/cities/get/get-cities-by-country.service';
import { StatesModule } from './states.module';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [configuration]
}),
MongooseModule.forFeature([{ name: City.name, schema: CitySchema }]),
StatesModule
],
controllers: [CitiesController],
providers: [
CitiesMongoose,
ValidateCityByNameOrAliasService,
ValidateInputParamsService,
GetCitiesByStateService,
GetCitiesByCountryService
],
exports: [CitiesMongoose, ValidateInputParamsService, GetCitiesByStateService]
})
export class CitiesModule {}
78 changes: 78 additions & 0 deletions src/microservice/adapter/controller/cities.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Controller, Get, HttpStatus, Param } from '@nestjs/common';
import { NestResponse } from '../../../core/http/nest-response';
import { AbstractController } from '../../domain/controller/abstract-controller';
import { GetCitiesByStateService } from '../../domain/service/cities/get/get-cities-by-state.service';
import { SearchCitiesDTO } from '../../domain/model/search/cities/search-cities-dto.model';
import { GetCitiesByCountryService } from '../../domain/service/cities/get/get-cities-by-country.service';
import {
ApiOkResponse,
ApiOperation,
ApiParam,
ApiTags
} from '@nestjs/swagger';
import { CityResponse } from '../../domain/model/cities/city-response.model';
import { CitiesByCountry } from '../../domain/model/cities/cities-by-country.model';

@ApiTags('cities')
@Controller('cities')
export class CitiesController extends AbstractController {
constructor(
private readonly getCitiesByStateService: GetCitiesByStateService,
private readonly getCitiesByCountryService: GetCitiesByCountryService
) {
super();
}

@ApiOperation({
description: 'Get Cities By State Reference'
})
@ApiOkResponse({
description: 'Cities found.',
isArray: true,
type: CityResponse
})
@ApiParam({
name: 'country',
required: true,
description: 'The Country name of the city',
type: String
})
@ApiParam({
name: 'state',
required: true,
description: 'The State name of the city',
type: String
})
@Get('/state/:country/:state')
async getCitiesByState(
@Param() params: SearchCitiesDTO
): Promise<NestResponse> {
return this.buildResponse(
HttpStatus.OK,
await this.getCitiesByStateService.getCitiesByState(params)
);
}

@ApiOperation({
description: 'Get Cities By Country Reference'
})
@ApiOkResponse({
description: 'Cities found.',
type: CitiesByCountry
})
@ApiParam({
name: 'country',
required: true,
description: 'The Country name of the city',
type: String
})
@Get('/country/:country')
async getCitiesByCountry(
@Param('country') country: string
): Promise<NestResponse> {
return this.buildResponse(
HttpStatus.OK,
await this.getCitiesByCountryService.getCitiesByCountry(country)
);
}
}
Loading

0 comments on commit 40b8896

Please sign in to comment.