-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
243e287
commit f3fa36f
Showing
9 changed files
with
203 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { Controller, Get, Body, Post } from '@nestjs/common'; | ||
import { Game } from './game.interface'; | ||
import { GameService } from './game.service'; | ||
import { CreateGameDto } from './game.dto'; | ||
|
||
@Controller('game') | ||
export class GameController { | ||
constructor(private readonly service: GameService) {} | ||
|
||
@Get('overview') | ||
getAllOverview(): Game[] { | ||
return [ | ||
{ | ||
id: 123, | ||
src: '/img/game.png', | ||
alt: 'Imagem do Game', | ||
title: 'Moonlighter', | ||
price: 599.9, | ||
stars: 3, | ||
}, | ||
{ | ||
id: 123, | ||
src: '/img/game.png', | ||
alt: 'Imagem do Game', | ||
title: 'Moonlighter', | ||
price: 599.9, | ||
stars: 3, | ||
}, | ||
{ | ||
id: 123, | ||
src: '/img/game.png', | ||
alt: 'Imagem do Game', | ||
title: 'Moonlighter', | ||
price: 599.9, | ||
stars: 3, | ||
}, | ||
]; | ||
async getAllOverview(): Promise<Game[]> { | ||
return await this.service.findAll(); | ||
} | ||
|
||
@Post() | ||
async create(@Body() createGameDto: CreateGameDto) { | ||
return await this.service.create(createGameDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class CreateGameDto { | ||
readonly src: string; | ||
readonly alt: string; | ||
readonly title: string; | ||
readonly price: number; | ||
readonly stars: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { GameController } from './game.controller'; | ||
import { GameService } from './game.service'; | ||
import GameSchema from './game.schema'; | ||
|
||
@Module({ | ||
controllers: [GameController] | ||
imports: [MongooseModule.forFeature([{ name: 'Game', schema: GameSchema }])], | ||
controllers: [GameController], | ||
providers: [GameService], | ||
}) | ||
export class GameModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Schema } from 'mongoose'; | ||
|
||
const GameSchema = new Schema({ | ||
id: Number, | ||
src: String, | ||
alt: String, | ||
title: String, | ||
price: Number, | ||
stars: Number, | ||
}); | ||
|
||
export default GameSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { GameService } from './game.service'; | ||
|
||
describe('GameService', () => { | ||
let service: GameService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [GameService], | ||
}).compile(); | ||
|
||
service = module.get<GameService>(GameService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Model } from 'mongoose'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Game } from './game.interface'; | ||
import { CreateGameDto } from './game.dto'; | ||
|
||
@Injectable() | ||
export class GameService { | ||
constructor(@InjectModel('Game') private readonly gameModel: Model<Game>) {} | ||
|
||
async create(createGameDto: CreateGameDto): Promise<Game> { | ||
const createGame = new this.gameModel(createGameDto); | ||
return await createGame.save(); | ||
} | ||
|
||
async findAll(): Promise<Game[]> { | ||
return await this.gameModel.find().exec(); | ||
} | ||
} |