Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modulo5/case-estante-coe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
build
.env
23 changes: 23 additions & 0 deletions modulo5/case-estante-coe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Teste prático da EstanteVirtual

### Documentação postman:

### Descrição:

* Teste prático da EstanteVirtual*, Com a chegada dos jogos olímpicos, fomos designados para construir uma API REST em Ruby para o COB (Comitê Olímico Brasileiro), que será responsável por marcar e dizer os vencedores das seguintes modalidades:
<br>
As modalidades escolhidas foram:
<br>100m rasos: Menor tempo vence
<br>Lançamento de Dardo: Maior distância vence
<br>Para verifica-lo deve-se baixar o arquivo atraves do git clone e instalar as dependencias atraves do npm i

### Funcionalidades:

1. Cadastro
2. Login
3. Endpoint de registrar banda
4. Endpoint de visualização de detalhes sobre a banda
5. Endpoint de adicionar um show a um dia
6. Endpoint de pegar todos os shows de uma data


8 changes: 8 additions & 0 deletions modulo5/case-estante-coe/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
roots: ["<rootDir>/tests"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
22 changes: 22 additions & 0 deletions modulo5/case-estante-coe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "case1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start:dev": "ts-node-dev ./src/index.ts",
"start": "tsc && node ./build/index.js",
"build": "tsc",
"dev": "ts-node-dev ./src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"jsonwebtoken": "^8.5.1",
"typescript": "^4.6.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Competition, InputDTO, Progretion } from "../../Model/Competition";
import { IdGenerator } from "../../Services/IdGeneretor";
import { DartCompetitionRepository } from "./DartCompetitionRepository";

export default class DartCompetitionBusiness {
private idGenerator: IdGenerator;
private competitionData: DartCompetitionRepository;

constructor(
competitionDataImplementation: DartCompetitionRepository
) {
this.idGenerator = new IdGenerator
this.competitionData = competitionDataImplementation
}

insertDart = async (input: InputDTO) => {
const { athlete, competition, unity, valor } = input

if (!competition || !athlete || !valor || !unity) {
throw new Error("Preencha todos os campos")
}

if (typeof competition !== "string" || typeof athlete !== "string" || typeof valor !== "string" || typeof unity !== "string") {
throw new Error("Preencha valores válidos")
}

if (unity !== "m") {
throw new Error("unity inválida!")
}

const verificaProgretionCompetition = await this.competitionData.getSituationByName(competition, Progretion.FINISH)

if (verificaProgretionCompetition?.length > 0) {
throw new Error("Competição finalizada.")
}

const verificaChances = await this.competitionData.getAthleteCount(athlete, competition)

if (verificaChances >= 3) {
throw new Error("O athlete já realizou todos os lançamentos!")
}

if (unity !== "m") {
throw new Error("unity inválida!")
}

const id = this.idGenerator.generate()

const progretion = Progretion.PROGRESS

const novacompetition = new Competition(
id,
competition,
athlete,
valor,
unity,
progretion
)

await this.competitionData.insert(novacompetition)


}

finishDart = async (input: string) => {
const competition = input

const progretion = Progretion.FINISH

const verifyCompetition = await this.competitionData.getCompetitionByName(competition)

if (!verifyCompetition) {
throw new Error("Competição ou modalidade não existente.")
}

await this.competitionData.updateSituation(progretion, competition)
}

getRanking = async (input: string) => {
const competition = input

const verificacompetition = await this.competitionData.getCompetitionByName(competition)

if (!verificacompetition) {
throw new Error("Competição ou modalidade não existente")

}

const resultado = await this.competitionData.getRanking(competition)

return resultado
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Competition, Progretion } from "../../Model/Competition"

export interface DartCompetitionRepository {
insert(competition: Competition): Promise<Competition>
getByAthlete(athlete: string): Promise<Competition>
getCompetitionByName(competition: string): Promise<Competition>
updateSituation(situation: Progretion.FINISH, competition: string): Promise<void>
getSituationByName(competition: string, situation: Progretion.FINISH): Promise<any>
getCompetitionAndAthlete(competition: string): Promise<string>
getRanking(competition: string): Promise<Competition[]>
getAthleteCount(athlete: string, competition: string): Promise<number>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Competition, InputDTO, Progretion } from "../../Model/Competition";
import { IdGenerator } from "../../Services/IdGeneretor";
import { RunnerCompetitionRepository } from "./RunnerCompetitionRepository";


export class RunnerCompetitionBusiness {
private idGenerator: IdGenerator;
private competitionData: RunnerCompetitionRepository;

constructor(
competitionDataImplementation: RunnerCompetitionRepository
) {
this.idGenerator = new IdGenerator
this.competitionData = competitionDataImplementation
}

insertRunner = async (input: InputDTO): Promise<void> => {
const { athlete, competition, unity, valor } = input

if (!competition || !athlete || !valor || !unity) {
throw new Error("Preencha todos os campos")
}

if (typeof competition !== "string" || typeof athlete !== "string" || typeof valor !== "string" || typeof unity !== "string") {
throw new Error("Preencha valores válidos")
}

if (unity !== "s") {
throw new Error("unity inválida!")
}

const verificaProgretioncompetition = await this.competitionData.getSituationByName(competition, Progretion.FINISH)

if (verificaProgretioncompetition.length > 0) {
throw new Error("Competição finalizada.")
}

const verificaCompetidor = await this.competitionData.getByAthlete(athlete)

if (verificaCompetidor) {
const verificaQualcompetition = await this.competitionData.getCompetitionAndAthlete(competition)

if (verificaQualcompetition === athlete) {
throw new Error(" 'athlete' já realizou essa prova")
}

const id = this.idGenerator.generate()

const progretion = Progretion.PROGRESS

const novacompetition = new Competition(
id,
competition,
athlete,
valor,
unity,
progretion
)

await this.competitionData.insert(novacompetition)
}
}

finishRun = async (input: string) => {
const competition = input

const progretion = Progretion.FINISH

const verificacompetition = await this.competitionData.getCompetitionByName(competition)

if (!verificacompetition) {
throw new Error("Competição ou modalidade não existente.")
}

await this.competitionData.updateSituation(progretion, competition)
}

getRanking = async (input: string) => {
const competition = input

const verificacompetition = await this.competitionData.getCompetitionByName(competition)

if (!verificacompetition) {
throw new Error("Competição ou modalidade não existente")
}

const resultado = await this.competitionData.getRanking(competition)

return resultado
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Competition, Progretion } from "../../Model/Competition";

export interface RunnerCompetitionRepository {
insert(competition: Competition): Promise<Competition>
getByAthlete(athlete: string): Promise<Competition>
getCompetitionByName(competition: string): Promise<Competition>
updateSituation(situation: Progretion.FINISH, competition: string): Promise<void>
getSituationByName(competition: string, situation: Progretion.FINISH): Promise<any>
getCompetitionAndAthlete(competition: string): Promise<string>
getRanking(competition: string): Promise<Competition[]>
getAthleteCount(athlete: string, competition: string): Promise<number>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Request, Response } from "express";
import DartCompetitionBusiness from "../Business/DartCompetition/DartCompetitionBusiness";
import { DartCompetitionDatabase } from "../Data/DartCompetitionDatabase";

import { InputDTO } from "../Model/Competition";


export default class DartCompetitionController {
private dartCompetitionBusiness: DartCompetitionBusiness;
constructor(
) {
this.dartCompetitionBusiness = new DartCompetitionBusiness(new DartCompetitionDatabase())
}

createDart = async (req: Request, res: Response) => {
const { competition, athlete, valor, unity } = req.body

const input: InputDTO = {
competition,
athlete,
valor,
unity
}

try {
await this.dartCompetitionBusiness.insertDart(input)
res.send({ message: `Atleta inscrito na competição ' ${competition}'` })

} catch (error: any) {
res.statusCode = 400
let message = error.sqlMessage || error.message
res.send({ message })
}
}

finishDart = async (req: Request, res: Response) => {
const { competition } = req.body

try {
await this.dartCompetitionBusiness.finishDart(competition)
res.send({ message: "Competição finalizada." })

} catch (error: any) {
res.statusCode = 400
let message = error.sqlMessage || error.message
res.send({ message })
}
}

rankingDart = async (req: Request, res: Response) => {
const { competition } = req.body

try {
const ranking = await this.dartCompetitionBusiness.getRanking(competition)
res.send({ message: "Resultado da competição", ranking })

} catch (error: any) {
res.statusCode = 400
let message = error.sqlMessage || error.message
res.send({ message })
}
}

}
Loading