From ca90d6d9cfbeca7f72b74ec281bde66e803f7446 Mon Sep 17 00:00:00 2001 From: Anderson-Felix-de-Lyra Date: Thu, 9 Jun 2022 23:22:01 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Testanto=20a=20aplica=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Case4_Doghero/src/business/UserTutorBusiness.ts | 6 +++--- .../Case4_Doghero/src/controller/UserTutorController.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts b/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts index 9aef2b9..cf4f012 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts @@ -11,13 +11,13 @@ export class UserTutorBusiness { async createTutor(tutor: TutorInputDTO) { - if (!tutor.email || !tutor.password || !tutor.name) { + if (!tutor.email || !tutor.name || !tutor.password) { throw new Error("Todos os campos devem ser preenchidos"); } - if (tutor.password.length < 6 || tutor.name.length < 15) { - throw new Error("O password deve ter no mínimo 6 caracteres e o nome deve ter no maximo 15 caracteres"); + if (tutor.password.length < 6 || tutor.name.length < 5) { + throw new Error("O password deve ter no mínimo 6 caracteres e o nome deve ter no mínimo 5 caracteres"); } const idGenerator = new IdGenerator(); diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/controller/UserTutorController.ts b/BackEnd/Modulo 1/Case4_Doghero/src/controller/UserTutorController.ts index 937ede9..8e91e82 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/controller/UserTutorController.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/controller/UserTutorController.ts @@ -8,8 +8,8 @@ export class UserTutorController { try { const input: TutorInputDTO = { - email: req.body.email, name: req.body.name, + email: req.body.email, password: req.body.password } From 606d9a0c7b8a271502064eaba023e33b5e982e4a Mon Sep 17 00:00:00 2001 From: Anderson-Felix-de-Lyra Date: Fri, 10 Jun 2022 15:08:44 -0300 Subject: [PATCH 2/3] Case DogHero finalizado --- BackEnd/Modulo 1/Case4_Doghero/README.md | 37 +++++++++++++ BackEnd/Modulo 1/Case4_Doghero/package.json | 1 + .../src/business/DogHeroBusiness.ts | 19 +------ .../src/business/UserTutorBusiness.ts | 4 +- .../src/controller/DogHeroController.ts | 53 ++----------------- .../Case4_Doghero/src/data/DogHeroDatabase.ts | 40 +++----------- .../src/data/UserTutorDatabase.ts | 4 +- .../Case4_Doghero/src/model/DogHeroWalking.ts | 6 --- .../Case4_Doghero/src/routes/DogHeroRouter.ts | 9 +++- .../src/service/HashGenerator.ts | 2 +- 10 files changed, 62 insertions(+), 113 deletions(-) create mode 100644 BackEnd/Modulo 1/Case4_Doghero/README.md diff --git a/BackEnd/Modulo 1/Case4_Doghero/README.md b/BackEnd/Modulo 1/Case4_Doghero/README.md new file mode 100644 index 0000000..992ae99 --- /dev/null +++ b/BackEnd/Modulo 1/Case4_Doghero/README.md @@ -0,0 +1,37 @@ +# CASE DOGHERO + + +Este é um projeto de Backend, utilizando Typescript, MySQL, além das bibliotecas knexJs e expressJs, desenvolvido para atender aos modelos das APIs. + +## DESCRIÇÃO DO PROJETO + +O projeto consiste em simular uma plataforma de Passeio de Dogs, onde o usuário (Tutor) poderá criar e acessar informações dos passeios contratado, nas formas de tempo, quantidade de Dogs, hora inicial e final. Sendo criado endpoints GET e POST para simular as demandas. + + +## RECURSOS UTILIZADOS + +* Nodejs; +* MySQL; +* express; +* typescript; +* uuid; +* knex; +* bcryptjs; +* moment + + +## LINK DA DOCUMENTAÇÃO NO POSTMAN: +https://documenter.getpostman.com/view/19296981/Uz5NiCp8#2120e0cf-beab-4d9c-ac7c-43ad58005bab + + +## PARA RODAR A APLICAÇÃO + +* npm install +* npm run dev + +## DESENVOLVEDOR + +Anderson Felix +* Linkedin - https://www.linkedin.com/in/anderson-fl/ + + diff --git a/BackEnd/Modulo 1/Case4_Doghero/package.json b/BackEnd/Modulo 1/Case4_Doghero/package.json index de9cb41..48f1511 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/package.json +++ b/BackEnd/Modulo 1/Case4_Doghero/package.json @@ -23,6 +23,7 @@ "typescript": "^4.7.3" }, "dependencies": { + "bcrypt": "^5.0.1", "bcryptjs": "^2.4.3", "cors": "^2.8.5", "dotenv": "^16.0.1", diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/business/DogHeroBusiness.ts b/BackEnd/Modulo 1/Case4_Doghero/src/business/DogHeroBusiness.ts index 3a652e7..97a4fc0 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/business/DogHeroBusiness.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/business/DogHeroBusiness.ts @@ -1,4 +1,3 @@ -import { Time, EditWalkDTO, Status } from './../model/DogHeroWalking'; import { WalkInputDTO } from "../model/DogHeroWalking"; import { InputError } from "../error/BaseError"; import moment from "moment"; @@ -79,21 +78,5 @@ export class DogHeroBusiness { return result } - - async editStartOrFinishBusiness(input: EditWalkDTO){ - - const wbd = new DogHeroDatabase(); - const result = await wbd.editStartOrFinishData(input); - - return result - } - - - async editStatusBusiness(input: EditWalkDTO){ - - const wbd = new DogHeroDatabase(); - const result = await wbd.editStatusData(input); - - return result - } + } \ No newline at end of file diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts b/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts index cf4f012..a660734 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/business/UserTutorBusiness.ts @@ -11,13 +11,13 @@ export class UserTutorBusiness { async createTutor(tutor: TutorInputDTO) { - if (!tutor.email || !tutor.name || !tutor.password) { + if (!tutor.name || !tutor.email || !tutor.password) { throw new Error("Todos os campos devem ser preenchidos"); } if (tutor.password.length < 6 || tutor.name.length < 5) { - throw new Error("O password deve ter no mínimo 6 caracteres e o nome deve ter no mínimo 5 caracteres"); + throw new Error("O password deve ter ate 6 caracteres e o nome deve ser menor que 5 caracteres"); } const idGenerator = new IdGenerator(); diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/controller/DogHeroController.ts b/BackEnd/Modulo 1/Case4_Doghero/src/controller/DogHeroController.ts index 56ea5a8..4d41ce1 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/controller/DogHeroController.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/controller/DogHeroController.ts @@ -1,8 +1,8 @@ -import { Status, Walk, EditWalkDTO } from './../model/DogHeroWalking'; +import { Walk} from './../model/DogHeroWalking'; import { Request, Response } from "express"; import { DogHeroBusiness } from "../business/DogHeroBusiness"; import { BaseDatabase } from "../data/BaseDatabase"; -import { Time, WalkInputDTO } from "../model/DogHeroWalking"; +import { WalkInputDTO } from "../model/DogHeroWalking"; export class DogHeroController { async walkCreate(req: Request, res: Response) { @@ -22,7 +22,7 @@ export class DogHeroController { const dogHeroBusiness = new DogHeroBusiness(); await dogHeroBusiness.createWalk(input); - res.status(200).send("Walk criado com sucesso."); + res.status(200).send("Walkink criado com sucesso."); } catch (error:any) { res.status(400).send({ error: error.message }); @@ -86,51 +86,6 @@ export class DogHeroController { }) } } - - async editStartWalkOrFinishWalk(req: Request, res: Response) { - try { - - const input: EditWalkDTO ={ - id: req.params.id, - startWalk: req.body.startWalk, - finishWalk: req.body.finishWalk - }; - - - const dogHeroBusiness = new DogHeroBusiness(); - await dogHeroBusiness.editStartOrFinishBusiness(input); - - - res.status(200).send("Alterado com sucesso") - - } catch (error:any) { - res.status(400).send({ error: error.message }); - } - - await BaseDatabase.destroyConnection(); - } - - async editStatus(req: Request, res: Response) { - try { - - const status = Walk.toStatusEnum(req.body.status as string) - - const input: EditWalkDTO ={ - id: req.params.id, - status - }; - - const dogHeroBusiness = new DogHeroBusiness(); - await dogHeroBusiness.editStatusBusiness(input); - - - res.status(200).send("Status alterado com sucesso") - - } catch (error:any) { - res.status(400).send({ error: error.message }); - } - - await BaseDatabase.destroyConnection(); - } + } \ No newline at end of file diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/data/DogHeroDatabase.ts b/BackEnd/Modulo 1/Case4_Doghero/src/data/DogHeroDatabase.ts index bea1fd2..a1a3d6c 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/data/DogHeroDatabase.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/data/DogHeroDatabase.ts @@ -1,5 +1,4 @@ -import { UserTutor } from '../model/UserTutor'; -import { WalkCalc, WalkOutputDTO, Status, EditWalkDTO } from '../model/DogHeroWalking'; +import { WalkCalc, WalkOutputDTO, } from '../model/DogHeroWalking'; import moment from "moment"; import { NotFoundError } from "../error/BaseError"; import { Time} from "../model/DogHeroWalking"; @@ -113,12 +112,14 @@ export class DogHeroDatabase extends BaseDatabase{ ): Promise { const walk = await this.getConnection().raw(` - SELECT w.id as id, + SELECT + w.id as id, t.id as tutorId, w.date_walk as dateWalk, w.start_walk as startWalk, w.finish_walk as finishWalk, w.quantity_dogs as quantityDogs, + w.price as price, t.name as name FROM ${this.TABLE_NAME.WALLKING} w LEFT JOIN ${this.TABLE_NAME.TUTOR} t ON t.id = w.id_user_tutor @@ -136,38 +137,11 @@ export class DogHeroDatabase extends BaseDatabase{ name: data.name, dateWalk: data.dateWalk, startWalk: data.startWalk, - quantityDogs: data.quantityDogs + quantityDogs: data.quantityDogs, + finishWalk: data.finishWalk, + price: data.price })) } - async editStartOrFinishData(walk: EditWalkDTO): Promise{ - - try { - await this.getConnection().where("id",walk.id) - .update({ - start_walk: walk.startWalk, - finish_walk: walk.finishWalk - - }).into(this.TABLE_NAME.WALLKING) - - } catch (error:any) { - throw new Error(error.sqlMessage || error.message); - } - } - - async editStatusData(input: EditWalkDTO): Promise{ - - try { - await this.getConnection().where("id",input.id) - .update({ - status: input.status - - }).into(this.TABLE_NAME.WALLKING) - - } catch (error:any) { - throw new Error(error.sqlMessage || error.message); - } -} - } \ No newline at end of file diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/data/UserTutorDatabase.ts b/BackEnd/Modulo 1/Case4_Doghero/src/data/UserTutorDatabase.ts index 09e1f86..570252a 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/data/UserTutorDatabase.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/data/UserTutorDatabase.ts @@ -27,7 +27,7 @@ export class UserTutorDatabase extends BaseDatabase { public async getTutorData(offset: number): Promise { try { const result = await this.getConnection() - .select("id", "name", "phone", "email") + .select("id", "name", "email") .into(this.TABLE_NAME.TUTOR) .orderBy("name", 'asc') .limit(5) @@ -40,7 +40,5 @@ export class UserTutorDatabase extends BaseDatabase { } } - - } diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/model/DogHeroWalking.ts b/BackEnd/Modulo 1/Case4_Doghero/src/model/DogHeroWalking.ts index bb279c7..f0312f6 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/model/DogHeroWalking.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/model/DogHeroWalking.ts @@ -190,9 +190,3 @@ export interface WalkCalc{ } -export interface EditWalkDTO{ - id: string, - startWalk?: Time, - finishWalk?: Time, - status?: string -} \ No newline at end of file diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/routes/DogHeroRouter.ts b/BackEnd/Modulo 1/Case4_Doghero/src/routes/DogHeroRouter.ts index fab92dd..4dc1734 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/routes/DogHeroRouter.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/routes/DogHeroRouter.ts @@ -6,4 +6,11 @@ export const dogHeroRouter = express.Router(); const dogHeroController = new DogHeroController(); -dogHeroRouter.post("/signup", dogHeroController.walkCreate); \ No newline at end of file +dogHeroRouter.post("/signup", dogHeroController.walkCreate); + +dogHeroRouter.get("/WalkDateTodayOrAll", dogHeroController.index); + +dogHeroRouter.get("/showWalk/:id", dogHeroController.showWalkId); + +dogHeroRouter.get("/walkTutor/:id", dogHeroController.getWalkTutor); + diff --git a/BackEnd/Modulo 1/Case4_Doghero/src/service/HashGenerator.ts b/BackEnd/Modulo 1/Case4_Doghero/src/service/HashGenerator.ts index 5a23137..3ae0e48 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/src/service/HashGenerator.ts +++ b/BackEnd/Modulo 1/Case4_Doghero/src/service/HashGenerator.ts @@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs'; export class HashGenerator { public async hash(text: string): Promise { - const rounds = 20 + const rounds = 12 const salt = await bcrypt.genSalt(rounds); const result = await bcrypt.hash(text, salt); From 9b5b7ba178ba154fdfe9284aef381c638800da36 Mon Sep 17 00:00:00 2001 From: Anderson-Felix-de-Lyra Date: Mon, 13 Jun 2022 15:32:40 -0300 Subject: [PATCH 3/3] Projeto Finalizado --- BackEnd/Modulo 1/Case4_Doghero/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BackEnd/Modulo 1/Case4_Doghero/README.md b/BackEnd/Modulo 1/Case4_Doghero/README.md index 992ae99..641b0fd 100644 --- a/BackEnd/Modulo 1/Case4_Doghero/README.md +++ b/BackEnd/Modulo 1/Case4_Doghero/README.md @@ -3,6 +3,7 @@ Este é um projeto de Backend, utilizando Typescript, MySQL, além das bibliotecas knexJs e expressJs, desenvolvido para atender aos modelos das APIs. + ## DESCRIÇÃO DO PROJETO O projeto consiste em simular uma plataforma de Passeio de Dogs, onde o usuário (Tutor) poderá criar e acessar informações dos passeios contratado, nas formas de tempo, quantidade de Dogs, hora inicial e final. Sendo criado endpoints GET e POST para simular as demandas.