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