mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Setup Swagger
This commit is contained in:
parent
a1b2f2cd78
commit
2c3c9a0532
|
|
@ -3,20 +3,20 @@ import { AppController } from './app.controller';
|
|||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ AppController ],
|
||||
providers: [ AppService ]
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
describe('root', () => {
|
||||
it('should return "Healthy!"', () => {
|
||||
expect(appController.getHello()).toBe('Healthy!');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
getHello(): string {
|
||||
return 'Healthy!';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export class GameController {
|
|||
|
||||
// /games/:gameId
|
||||
@Get(':gameId')
|
||||
@ApiOperation({ summary: 'Find game by Id' })
|
||||
@ApiOperation({ tags: [ 'Game' ], summary: 'Find game by Id' })
|
||||
findOne(@Param('gameId') gameId: string) {
|
||||
return this.gameService.findOne(gameId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { ApiOperation } from '@nestjs/swagger';
|
||||
|
||||
import { GamesService } from './games.service';
|
||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||
|
|
@ -9,6 +10,7 @@ export class GamesController {
|
|||
|
||||
// /games
|
||||
@Get()
|
||||
@ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games' })
|
||||
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
||||
const { limit = 10, offset = 0 } = paginationQuery;
|
||||
return this.gameService.findAll({ limit, offset });
|
||||
|
|
@ -16,13 +18,8 @@ export class GamesController {
|
|||
|
||||
// /gametype/:gametype
|
||||
@Get('gametype/:gametype')
|
||||
@ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' })
|
||||
findByType(@Param('gametype') gametype: string) {
|
||||
return this.gameService.findByType(gametype);
|
||||
}
|
||||
|
||||
// /games/:gameId
|
||||
@Get(':gameId')
|
||||
findOne(@Param('gameId') gameId: string) {
|
||||
return this.gameService.findOne(gameId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,4 @@ export class GamesService {
|
|||
}
|
||||
return game;
|
||||
}
|
||||
|
||||
async findOne(gameId: string) {
|
||||
const game = await this.gamesRepository.findOne(gameId);
|
||||
if (!game) {
|
||||
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||
}
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ async function bootstrap() {
|
|||
.setTitle('Tribes 2 Stats API')
|
||||
.setDescription('Powering stats.playt2.com')
|
||||
.setVersion('1.0')
|
||||
.addTag('task')
|
||||
.addTag('Game')
|
||||
.addTag('Player')
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, swaggerOptions);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ApiOperation } from '@nestjs/swagger';
|
||||
|
||||
import { PlayerService } from './player.service';
|
||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||
|
||||
@Controller('player')
|
||||
export class PlayerController {
|
||||
|
|
@ -9,6 +9,7 @@ export class PlayerController {
|
|||
|
||||
// /player/:playerGuid
|
||||
@Get(':playerGuid')
|
||||
@ApiOperation({ tags: [ 'Player' ], summary: 'Return player stats by guid' })
|
||||
findOne(@Param('playerGuid') playerGuid: string) {
|
||||
return this.playerService.findOne(playerGuid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Controller, Get, Query, Param } from '@nestjs/common';
|
||||
import { ApiOperation } from '@nestjs/swagger';
|
||||
|
||||
import { PlayersService } from './players.service';
|
||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||
|
|
@ -9,14 +10,9 @@ export class PlayersController {
|
|||
|
||||
// /players
|
||||
@Get()
|
||||
@ApiOperation({ tags: [ 'Player' ], summary: 'Return a list of players' })
|
||||
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
||||
const { limit = 10, offset = 0 } = paginationQuery;
|
||||
return this.playerService.findAll({ limit, offset });
|
||||
}
|
||||
|
||||
// /players/:playerGuid
|
||||
@Get(':playerGuid')
|
||||
findOne(@Param('playerGuid') playerGuid: string) {
|
||||
return this.playerService.findOne(playerGuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,21 +4,18 @@ import * as request from 'supertest';
|
|||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [ AppModule ]
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer()).get('/').expect(200).expect('Healthy!');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue