From 2e4809c2b1c93f2ba046b454a897ebba0210280b Mon Sep 17 00:00:00 2001 From: raulrita08 Date: Sun, 17 Jul 2022 17:46:44 -0300 Subject: [PATCH 01/11] setup e inicio da criacao das tabelas DB --- labenu-system/.gitignore | 4 ++++ labenu-system/package.json | 28 ++++++++++++++++++++++++++++ labenu-system/querys.sql | 28 ++++++++++++++++++++++++++++ labenu-system/request.rest | 0 labenu-system/src/app.ts | 19 +++++++++++++++++++ labenu-system/src/connection.ts | 17 +++++++++++++++++ labenu-system/src/index.ts | 9 +++++++++ labenu-system/tsconfig.json | 14 ++++++++++++++ 8 files changed, 119 insertions(+) create mode 100644 labenu-system/.gitignore create mode 100644 labenu-system/package.json create mode 100644 labenu-system/querys.sql create mode 100644 labenu-system/request.rest create mode 100644 labenu-system/src/app.ts create mode 100644 labenu-system/src/connection.ts create mode 100644 labenu-system/src/index.ts create mode 100644 labenu-system/tsconfig.json diff --git a/labenu-system/.gitignore b/labenu-system/.gitignore new file mode 100644 index 0000000..9708d9f --- /dev/null +++ b/labenu-system/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/labenu-system/package.json b/labenu-system/package.json new file mode 100644 index 0000000..17cb20b --- /dev/null +++ b/labenu-system/package.json @@ -0,0 +1,28 @@ +{ + "name": "labenu-system", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "ts-node-dev ./src/index.ts", + "start": "tsc && node ./build/index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.0.1", + "express": "^4.18.1", + "knex": "^2.1.0", + "mysql": "^2.18.1" + }, + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/express": "^4.17.13", + "@types/knex": "^0.16.1", + "ts-node-dev": "^2.0.0", + "typescript": "^4.7.4" + } +} diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql new file mode 100644 index 0000000..f0277d9 --- /dev/null +++ b/labenu-system/querys.sql @@ -0,0 +1,28 @@ +USE `guimaraes-4211089-raul-rita`; + +CREATE TABLE LS_Turma( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + modulo ENUM('0','1','2','3','4','5','6') DEFAULT '0' +); + +CREATE TABLE LS_Estudante( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + data_nasc VARCHAR(255) NOT NULL, + turma_id VARCHAR(255), FOREIGN KEY (turma_id) REFERENCES LS_Turma(id) +); + +CREATE TABLE LS_Hobby ( + id VARCHAR(255) PRIMARY KEY, + nome_hobby ENUM("assistir séries de tv", "jogar videogames", "sair com os amigos", "praticar esportes") NOT NULL +); + +CREATE TABLE LS_Hobby_Estudante( + id VARCHAR(255) PRIMARY KEY, + id_estudante VARCHAR(255), FOREIGN KEY(id_estudante) REFERENCES LS_Estudante(id), + id_hobby VARCHAR(255), FOREIGN KEY(id_hobby) REFERENCES LS_Hobby(id) +); +SELECT * FROM `LS_Hobby_Estudante`; + diff --git a/labenu-system/request.rest b/labenu-system/request.rest new file mode 100644 index 0000000..e69de29 diff --git a/labenu-system/src/app.ts b/labenu-system/src/app.ts new file mode 100644 index 0000000..201a5a2 --- /dev/null +++ b/labenu-system/src/app.ts @@ -0,0 +1,19 @@ +import express from "express"; +import cors from "cors" +import { AddressInfo } from "net"; + +const app = express(); + +app.use(express.json()); +app.use(cors()); + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost: ${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); + +export default app; \ No newline at end of file diff --git a/labenu-system/src/connection.ts b/labenu-system/src/connection.ts new file mode 100644 index 0000000..4ff5f00 --- /dev/null +++ b/labenu-system/src/connection.ts @@ -0,0 +1,17 @@ +import knex from "knex"; +import dotenv from "dotenv"; + +dotenv.config(); + +export const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: 3306, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME + } +}); + +export default connection; \ No newline at end of file diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts new file mode 100644 index 0000000..96f9de5 --- /dev/null +++ b/labenu-system/src/index.ts @@ -0,0 +1,9 @@ +import connection from "./connection"; +import app from "./app"; +import { Request, Response } from "express"; +// import { v4 as generateId } from "uuid" + +// TESTANDO FUNCIONAMENTO DA API +app.get('/test', (req:Request, res:Response) => { + res.status(200).send("Api funcionando!") +}); \ No newline at end of file diff --git a/labenu-system/tsconfig.json b/labenu-system/tsconfig.json new file mode 100644 index 0000000..f7c1338 --- /dev/null +++ b/labenu-system/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "outDir": "./build", + "rootDir": "./src", + "removeComments": true, + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } + } \ No newline at end of file From 08eb74766bf7f0645a84e33a59c084f22b14068e Mon Sep 17 00:00:00 2001 From: maria-freitas Date: Mon, 18 Jul 2022 21:01:10 -0300 Subject: [PATCH 02/11] =?UTF-8?q?Cria=C3=A7=C3=A3o=20das=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- labenu-system/package.json | 1 + labenu-system/src/classes/docentes.ts | 30 +++++++++++++++++++++++++ labenu-system/src/classes/estudantes.ts | 28 +++++++++++++++++++++++ labenu-system/src/classes/turma.ts | 30 +++++++++++++++++++++++++ labenu-system/src/endpoints.ts | 1 + 5 files changed, 90 insertions(+) create mode 100644 labenu-system/src/classes/docentes.ts create mode 100644 labenu-system/src/classes/estudantes.ts create mode 100644 labenu-system/src/classes/turma.ts create mode 100644 labenu-system/src/endpoints.ts diff --git a/labenu-system/package.json b/labenu-system/package.json index 17cb20b..34a3217 100644 --- a/labenu-system/package.json +++ b/labenu-system/package.json @@ -22,6 +22,7 @@ "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/knex": "^0.16.1", + "@types/node": "^18.0.6", "ts-node-dev": "^2.0.0", "typescript": "^4.7.4" } diff --git a/labenu-system/src/classes/docentes.ts b/labenu-system/src/classes/docentes.ts new file mode 100644 index 0000000..67a9a27 --- /dev/null +++ b/labenu-system/src/classes/docentes.ts @@ -0,0 +1,30 @@ + +export enum ESPECIALIDADES { + REACT = "React", + JS = "JS", + CSS = "CSS", + TYPESCRIPT = "Typescript", + PROGRAMACAO_ORIENTADA_A_OBJETO = "Programacao Orientada a Objetos", + + } + + +export class docentes { + private "id": string + public "nome": string + public "email": string + public "data_de_nascimento": string + public "turma_id": string + public "especialidades": ESPECIALIDADES[] + + + constructor(id:string , nome:string, email: string, data_de_nascimento:string, turma_id:string,especialidades:ESPECIALIDADES[] ,) { + this.id = id + this.nome = nome + this.email = email + this.data_de_nascimento = data_de_nascimento + this.turma_id = turma_id + this.especialidades = especialidades + + } + } \ No newline at end of file diff --git a/labenu-system/src/classes/estudantes.ts b/labenu-system/src/classes/estudantes.ts new file mode 100644 index 0000000..dadd9ea --- /dev/null +++ b/labenu-system/src/classes/estudantes.ts @@ -0,0 +1,28 @@ + +export enum HOBBIES { + ASSITIR_SERIE = "Assistir séries de TV", + JOGAR_VIDEO_GAME = "Jogar vídeogame", + SAIR_COM_AMIGOS = "Sair com amigos", + PRATICAR_ESPORTES = "Praticar esportes" + + } + +export class estudantes { + "id": string + "nome": string + "email": string + "data_de_nascimento": string + "turma_id": string + "hobbies": HOBBIES[] + + + constructor(id:string , nome:string, email: string, data_de_nascimento:string, turma_id:string,hobbies:HOBBIES[]) { + this.id = id + this.nome = nome + this.email = email + this.data_de_nascimento = data_de_nascimento + this.turma_id = turma_id + this.hobbies = hobbies + + } + } \ No newline at end of file diff --git a/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts new file mode 100644 index 0000000..6f00b5a --- /dev/null +++ b/labenu-system/src/classes/turma.ts @@ -0,0 +1,30 @@ + + +export enum MODULO { + MODULO_0 = "Aulas não iniciadas", + MODULO_1 = "Módulo 1", + MODULO_2 = "Módulo 2", + MODULO_3 = "Módulo 3", + MODULO_4 = "Módulo 4", + MODULO_5 = "Módulo 5", + MODULO_6 = "Módulo 6", + + } + + +export class Turma { + "id": string + "nome": string + "docentes": string + "estudantes": string + "modulo": string + + + constructor(id:string , nome:string, docentes: string, estudantes:string, modulo:string ) { + this.id = id; + this.nome = nome; + this.docentes = docentes + this.estudantes = estudantes + this.modulo = modulo + } + } diff --git a/labenu-system/src/endpoints.ts b/labenu-system/src/endpoints.ts new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/labenu-system/src/endpoints.ts @@ -0,0 +1 @@ + From 95380e96575bf845522c04eacb833c795d987091 Mon Sep 17 00:00:00 2001 From: raulrita08 Date: Tue, 19 Jul 2022 18:57:46 -0300 Subject: [PATCH 03/11] organizando banco e classes --- labenu-system/querys.sql | 29 +++++++++++++++++++++++++++++ labenu-system/src/classes/User.ts | 14 ++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 labenu-system/src/classes/User.ts diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql index f0277d9..028ccc1 100644 --- a/labenu-system/querys.sql +++ b/labenu-system/querys.sql @@ -1,3 +1,4 @@ +-- Active: 1657909499156@@35.226.146.116@3306@guimaraes-4211089-raul-rita USE `guimaraes-4211089-raul-rita`; CREATE TABLE LS_Turma( @@ -19,6 +20,10 @@ CREATE TABLE LS_Hobby ( nome_hobby ENUM("assistir séries de tv", "jogar videogames", "sair com os amigos", "praticar esportes") NOT NULL ); +ALTER TABLE `LS_Hobby` +MODIFY COLUMN nome_hobby VARCHAR(255) NOT NULL; +SELECT * FROM `LS_Hobby`; + CREATE TABLE LS_Hobby_Estudante( id VARCHAR(255) PRIMARY KEY, id_estudante VARCHAR(255), FOREIGN KEY(id_estudante) REFERENCES LS_Estudante(id), @@ -26,3 +31,27 @@ CREATE TABLE LS_Hobby_Estudante( ); SELECT * FROM `LS_Hobby_Estudante`; +CREATE TABLE LS_Docente( + id VARCHAR(255) PRIMARY KEY, + nome VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + data_nasc VARCHAR(255) NOT NULL, + turma_id VARCHAR(255), FOREIGN KEY (turma_id) REFERENCES LS_Turma(id) +); + +SELECT * FROM `LS_Docente_Especialidade`; + +CREATE TABLE LS_Especialidade ( + id VARCHAR(255) PRIMARY KEY, + nome_especialidade ENUM("JS", "CSS", "React", "Typescript", "POO") NOT NULL +); + +ALTER TABLE `LS_Especialidade` +MODIFY COLUMN nome_especialidade VARCHAR(255) NOT NULL; +SELECT * FROM `LS_Especialidade`; + +CREATE TABLE LS_Docente_Especialidade ( + id VARCHAR(255) PRIMARY KEY, + id_docente VARCHAR(255), FOREIGN KEY(id_docente) REFERENCES LS_Docente(id), + id_especialidade VARCHAR(255), FOREIGN KEY(id_especialidade) REFERENCES LS_Especialidade(id) +); \ No newline at end of file diff --git a/labenu-system/src/classes/User.ts b/labenu-system/src/classes/User.ts new file mode 100644 index 0000000..bf1816f --- /dev/null +++ b/labenu-system/src/classes/User.ts @@ -0,0 +1,14 @@ +export class User { + "id": string + "nome": string + "email": string + "data_de_nasc": string + "turma_id": string + + constructor( + + ) + { + + } +} \ No newline at end of file From e972d5ab425476f832dd1668383e04a3e5da52c0 Mon Sep 17 00:00:00 2001 From: raulrita08 Date: Tue, 19 Jul 2022 21:48:11 -0300 Subject: [PATCH 04/11] iniciando criacao de endpoints --- labenu-system/package.json | 4 ++- labenu-system/querys.sql | 11 ++++++--- labenu-system/request.rest | 13 ++++++++++ labenu-system/src/classes/Docente.ts | 26 +++++++++++++++++++ labenu-system/src/classes/Estudante.ts | 25 +++++++++++++++++++ labenu-system/src/classes/User.ts | 25 +++++++++++++------ labenu-system/src/classes/docentes.ts | 30 ---------------------- labenu-system/src/classes/estudantes.ts | 28 --------------------- labenu-system/src/classes/turma.ts | 27 +++++++++++--------- labenu-system/src/endpoints.ts | 1 - labenu-system/src/endpoints/Criar.ts | 33 +++++++++++++++++++++++++ labenu-system/src/endpoints/Delete.ts | 0 labenu-system/src/endpoints/Request.ts | 0 labenu-system/src/endpoints/Update.ts | 0 labenu-system/src/index.ts | 5 +++- 15 files changed, 144 insertions(+), 84 deletions(-) create mode 100644 labenu-system/src/classes/Docente.ts create mode 100644 labenu-system/src/classes/Estudante.ts delete mode 100644 labenu-system/src/classes/docentes.ts delete mode 100644 labenu-system/src/classes/estudantes.ts delete mode 100644 labenu-system/src/endpoints.ts create mode 100644 labenu-system/src/endpoints/Criar.ts create mode 100644 labenu-system/src/endpoints/Delete.ts create mode 100644 labenu-system/src/endpoints/Request.ts create mode 100644 labenu-system/src/endpoints/Update.ts diff --git a/labenu-system/package.json b/labenu-system/package.json index 34a3217..8874279 100644 --- a/labenu-system/package.json +++ b/labenu-system/package.json @@ -16,13 +16,15 @@ "dotenv": "^16.0.1", "express": "^4.18.1", "knex": "^2.1.0", - "mysql": "^2.18.1" + "mysql": "^2.18.1", + "uuid": "^8.3.2" }, "devDependencies": { "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/knex": "^0.16.1", "@types/node": "^18.0.6", + "@types/uuid": "^8.3.4", "ts-node-dev": "^2.0.0", "typescript": "^4.7.4" } diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql index 028ccc1..1ea6718 100644 --- a/labenu-system/querys.sql +++ b/labenu-system/querys.sql @@ -20,9 +20,7 @@ CREATE TABLE LS_Hobby ( nome_hobby ENUM("assistir séries de tv", "jogar videogames", "sair com os amigos", "praticar esportes") NOT NULL ); -ALTER TABLE `LS_Hobby` -MODIFY COLUMN nome_hobby VARCHAR(255) NOT NULL; -SELECT * FROM `LS_Hobby`; + CREATE TABLE LS_Hobby_Estudante( id VARCHAR(255) PRIMARY KEY, @@ -54,4 +52,9 @@ CREATE TABLE LS_Docente_Especialidade ( id VARCHAR(255) PRIMARY KEY, id_docente VARCHAR(255), FOREIGN KEY(id_docente) REFERENCES LS_Docente(id), id_especialidade VARCHAR(255), FOREIGN KEY(id_especialidade) REFERENCES LS_Especialidade(id) -); \ No newline at end of file +); + +ALTER TABLE `LS_Turma` +MODIFY COLUMN modulo VARCHAR(255) NOT NULL; + +SELECT * FROM `LS_Turma`; \ No newline at end of file diff --git a/labenu-system/request.rest b/labenu-system/request.rest index e69de29..aa4a609 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -0,0 +1,13 @@ +GET http://localhost:3003/test + +### + +POST http://localhost:3003/turma +Content-Type: application/json + +{ + "nome": "guimaraes", + "docente": "PH", + "estudante": "Talita", + "modulo": "MODULO.MODULO_6" +} \ No newline at end of file diff --git a/labenu-system/src/classes/Docente.ts b/labenu-system/src/classes/Docente.ts new file mode 100644 index 0000000..3eae6ea --- /dev/null +++ b/labenu-system/src/classes/Docente.ts @@ -0,0 +1,26 @@ +import { User } from "./User" + +export enum ESPECIALIDADES { + REACT = "React", + JS = "JS", + CSS = "CSS", + TYPESCRIPT = "Typescript", + PROGRAMACAO_ORIENTADA_A_OBJETO = "Programacao Orientada a Objetos", + } + +export class Docente extends User { + + public "especialidade": ESPECIALIDADES + + constructor( + id:string, + nome:string, + email:string, + dataNasc:string, + turmaId:string, + especialidade: ESPECIALIDADES + ) { + super(id, nome, email, dataNasc, turmaId) + this.especialidade = especialidade + } + } \ No newline at end of file diff --git a/labenu-system/src/classes/Estudante.ts b/labenu-system/src/classes/Estudante.ts new file mode 100644 index 0000000..9d1ac9e --- /dev/null +++ b/labenu-system/src/classes/Estudante.ts @@ -0,0 +1,25 @@ +import { User } from "./User" + +export enum HOBBIES { + ASSITIR_SERIE = "Assistir séries de TV", + JOGAR_VIDEO_GAME = "Jogar vídeogame", + SAIR_COM_AMIGOS = "Sair com amigos", + PRATICAR_ESPORTES = "Praticar esportes" + } + +export class Estudante extends User{ + public "hobby" : HOBBIES + + constructor( + id:string, + nome:string, + email:string, + dataNasc:string, + turmaId:string, + hobby:HOBBIES + ){ + super(id, nome, email, dataNasc, turmaId) + this.hobby = hobby + } + + } \ No newline at end of file diff --git a/labenu-system/src/classes/User.ts b/labenu-system/src/classes/User.ts index bf1816f..8781aec 100644 --- a/labenu-system/src/classes/User.ts +++ b/labenu-system/src/classes/User.ts @@ -1,14 +1,23 @@ export class User { - "id": string - "nome": string - "email": string - "data_de_nasc": string - "turma_id": string + public "id": string + public "nome": string + public "email": string + public "dataNasc": string + public "turmaId": string constructor( - + id:string, + nome:string, + email:string, + dataNasc:string, + turmaId:string ) - { - + { + console.log("Chamando o constructor da Classe User") + this.id = id, + this.nome = nome, + this.email = email, + this.dataNasc = dataNasc + this.turmaId = turmaId } } \ No newline at end of file diff --git a/labenu-system/src/classes/docentes.ts b/labenu-system/src/classes/docentes.ts deleted file mode 100644 index 67a9a27..0000000 --- a/labenu-system/src/classes/docentes.ts +++ /dev/null @@ -1,30 +0,0 @@ - -export enum ESPECIALIDADES { - REACT = "React", - JS = "JS", - CSS = "CSS", - TYPESCRIPT = "Typescript", - PROGRAMACAO_ORIENTADA_A_OBJETO = "Programacao Orientada a Objetos", - - } - - -export class docentes { - private "id": string - public "nome": string - public "email": string - public "data_de_nascimento": string - public "turma_id": string - public "especialidades": ESPECIALIDADES[] - - - constructor(id:string , nome:string, email: string, data_de_nascimento:string, turma_id:string,especialidades:ESPECIALIDADES[] ,) { - this.id = id - this.nome = nome - this.email = email - this.data_de_nascimento = data_de_nascimento - this.turma_id = turma_id - this.especialidades = especialidades - - } - } \ No newline at end of file diff --git a/labenu-system/src/classes/estudantes.ts b/labenu-system/src/classes/estudantes.ts deleted file mode 100644 index dadd9ea..0000000 --- a/labenu-system/src/classes/estudantes.ts +++ /dev/null @@ -1,28 +0,0 @@ - -export enum HOBBIES { - ASSITIR_SERIE = "Assistir séries de TV", - JOGAR_VIDEO_GAME = "Jogar vídeogame", - SAIR_COM_AMIGOS = "Sair com amigos", - PRATICAR_ESPORTES = "Praticar esportes" - - } - -export class estudantes { - "id": string - "nome": string - "email": string - "data_de_nascimento": string - "turma_id": string - "hobbies": HOBBIES[] - - - constructor(id:string , nome:string, email: string, data_de_nascimento:string, turma_id:string,hobbies:HOBBIES[]) { - this.id = id - this.nome = nome - this.email = email - this.data_de_nascimento = data_de_nascimento - this.turma_id = turma_id - this.hobbies = hobbies - - } - } \ No newline at end of file diff --git a/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts index 6f00b5a..2073a42 100644 --- a/labenu-system/src/classes/turma.ts +++ b/labenu-system/src/classes/turma.ts @@ -1,4 +1,5 @@ - +import { Docente } from "./Docente" +import { Estudante } from "./Estudante" export enum MODULO { MODULO_0 = "Aulas não iniciadas", @@ -7,24 +8,28 @@ export enum MODULO { MODULO_3 = "Módulo 3", MODULO_4 = "Módulo 4", MODULO_5 = "Módulo 5", - MODULO_6 = "Módulo 6", - + MODULO_6 = "Módulo 6", } - export class Turma { "id": string "nome": string - "docentes": string - "estudantes": string - "modulo": string - + "docente": Docente + "estudante": Estudante + "modulo": MODULO - constructor(id:string , nome:string, docentes: string, estudantes:string, modulo:string ) { + constructor( + id:string, + nome:string, + docente:Docente, + estudante:Estudante, + modulo:MODULO + ) + { this.id = id; this.nome = nome; - this.docentes = docentes - this.estudantes = estudantes + this.docente = docente + this.estudante = estudante this.modulo = modulo } } diff --git a/labenu-system/src/endpoints.ts b/labenu-system/src/endpoints.ts deleted file mode 100644 index 8b13789..0000000 --- a/labenu-system/src/endpoints.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/labenu-system/src/endpoints/Criar.ts b/labenu-system/src/endpoints/Criar.ts new file mode 100644 index 0000000..7b70585 --- /dev/null +++ b/labenu-system/src/endpoints/Criar.ts @@ -0,0 +1,33 @@ +import { Request, Response } from "express"; +// import { Turma } from "../classes/Turma"; +import { v4 as generateId } from "uuid"; +import { Turma } from "../classes/Turma"; +import connection from "../connection"; + +export async function criarTurma(req:Request, res:Response) :Promise { + let errorCode = 400 + try { + const {nome, docente, estudante, modulo}:Turma = req.body + + if(!nome || !docente || !estudante || !modulo) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + await connection("LS_Turma") + .insert({ + id: generateId(), + nome:nome, + docente:docente, + estudante:estudante, + modulo:modulo + }) + + res.status(200).send("Turma criada!") + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Delete.ts b/labenu-system/src/endpoints/Delete.ts new file mode 100644 index 0000000..e69de29 diff --git a/labenu-system/src/endpoints/Request.ts b/labenu-system/src/endpoints/Request.ts new file mode 100644 index 0000000..e69de29 diff --git a/labenu-system/src/endpoints/Update.ts b/labenu-system/src/endpoints/Update.ts new file mode 100644 index 0000000..e69de29 diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index 96f9de5..94593e3 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -1,9 +1,12 @@ import connection from "./connection"; import app from "./app"; import { Request, Response } from "express"; +import { criarTurma } from "./endpoints/Criar"; // import { v4 as generateId } from "uuid" // TESTANDO FUNCIONAMENTO DA API app.get('/test', (req:Request, res:Response) => { res.status(200).send("Api funcionando!") -}); \ No newline at end of file +}); + +app.post('/turma', criarTurma) \ No newline at end of file From 24974ad1780ec18faddf8d835b858e7d822184f0 Mon Sep 17 00:00:00 2001 From: Tiago Hennig Date: Wed, 20 Jul 2022 20:44:55 -0300 Subject: [PATCH 05/11] em desenvolvimento --- labenu-system/querys.sql | 8 +- labenu-system/request.rest | 20 +++- labenu-system/src/classes/Docente.ts | 26 ++-- labenu-system/src/classes/Estudante.ts | 20 ++-- labenu-system/src/classes/User.ts | 12 +- labenu-system/src/classes/turma.ts | 32 ++--- labenu-system/src/connection.ts | 4 +- labenu-system/src/endpoints/Criar.ts | 158 +++++++++++++++++++++++-- labenu-system/src/index.ts | 5 +- 9 files changed, 218 insertions(+), 67 deletions(-) diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql index 1ea6718..03b034c 100644 --- a/labenu-system/querys.sql +++ b/labenu-system/querys.sql @@ -1,4 +1,4 @@ --- Active: 1657909499156@@35.226.146.116@3306@guimaraes-4211089-raul-rita +-- Active: 1658325348046@@35.226.146.116@3306@guimaraes-4211089-raul-rita USE `guimaraes-4211089-raul-rita`; CREATE TABLE LS_Turma( @@ -55,6 +55,8 @@ CREATE TABLE LS_Docente_Especialidade ( ); ALTER TABLE `LS_Turma` -MODIFY COLUMN modulo VARCHAR(255) NOT NULL; +MODIFY COLUMN modulo VARCHAR(255) NOT NULL DEFAULT 0; -SELECT * FROM `LS_Turma`; \ No newline at end of file +SELECT * FROM `LS_Turma`; + +SELECT * FROM LS_Turma INNER JOIN `LS_Estudante` ON LS_Turma.id = LS_Estudante.turma_id; \ No newline at end of file diff --git a/labenu-system/request.rest b/labenu-system/request.rest index aa4a609..211885b 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -6,8 +6,20 @@ POST http://localhost:3003/turma Content-Type: application/json { - "nome": "guimaraes", - "docente": "PH", - "estudante": "Talita", - "modulo": "MODULO.MODULO_6" + "nome": "abc", + "modulo": "Módulo 7" +} + +### + +POST http://localhost:3003/aluno +Content-Type: application/json + +{ + "nome": "lady gaga", + "email": "ladygaga@julia", + "data_nasc": "10/12/1993", + "turma_id": "adcedc99-cd88-4a6d-9614-6051298c30a9", + "hobby": ["Voar", "Nadar", "Cantar", "Dançar", "Pular"] + } \ No newline at end of file diff --git a/labenu-system/src/classes/Docente.ts b/labenu-system/src/classes/Docente.ts index 3eae6ea..99e8807 100644 --- a/labenu-system/src/classes/Docente.ts +++ b/labenu-system/src/classes/Docente.ts @@ -6,21 +6,21 @@ export enum ESPECIALIDADES { CSS = "CSS", TYPESCRIPT = "Typescript", PROGRAMACAO_ORIENTADA_A_OBJETO = "Programacao Orientada a Objetos", - } +} export class Docente extends User { - - public "especialidade": ESPECIALIDADES + + public "especialidade": ESPECIALIDADES - constructor( - id:string, - nome:string, - email:string, - dataNasc:string, - turmaId:string, - especialidade: ESPECIALIDADES + constructor( + id:string, + nome:string, + email:string, + data_nasc:string, + turma_id:string, + especialidade: ESPECIALIDADES ) { - super(id, nome, email, dataNasc, turmaId) - this.especialidade = especialidade + super(id, nome, email, data_nasc, turma_id) + this.especialidade = especialidade } - } \ No newline at end of file +} \ No newline at end of file diff --git a/labenu-system/src/classes/Estudante.ts b/labenu-system/src/classes/Estudante.ts index 9d1ac9e..a6983e1 100644 --- a/labenu-system/src/classes/Estudante.ts +++ b/labenu-system/src/classes/Estudante.ts @@ -1,25 +1,19 @@ import { User } from "./User" -export enum HOBBIES { - ASSITIR_SERIE = "Assistir séries de TV", - JOGAR_VIDEO_GAME = "Jogar vídeogame", - SAIR_COM_AMIGOS = "Sair com amigos", - PRATICAR_ESPORTES = "Praticar esportes" - } - + export class Estudante extends User{ - public "hobby" : HOBBIES + public "hobby":string | string[] constructor( id:string, nome:string, email:string, - dataNasc:string, - turmaId:string, - hobby:HOBBIES + data_nasc:string, + turma_id:string, + hobby:string | string[] ){ - super(id, nome, email, dataNasc, turmaId) + super(id, nome, email, data_nasc, turma_id) this.hobby = hobby } - + } \ No newline at end of file diff --git a/labenu-system/src/classes/User.ts b/labenu-system/src/classes/User.ts index 8781aec..31fd930 100644 --- a/labenu-system/src/classes/User.ts +++ b/labenu-system/src/classes/User.ts @@ -2,22 +2,22 @@ export class User { public "id": string public "nome": string public "email": string - public "dataNasc": string - public "turmaId": string + public "data_nasc": string + public "turma_id": string constructor( id:string, nome:string, email:string, - dataNasc:string, - turmaId:string + data_nasc:string, + turma_id:string ) { console.log("Chamando o constructor da Classe User") this.id = id, this.nome = nome, this.email = email, - this.dataNasc = dataNasc - this.turmaId = turmaId + this.data_nasc = data_nasc + this.turma_id = turma_id } } \ No newline at end of file diff --git a/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts index 2073a42..14488c6 100644 --- a/labenu-system/src/classes/turma.ts +++ b/labenu-system/src/classes/turma.ts @@ -2,14 +2,14 @@ import { Docente } from "./Docente" import { Estudante } from "./Estudante" export enum MODULO { - MODULO_0 = "Aulas não iniciadas", - MODULO_1 = "Módulo 1", - MODULO_2 = "Módulo 2", - MODULO_3 = "Módulo 3", - MODULO_4 = "Módulo 4", - MODULO_5 = "Módulo 5", - MODULO_6 = "Módulo 6", - } + MODULO_0 = "Aulas não iniciadas", + MODULO_1 = "1", + MODULO_2 = "2", + MODULO_3 = "3", + MODULO_4 = "4", + MODULO_5 = "5", + MODULO_6 = "6", +} export class Turma { "id": string @@ -24,12 +24,12 @@ export class Turma { docente:Docente, estudante:Estudante, modulo:MODULO - ) - { - this.id = id; - this.nome = nome; - this.docente = docente - this.estudante = estudante - this.modulo = modulo + ) + { + this.id = id; + this.nome = nome; + this.docente = docente + this.estudante = estudante + this.modulo = modulo } - } +} diff --git a/labenu-system/src/connection.ts b/labenu-system/src/connection.ts index 4ff5f00..c831b73 100644 --- a/labenu-system/src/connection.ts +++ b/labenu-system/src/connection.ts @@ -9,8 +9,8 @@ export const connection = knex({ host: process.env.DB_HOST, port: 3306, user: process.env.DB_USER, - password: process.env.DB_PASS, - database: process.env.DB_NAME + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA } }); diff --git a/labenu-system/src/endpoints/Criar.ts b/labenu-system/src/endpoints/Criar.ts index 7b70585..6c6878f 100644 --- a/labenu-system/src/endpoints/Criar.ts +++ b/labenu-system/src/endpoints/Criar.ts @@ -1,15 +1,21 @@ import { Request, Response } from "express"; // import { Turma } from "../classes/Turma"; import { v4 as generateId } from "uuid"; -import { Turma } from "../classes/Turma"; +import { Docente } from "../classes/Docente"; +import { Estudante } from "../classes/Estudante"; +import { MODULO, Turma } from "../classes/turma"; import connection from "../connection"; export async function criarTurma(req:Request, res:Response) :Promise { let errorCode = 400 try { - const {nome, docente, estudante, modulo}:Turma = req.body + const {nome, modulo}:Turma = req.body - if(!nome || !docente || !estudante || !modulo) { + if (!(Object.values(MODULO).includes(modulo))) { + res.send("Módulo inválido!") + } + + if(!nome) { errorCode = 400 res.send("Todos os campos são obrigatórios.") } @@ -17,11 +23,9 @@ export async function criarTurma(req:Request, res:Response) :Promise { await connection("LS_Turma") .insert({ id: generateId(), - nome:nome, - docente:docente, - estudante:estudante, - modulo:modulo - }) + nome, + modulo + }) res.status(200).send("Turma criada!") @@ -29,5 +33,143 @@ export async function criarTurma(req:Request, res:Response) :Promise { console.log(error) console.error(error) res.status(errorCode).send(error.message || error.sqlMessage) + } +} + +export async function criarAluno(req:Request, res:Response):Promise { + let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body + + if(!nome || !email || !data_nasc || !turma_id || !hobby) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + await connection("LS_Estudante") + .insert({ + id:generateId(), + nome, + email, + data_nasc: data_nasc, + turma_id: turma_id + }) + + + + + if (typeof(hobby) == "object") { + for (let h of hobby) { + let buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + console.log(buscaHobby) + + if (buscaHobby.length === 0) { + await connection("LS_Hobby") + .insert({ + id: generateId(), + nome_hobby: h + }) + + buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + } + + const response = await connection("LS_Estudante") + .select("id") + .where("email" ,"like", email) + console.log(response[0].id) + console.log() + + await connection("LS_Hobby_Estudante") + .insert({ + id:generateId(), + id_estudante: response[0].id, + id_hobby: buscaHobby[0].id + }) + } + res.status(200).send("Aluno cadastrado!") + return + } + + + + + + let buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", hobby) + console.log(buscaHobby) + + + if (buscaHobby.length === 0) { + await connection("LS_Hobby") + .insert({ + id: generateId(), + nome_hobby: hobby + }) + + buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", hobby) + } + + + + const response = await connection("LS_Estudante") + .select("id") + .where("email" ,"like", email) + console.log(response[0].id) + console.log() + + await connection("LS_Hobby_Estudante") + .insert({ + id:generateId(), + id_estudante: response[0].id, + id_hobby: buscaHobby[0].id + }) + + res.status(200).send("Aluno cadastrado!") + + + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + + + } +} + + +export async function criarDocente(req:Request, res:Response):Promise { + let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id}:Docente = req.body + + if(!nome || !email || !data_nasc || !turma_id) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + await connection("LS_Docente") + .insert({ + id:generateId(), + nome, + email, + data_nasc: data_nasc, + turma_id: turma_id + }) + res.status(200).send("Aluno cadastrado!") + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + + } } \ No newline at end of file diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index 94593e3..aa6ed12 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -1,7 +1,7 @@ import connection from "./connection"; import app from "./app"; import { Request, Response } from "express"; -import { criarTurma } from "./endpoints/Criar"; +import { criarAluno, criarTurma } from "./endpoints/Criar"; // import { v4 as generateId } from "uuid" // TESTANDO FUNCIONAMENTO DA API @@ -9,4 +9,5 @@ app.get('/test', (req:Request, res:Response) => { res.status(200).send("Api funcionando!") }); -app.post('/turma', criarTurma) \ No newline at end of file +app.post('/turma', criarTurma) +app.post("/aluno", criarAluno) \ No newline at end of file From 26ab932c7dc9fca4266d7ccec98904dec79682ff Mon Sep 17 00:00:00 2001 From: Tiago Hennig Date: Sat, 23 Jul 2022 14:12:01 -0300 Subject: [PATCH 06/11] em desenvolvimento --- labenu-system/request.rest | 3 +- labenu-system/src/classes/Estudante.ts | 4 +- labenu-system/src/endpoints/Criar.ts | 175 ------------------ .../src/endpoints/Criar/CriarAluno.ts | 70 +++++++ .../src/endpoints/Criar/CriarDocente.ts | 43 +++++ .../src/endpoints/Criar/CriarTurma.ts | 43 +++++ labenu-system/src/index.ts | 3 +- 7 files changed, 161 insertions(+), 180 deletions(-) delete mode 100644 labenu-system/src/endpoints/Criar.ts create mode 100644 labenu-system/src/endpoints/Criar/CriarAluno.ts create mode 100644 labenu-system/src/endpoints/Criar/CriarDocente.ts create mode 100644 labenu-system/src/endpoints/Criar/CriarTurma.ts diff --git a/labenu-system/request.rest b/labenu-system/request.rest index 211885b..f3c8632 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -7,7 +7,7 @@ Content-Type: application/json { "nome": "abc", - "modulo": "Módulo 7" + "modulo": "9" } ### @@ -21,5 +21,4 @@ Content-Type: application/json "data_nasc": "10/12/1993", "turma_id": "adcedc99-cd88-4a6d-9614-6051298c30a9", "hobby": ["Voar", "Nadar", "Cantar", "Dançar", "Pular"] - } \ No newline at end of file diff --git a/labenu-system/src/classes/Estudante.ts b/labenu-system/src/classes/Estudante.ts index a6983e1..0c77f91 100644 --- a/labenu-system/src/classes/Estudante.ts +++ b/labenu-system/src/classes/Estudante.ts @@ -2,7 +2,7 @@ import { User } from "./User" export class Estudante extends User{ - public "hobby":string | string[] + public "hobby": string[] constructor( id:string, @@ -10,7 +10,7 @@ export class Estudante extends User{ email:string, data_nasc:string, turma_id:string, - hobby:string | string[] + hobby:string[] ){ super(id, nome, email, data_nasc, turma_id) this.hobby = hobby diff --git a/labenu-system/src/endpoints/Criar.ts b/labenu-system/src/endpoints/Criar.ts deleted file mode 100644 index 6c6878f..0000000 --- a/labenu-system/src/endpoints/Criar.ts +++ /dev/null @@ -1,175 +0,0 @@ -import { Request, Response } from "express"; -// import { Turma } from "../classes/Turma"; -import { v4 as generateId } from "uuid"; -import { Docente } from "../classes/Docente"; -import { Estudante } from "../classes/Estudante"; -import { MODULO, Turma } from "../classes/turma"; -import connection from "../connection"; - -export async function criarTurma(req:Request, res:Response) :Promise { - let errorCode = 400 - try { - const {nome, modulo}:Turma = req.body - - if (!(Object.values(MODULO).includes(modulo))) { - res.send("Módulo inválido!") - } - - if(!nome) { - errorCode = 400 - res.send("Todos os campos são obrigatórios.") - } - - await connection("LS_Turma") - .insert({ - id: generateId(), - nome, - modulo - }) - - res.status(200).send("Turma criada!") - - } catch (error:any) { - console.log(error) - console.error(error) - res.status(errorCode).send(error.message || error.sqlMessage) - } -} - -export async function criarAluno(req:Request, res:Response):Promise { - let errorCode = 400 - try { - const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body - - if(!nome || !email || !data_nasc || !turma_id || !hobby) { - errorCode = 400 - res.send("Todos os campos são obrigatórios.") - } - - await connection("LS_Estudante") - .insert({ - id:generateId(), - nome, - email, - data_nasc: data_nasc, - turma_id: turma_id - }) - - - - - if (typeof(hobby) == "object") { - for (let h of hobby) { - let buscaHobby = await connection("LS_Hobby") - .select("id") - .where("nome_hobby", "like", h) - console.log(buscaHobby) - - if (buscaHobby.length === 0) { - await connection("LS_Hobby") - .insert({ - id: generateId(), - nome_hobby: h - }) - - buscaHobby = await connection("LS_Hobby") - .select("id") - .where("nome_hobby", "like", h) - } - - const response = await connection("LS_Estudante") - .select("id") - .where("email" ,"like", email) - console.log(response[0].id) - console.log() - - await connection("LS_Hobby_Estudante") - .insert({ - id:generateId(), - id_estudante: response[0].id, - id_hobby: buscaHobby[0].id - }) - } - res.status(200).send("Aluno cadastrado!") - return - } - - - - - - let buscaHobby = await connection("LS_Hobby") - .select("id") - .where("nome_hobby", "like", hobby) - console.log(buscaHobby) - - - if (buscaHobby.length === 0) { - await connection("LS_Hobby") - .insert({ - id: generateId(), - nome_hobby: hobby - }) - - buscaHobby = await connection("LS_Hobby") - .select("id") - .where("nome_hobby", "like", hobby) - } - - - - const response = await connection("LS_Estudante") - .select("id") - .where("email" ,"like", email) - console.log(response[0].id) - console.log() - - await connection("LS_Hobby_Estudante") - .insert({ - id:generateId(), - id_estudante: response[0].id, - id_hobby: buscaHobby[0].id - }) - - res.status(200).send("Aluno cadastrado!") - - - - } catch (error:any) { - console.log(error) - console.error(error) - res.status(errorCode).send(error.message || error.sqlMessage) - - - } -} - - -export async function criarDocente(req:Request, res:Response):Promise { - let errorCode = 400 - try { - const {nome, email, data_nasc, turma_id}:Docente = req.body - - if(!nome || !email || !data_nasc || !turma_id) { - errorCode = 400 - res.send("Todos os campos são obrigatórios.") - } - - await connection("LS_Docente") - .insert({ - id:generateId(), - nome, - email, - data_nasc: data_nasc, - turma_id: turma_id - }) - res.status(200).send("Aluno cadastrado!") - - } catch (error:any) { - console.log(error) - console.error(error) - res.status(errorCode).send(error.message || error.sqlMessage) - - - } -} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarAluno.ts b/labenu-system/src/endpoints/Criar/CriarAluno.ts new file mode 100644 index 0000000..bd476fd --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarAluno.ts @@ -0,0 +1,70 @@ +import { Request, Response } from "express"; +import { v4 as generateId } from "uuid"; +import { Estudante } from "../../classes/Estudante"; +import connection from "../../connection"; + + +export async function criarAluno(req:Request, res:Response):Promise { + let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body + const id = generateId() + + if(!nome || !email || !data_nasc || !turma_id || !hobby) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + const novoEstudante = new Estudante(id, nome, email, data_nasc, turma_id, hobby) + + await connection("LS_Estudante") + .insert({ + novoEstudante + }) + + if (typeof(hobby) != "object") { + res.status(400).send("O hobby deve vir em forma de array!") + return + } + + for (let h of hobby) { + let buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + console.log(buscaHobby) + + if (buscaHobby.length === 0) { + await connection("LS_Hobby") + .insert({ + id: generateId(), + nome_hobby: h + }) + + buscaHobby = await connection("LS_Hobby") + .select("id") + .where("nome_hobby", "like", h) + } + + const response = await connection("LS_Estudante") + .select("id") + .where("email" ,"like", email) + console.log(response[0].id) + console.log() + + await connection("LS_Hobby_Estudante") + .insert({ + id:generateId(), + id_estudante: response[0].id, + id_hobby: buscaHobby[0].id + }) + } + res.status(200).send("Aluno cadastrado!") + return + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarDocente.ts b/labenu-system/src/endpoints/Criar/CriarDocente.ts new file mode 100644 index 0000000..dd039f9 --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarDocente.ts @@ -0,0 +1,43 @@ +import { Request, Response } from "express"; +import { v4 as generateId } from "uuid"; +import { Docente, ESPECIALIDADES } from "../../classes/Docente"; +import connection from "../../connection"; + + +export async function criarDocente(req:Request, res:Response):Promise { + let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id, especialidade}:Docente = req.body + const id = generateId() + + if(!nome || !email || !data_nasc || !turma_id || !especialidade) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + if (typeof(especialidade) != "object") { + res.status(400).send("O hobby deve vir em forma de array!") + return + } + + if (!(Object.values(ESPECIALIDADES).includes(especialidade))) { + res.send("Verifique as especialidades digitadas!") + return + } + + const newDocente = new Docente(id, nome, email, data_nasc, turma_id, especialidade) + + await connection("LS_Docente") + .insert({ + newDocente + }) + res.status(200).send("Aluno cadastrado!") + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + + + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarTurma.ts b/labenu-system/src/endpoints/Criar/CriarTurma.ts new file mode 100644 index 0000000..cf6c0b9 --- /dev/null +++ b/labenu-system/src/endpoints/Criar/CriarTurma.ts @@ -0,0 +1,43 @@ +import { Request, Response } from "express"; +// import { Turma } from "../classes/Turma"; +import { v4 as generateId } from "uuid"; +import { Docente } from "../../classes/Docente"; +import { Estudante } from "../../classes/Estudante"; +import { MODULO, Turma } from "../../classes/turma"; +import connection from "../../connection"; + + +export async function criarTurma(req:Request, res:Response) :Promise { + let errorCode = 400 + try { + const {nome, modulo}:Turma = req.body + + if (!(Object.values(MODULO).includes(modulo))) { + res.send("Módulo inválido!") + return + } + + if(!nome) { + errorCode = 400 + res.send("Todos os campos são obrigatórios.") + } + + await connection("LS_Turma") + .insert({ + id: generateId(), + nome, + modulo + }) + + res.status(200).send("Turma criada!") + + } catch (error:any) { + console.log(error) + console.error(error) + res.status(errorCode).send(error.message || error.sqlMessage) + } +} + + + + diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index aa6ed12..f82d45b 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -1,7 +1,8 @@ import connection from "./connection"; import app from "./app"; import { Request, Response } from "express"; -import { criarAluno, criarTurma } from "./endpoints/Criar"; +import { criarTurma } from "./endpoints/Criar/CriarTurma"; +import { criarAluno } from "./endpoints/Criar/CriarAluno"; // import { v4 as generateId } from "uuid" // TESTANDO FUNCIONAMENTO DA API From b9d250dce0ebb52a35f57391c2ec999984888f5f Mon Sep 17 00:00:00 2001 From: raulrita08 Date: Sat, 23 Jul 2022 18:08:56 -0300 Subject: [PATCH 07/11] em desenvolvimento --- labenu-system/request.rest | 12 +++++----- labenu-system/src/classes/Docente.ts | 2 +- labenu-system/src/classes/Estudante.ts | 6 ++--- labenu-system/src/classes/turma.ts | 12 +++++----- .../{CriarAluno.ts => CriarEstudante.ts} | 22 +++++++------------ .../src/endpoints/Criar/CriarTurma.ts | 11 +++++----- labenu-system/src/endpoints/Delete.ts | 0 labenu-system/src/endpoints/Request.ts | 0 labenu-system/src/endpoints/Update.ts | 0 labenu-system/src/index.ts | 4 ++-- 10 files changed, 30 insertions(+), 39 deletions(-) rename labenu-system/src/endpoints/Criar/{CriarAluno.ts => CriarEstudante.ts} (81%) delete mode 100644 labenu-system/src/endpoints/Delete.ts delete mode 100644 labenu-system/src/endpoints/Request.ts delete mode 100644 labenu-system/src/endpoints/Update.ts diff --git a/labenu-system/request.rest b/labenu-system/request.rest index f3c8632..26e29c8 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -12,13 +12,13 @@ Content-Type: application/json ### -POST http://localhost:3003/aluno +POST http://localhost:3003/estudante Content-Type: application/json { - "nome": "lady gaga", - "email": "ladygaga@julia", - "data_nasc": "10/12/1993", - "turma_id": "adcedc99-cd88-4a6d-9614-6051298c30a9", - "hobby": ["Voar", "Nadar", "Cantar", "Dançar", "Pular"] + "nome": "Maria Karolina", + "email": "mariakarolina@email.com", + "data_nasc": "28/06/1993", + "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", + "hobby": ["Programar", "Nadar", "Dançar"] } \ No newline at end of file diff --git a/labenu-system/src/classes/Docente.ts b/labenu-system/src/classes/Docente.ts index 99e8807..b628551 100644 --- a/labenu-system/src/classes/Docente.ts +++ b/labenu-system/src/classes/Docente.ts @@ -5,7 +5,7 @@ export enum ESPECIALIDADES { JS = "JS", CSS = "CSS", TYPESCRIPT = "Typescript", - PROGRAMACAO_ORIENTADA_A_OBJETO = "Programacao Orientada a Objetos", + POO = "Programacao Orientada a Objetos", } export class Docente extends User { diff --git a/labenu-system/src/classes/Estudante.ts b/labenu-system/src/classes/Estudante.ts index 0c77f91..b81f752 100644 --- a/labenu-system/src/classes/Estudante.ts +++ b/labenu-system/src/classes/Estudante.ts @@ -2,18 +2,16 @@ import { User } from "./User" export class Estudante extends User{ - public "hobby": string[] + public hobby?: string[] constructor( id:string, nome:string, email:string, data_nasc:string, - turma_id:string, - hobby:string[] + turma_id:string ){ super(id, nome, email, data_nasc, turma_id) - this.hobby = hobby } } \ No newline at end of file diff --git a/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts index 14488c6..63e7e00 100644 --- a/labenu-system/src/classes/turma.ts +++ b/labenu-system/src/classes/turma.ts @@ -14,22 +14,22 @@ export enum MODULO { export class Turma { "id": string "nome": string - "docente": Docente - "estudante": Estudante + // "docente": Docente + // "estudante": Estudante "modulo": MODULO constructor( id:string, nome:string, - docente:Docente, - estudante:Estudante, + // docente:Docente, + // estudante:Estudante, modulo:MODULO ) { this.id = id; this.nome = nome; - this.docente = docente - this.estudante = estudante + // this.docente = docente + // this.estudante = estudante this.modulo = modulo } } diff --git a/labenu-system/src/endpoints/Criar/CriarAluno.ts b/labenu-system/src/endpoints/Criar/CriarEstudante.ts similarity index 81% rename from labenu-system/src/endpoints/Criar/CriarAluno.ts rename to labenu-system/src/endpoints/Criar/CriarEstudante.ts index bd476fd..6b9ecc7 100644 --- a/labenu-system/src/endpoints/Criar/CriarAluno.ts +++ b/labenu-system/src/endpoints/Criar/CriarEstudante.ts @@ -4,34 +4,31 @@ import { Estudante } from "../../classes/Estudante"; import connection from "../../connection"; -export async function criarAluno(req:Request, res:Response):Promise { +export async function criarEstudante(req:Request, res:Response):Promise { let errorCode = 400 try { const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body const id = generateId() - if(!nome || !email || !data_nasc || !turma_id || !hobby) { + if(!nome || !email || !data_nasc || !turma_id) { errorCode = 400 - res.send("Todos os campos são obrigatórios.") + res.status(400).send("Todos os campos são obrigatórios.") } - const novoEstudante = new Estudante(id, nome, email, data_nasc, turma_id, hobby) - - await connection("LS_Estudante") - .insert({ - novoEstudante - }) - if (typeof(hobby) != "object") { res.status(400).send("O hobby deve vir em forma de array!") return } + const novoEstudante = new Estudante(id, nome, email, data_nasc, turma_id) + + await connection("LS_Estudante") + .insert(novoEstudante) + for (let h of hobby) { let buscaHobby = await connection("LS_Hobby") .select("id") .where("nome_hobby", "like", h) - console.log(buscaHobby) if (buscaHobby.length === 0) { await connection("LS_Hobby") @@ -48,8 +45,6 @@ export async function criarAluno(req:Request, res:Response):Promise { const response = await connection("LS_Estudante") .select("id") .where("email" ,"like", email) - console.log(response[0].id) - console.log() await connection("LS_Hobby_Estudante") .insert({ @@ -65,6 +60,5 @@ export async function criarAluno(req:Request, res:Response):Promise { console.log(error) console.error(error) res.status(errorCode).send(error.message || error.sqlMessage) - } } \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarTurma.ts b/labenu-system/src/endpoints/Criar/CriarTurma.ts index cf6c0b9..e2d973e 100644 --- a/labenu-system/src/endpoints/Criar/CriarTurma.ts +++ b/labenu-system/src/endpoints/Criar/CriarTurma.ts @@ -1,8 +1,6 @@ import { Request, Response } from "express"; -// import { Turma } from "../classes/Turma"; import { v4 as generateId } from "uuid"; import { Docente } from "../../classes/Docente"; -import { Estudante } from "../../classes/Estudante"; import { MODULO, Turma } from "../../classes/turma"; import connection from "../../connection"; @@ -11,6 +9,7 @@ export async function criarTurma(req:Request, res:Response) :Promise { let errorCode = 400 try { const {nome, modulo}:Turma = req.body + const id = generateId() if (!(Object.values(MODULO).includes(modulo))) { res.send("Módulo inválido!") @@ -19,14 +18,14 @@ export async function criarTurma(req:Request, res:Response) :Promise { if(!nome) { errorCode = 400 - res.send("Todos os campos são obrigatórios.") + res.send("Insira o nome da Turma.") } + const novaTurma = new Turma(id, nome, modulo) + await connection("LS_Turma") .insert({ - id: generateId(), - nome, - modulo + novaTurma }) res.status(200).send("Turma criada!") diff --git a/labenu-system/src/endpoints/Delete.ts b/labenu-system/src/endpoints/Delete.ts deleted file mode 100644 index e69de29..0000000 diff --git a/labenu-system/src/endpoints/Request.ts b/labenu-system/src/endpoints/Request.ts deleted file mode 100644 index e69de29..0000000 diff --git a/labenu-system/src/endpoints/Update.ts b/labenu-system/src/endpoints/Update.ts deleted file mode 100644 index e69de29..0000000 diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index f82d45b..552535a 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -2,7 +2,7 @@ import connection from "./connection"; import app from "./app"; import { Request, Response } from "express"; import { criarTurma } from "./endpoints/Criar/CriarTurma"; -import { criarAluno } from "./endpoints/Criar/CriarAluno"; +import { criarEstudante } from "./endpoints/Criar/CriarEstudante"; // import { v4 as generateId } from "uuid" // TESTANDO FUNCIONAMENTO DA API @@ -11,4 +11,4 @@ app.get('/test', (req:Request, res:Response) => { }); app.post('/turma', criarTurma) -app.post("/aluno", criarAluno) \ No newline at end of file +app.post("/estudante", criarEstudante) \ No newline at end of file From bda6f8525879c902eddf792c3e6015ce1962dd66 Mon Sep 17 00:00:00 2001 From: Tiago Hennig Date: Sat, 23 Jul 2022 19:52:21 -0300 Subject: [PATCH 08/11] posts ok --- labenu-system/querys.sql | 8 +++- labenu-system/request.rest | 15 ++++++- labenu-system/src/classes/Docente.ts | 11 +---- .../src/endpoints/Criar/CriarDocente.ts | 40 +++++++++++++------ .../src/endpoints/Criar/CriarEstudante.ts | 2 +- .../src/endpoints/Criar/CriarTurma.ts | 4 +- labenu-system/src/index.ts | 4 +- 7 files changed, 55 insertions(+), 29 deletions(-) diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql index 03b034c..836dc6a 100644 --- a/labenu-system/querys.sql +++ b/labenu-system/querys.sql @@ -59,4 +59,10 @@ MODIFY COLUMN modulo VARCHAR(255) NOT NULL DEFAULT 0; SELECT * FROM `LS_Turma`; -SELECT * FROM LS_Turma INNER JOIN `LS_Estudante` ON LS_Turma.id = LS_Estudante.turma_id; \ No newline at end of file +SELECT * FROM LS_Turma INNER JOIN `LS_Estudante` ON LS_Turma.id = LS_Estudante.turma_id; + +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("1", "react"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("2", "js"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("3", "css"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("4", "typescript"); +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("5", "poo"); \ No newline at end of file diff --git a/labenu-system/request.rest b/labenu-system/request.rest index 26e29c8..c4f8aae 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -7,7 +7,7 @@ Content-Type: application/json { "nome": "abc", - "modulo": "9" + "modulo": "5" } ### @@ -21,4 +21,17 @@ Content-Type: application/json "data_nasc": "28/06/1993", "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", "hobby": ["Programar", "Nadar", "Dançar"] +} + +### + +POST http://localhost:3003/docente +Content-Type: application/json + +{ + "nome": "Juliana", + "email": "juliana@email.com", + "data_nasc": "28/06/1990", + "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", + "especialidade": ["React", "JS", "poo"] } \ No newline at end of file diff --git a/labenu-system/src/classes/Docente.ts b/labenu-system/src/classes/Docente.ts index b628551..94770ce 100644 --- a/labenu-system/src/classes/Docente.ts +++ b/labenu-system/src/classes/Docente.ts @@ -1,16 +1,9 @@ import { User } from "./User" -export enum ESPECIALIDADES { - REACT = "React", - JS = "JS", - CSS = "CSS", - TYPESCRIPT = "Typescript", - POO = "Programacao Orientada a Objetos", -} export class Docente extends User { - public "especialidade": ESPECIALIDADES + public especialidade?: string[] constructor( id:string, @@ -18,9 +11,7 @@ export class Docente extends User { email:string, data_nasc:string, turma_id:string, - especialidade: ESPECIALIDADES ) { super(id, nome, email, data_nasc, turma_id) - this.especialidade = especialidade } } \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarDocente.ts b/labenu-system/src/endpoints/Criar/CriarDocente.ts index dd039f9..6b5b4ec 100644 --- a/labenu-system/src/endpoints/Criar/CriarDocente.ts +++ b/labenu-system/src/endpoints/Criar/CriarDocente.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import { v4 as generateId } from "uuid"; -import { Docente, ESPECIALIDADES } from "../../classes/Docente"; +import { Docente} from "../../classes/Docente"; import connection from "../../connection"; @@ -16,22 +16,38 @@ export async function criarDocente(req:Request, res:Response):Promise { } if (typeof(especialidade) != "object") { - res.status(400).send("O hobby deve vir em forma de array!") + res.status(400).send("A(s) especialidade(s) deve(m) vir em forma de array!") return } - if (!(Object.values(ESPECIALIDADES).includes(especialidade))) { - res.send("Verifique as especialidades digitadas!") - return + const novoDocente = new Docente(id, nome, email, data_nasc, turma_id) + await connection("LS_Docente") + .insert(novoDocente) + + for (let e of especialidade) { + let buscaEspecialidade = await connection("LS_Especialidade").select("id") + .where("nome_especialidade", "like", e.toLowerCase()) + + const response = await connection("LS_Docente") + .select("id") + .where("email", "like", email) + + if (buscaEspecialidade.length === 0) { + await connection("LS_Docente_Especialidade").delete().where("id_docente", "like", response[0].id) + await connection("LS_Docente").delete().where("email", "like", email) + res.send("Uma ou mais especialidades digitadas não existem.") + return + } + + await connection("LS_Docente_Especialidade") + .insert({ + id: generateId(), + id_docente: response[0].id, + id_especialidade: buscaEspecialidade[0].id + }) } - const newDocente = new Docente(id, nome, email, data_nasc, turma_id, especialidade) - - await connection("LS_Docente") - .insert({ - newDocente - }) - res.status(200).send("Aluno cadastrado!") + res.status(200).send("Docente cadastrado!") } catch (error:any) { console.log(error) diff --git a/labenu-system/src/endpoints/Criar/CriarEstudante.ts b/labenu-system/src/endpoints/Criar/CriarEstudante.ts index 6b9ecc7..d54fe3c 100644 --- a/labenu-system/src/endpoints/Criar/CriarEstudante.ts +++ b/labenu-system/src/endpoints/Criar/CriarEstudante.ts @@ -16,7 +16,7 @@ export async function criarEstudante(req:Request, res:Response):Promise { } if (typeof(hobby) != "object") { - res.status(400).send("O hobby deve vir em forma de array!") + res.status(400).send("O(s) hobby(s) deve(m) vir em forma de array!") return } diff --git a/labenu-system/src/endpoints/Criar/CriarTurma.ts b/labenu-system/src/endpoints/Criar/CriarTurma.ts index e2d973e..ef435f4 100644 --- a/labenu-system/src/endpoints/Criar/CriarTurma.ts +++ b/labenu-system/src/endpoints/Criar/CriarTurma.ts @@ -24,9 +24,7 @@ export async function criarTurma(req:Request, res:Response) :Promise { const novaTurma = new Turma(id, nome, modulo) await connection("LS_Turma") - .insert({ - novaTurma - }) + .insert(novaTurma) res.status(200).send("Turma criada!") diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index 552535a..16d3077 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -3,6 +3,7 @@ import app from "./app"; import { Request, Response } from "express"; import { criarTurma } from "./endpoints/Criar/CriarTurma"; import { criarEstudante } from "./endpoints/Criar/CriarEstudante"; +import { criarDocente } from "./endpoints/Criar/CriarDocente"; // import { v4 as generateId } from "uuid" // TESTANDO FUNCIONAMENTO DA API @@ -11,4 +12,5 @@ app.get('/test', (req:Request, res:Response) => { }); app.post('/turma', criarTurma) -app.post("/estudante", criarEstudante) \ No newline at end of file +app.post("/estudante", criarEstudante) +app.post("/docente", criarDocente) \ No newline at end of file From 4f4f2b0a81a8ea166c8457c95ffedf5ed06592cc Mon Sep 17 00:00:00 2001 From: Tiago Hennig Date: Sun, 24 Jul 2022 17:43:02 -0300 Subject: [PATCH 09/11] finalizando --- labenu-system/package.json | 2 +- labenu-system/querys.sql | 10 +++- labenu-system/request.rest | 60 ++++++++++++++++--- labenu-system/src/classes/turma.ts | 11 +--- .../src/endpoints/Buscar/BuscarAlunos.ts | 31 ++++++++++ .../src/endpoints/Buscar/BuscarDocentes.ts | 19 ++++++ .../endpoints/Buscar/BuscarTodasAsTurmas.ts | 19 ++++++ .../endpoints/Buscar/BuscarTurmasAtivas.ts | 20 +++++++ .../src/endpoints/Criar/CriarDocente.ts | 11 ++-- .../src/endpoints/Criar/CriarEstudante.ts | 12 ++-- .../src/endpoints/Criar/CriarTurma.ts | 10 ++-- .../src/endpoints/Mudar/MudarAlunoTurma.ts | 41 +++++++++++++ .../src/endpoints/Mudar/MudarDocenteTurma.ts | 39 ++++++++++++ .../src/endpoints/Mudar/MudarTurmaModulo.ts | 36 +++++++++++ labenu-system/src/index.ts | 28 +++++---- 15 files changed, 302 insertions(+), 47 deletions(-) create mode 100644 labenu-system/src/endpoints/Buscar/BuscarAlunos.ts create mode 100644 labenu-system/src/endpoints/Buscar/BuscarDocentes.ts create mode 100644 labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts create mode 100644 labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts create mode 100644 labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts create mode 100644 labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts create mode 100644 labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts diff --git a/labenu-system/package.json b/labenu-system/package.json index 8874279..d2aba23 100644 --- a/labenu-system/package.json +++ b/labenu-system/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "ts-node-dev ./src/index.ts", "start": "tsc && node ./build/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "build": "tsc" }, "keywords": [], "author": "", diff --git a/labenu-system/querys.sql b/labenu-system/querys.sql index 836dc6a..4ec3ab8 100644 --- a/labenu-system/querys.sql +++ b/labenu-system/querys.sql @@ -65,4 +65,12 @@ INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("1", "react"); INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("2", "js"); INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("3", "css"); INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("4", "typescript"); -INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("5", "poo"); \ No newline at end of file +INSERT INTO `LS_Especialidade`(id,nome_especialidade) VALUES ("5", "poo"); + + +SELECT nome, nome_hobby +FROM LS_Hobby_Estudante + INNER JOIN LS_Estudante + ON LS_Hobby_Estudante.id_estudante = LS_Estudante.id + INNER JOIN LS_Hobby + ON LS_Hobby_Estudante.id_hobby = "8c1fa295-c2b9-4e9f-b62e-7ab486f546af"; \ No newline at end of file diff --git a/labenu-system/request.rest b/labenu-system/request.rest index c4f8aae..e03a016 100644 --- a/labenu-system/request.rest +++ b/labenu-system/request.rest @@ -1,8 +1,4 @@ -GET http://localhost:3003/test - -### - -POST http://localhost:3003/turma +POST http://localhost:3003/turma/ Content-Type: application/json { @@ -12,7 +8,7 @@ Content-Type: application/json ### -POST http://localhost:3003/estudante +POST http://localhost:3003/estudante/ Content-Type: application/json { @@ -25,7 +21,7 @@ Content-Type: application/json ### -POST http://localhost:3003/docente +POST http://localhost:3003/docente/ Content-Type: application/json { @@ -34,4 +30,52 @@ Content-Type: application/json "data_nasc": "28/06/1990", "turma_id": "b555b321-8c42-4fab-9083-022c83b965d6", "especialidade": ["React", "JS", "poo"] -} \ No newline at end of file +} + +### + +GET http://localhost:3003/turma/ativa + +### + +GET http://localhost:3003/turma/ + +### + +Get http://localhost:3003/estudante/?nome= + +### + +GET http://localhost:3003/docente/ + +### + + + +PUT http://localhost:3003/turma/guimaraes +Content-Type: application/json + +{ + "modulo": "1" +} + +### + +PUT http://localhost:3003/estudante/ +Content-Type: application/json + +{ + "id": "a28cafd1-88e4-42b5-951a-1c075d08b8dd", + "turma": "joy" +} + +### + +PUT http://localhost:3003/docente/ +Content-Type: application/json + +{ + "id": "00800266-93f3-4d5c-b93d-3b6348afd150", + "turma": "joi" +} + diff --git a/labenu-system/src/classes/turma.ts b/labenu-system/src/classes/turma.ts index 63e7e00..b8060ac 100644 --- a/labenu-system/src/classes/turma.ts +++ b/labenu-system/src/classes/turma.ts @@ -1,8 +1,5 @@ -import { Docente } from "./Docente" -import { Estudante } from "./Estudante" - export enum MODULO { - MODULO_0 = "Aulas não iniciadas", + MODULO_0 = "0", MODULO_1 = "1", MODULO_2 = "2", MODULO_3 = "3", @@ -14,22 +11,16 @@ export enum MODULO { export class Turma { "id": string "nome": string - // "docente": Docente - // "estudante": Estudante "modulo": MODULO constructor( id:string, nome:string, - // docente:Docente, - // estudante:Estudante, modulo:MODULO ) { this.id = id; this.nome = nome; - // this.docente = docente - // this.estudante = estudante this.modulo = modulo } } diff --git a/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts b/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts new file mode 100644 index 0000000..9e855de --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarAlunos.ts @@ -0,0 +1,31 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarAlunos(req:Request, res:Response) { + + let errorCode = 400 + + try { + + const nome = req.query.nome + + if (!nome) { + const response = await connection("LS_Estudante") + .select("*") + + res.status(200).send(response) + return + } + + const response = await connection("LS_Estudante") + .select("*") + .where("nome", "like", `%${nome}%`) + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts b/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts new file mode 100644 index 0000000..b5e48ab --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarDocentes.ts @@ -0,0 +1,19 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarDocentes(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Docente") + .select("*") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts b/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts new file mode 100644 index 0000000..41275db --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarTodasAsTurmas.ts @@ -0,0 +1,19 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarTodasAsTurmas(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Turma") + .select("*") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts b/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts new file mode 100644 index 0000000..51881e9 --- /dev/null +++ b/labenu-system/src/endpoints/Buscar/BuscarTurmasAtivas.ts @@ -0,0 +1,20 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + + +export async function BuscarTurmasAtivas(req:Request, res:Response) { + let errorCode = 400 + + try { + + const response = await connection("LS_Turma") + .select("*") + .where("modulo", "not like", "0") + + res.status(200).send(response) + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } + +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarDocente.ts b/labenu-system/src/endpoints/Criar/CriarDocente.ts index 6b5b4ec..3d9860d 100644 --- a/labenu-system/src/endpoints/Criar/CriarDocente.ts +++ b/labenu-system/src/endpoints/Criar/CriarDocente.ts @@ -6,7 +6,9 @@ import connection from "../../connection"; export async function criarDocente(req:Request, res:Response):Promise { let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id, especialidade}:Docente = req.body const id = generateId() @@ -16,7 +18,7 @@ export async function criarDocente(req:Request, res:Response):Promise { } if (typeof(especialidade) != "object") { - res.status(400).send("A(s) especialidade(s) deve(m) vir em forma de array!") + res.status(errorCode).send("A(s) especialidade(s) deve(m) vir em forma de array!") return } @@ -25,7 +27,8 @@ export async function criarDocente(req:Request, res:Response):Promise { .insert(novoDocente) for (let e of especialidade) { - let buscaEspecialidade = await connection("LS_Especialidade").select("id") + let buscaEspecialidade = await connection("LS_Especialidade") + .select("id") .where("nome_especialidade", "like", e.toLowerCase()) const response = await connection("LS_Docente") @@ -50,10 +53,6 @@ export async function criarDocente(req:Request, res:Response):Promise { res.status(200).send("Docente cadastrado!") } catch (error:any) { - console.log(error) - console.error(error) res.status(errorCode).send(error.message || error.sqlMessage) - - } } \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarEstudante.ts b/labenu-system/src/endpoints/Criar/CriarEstudante.ts index d54fe3c..74c6a96 100644 --- a/labenu-system/src/endpoints/Criar/CriarEstudante.ts +++ b/labenu-system/src/endpoints/Criar/CriarEstudante.ts @@ -6,17 +6,19 @@ import connection from "../../connection"; export async function criarEstudante(req:Request, res:Response):Promise { let errorCode = 400 + try { + const {nome, email, data_nasc, turma_id, hobby}:Estudante = req.body const id = generateId() if(!nome || !email || !data_nasc || !turma_id) { - errorCode = 400 - res.status(400).send("Todos os campos são obrigatórios.") + errorCode = 404 + res.status(errorCode).send("Todos os campos são obrigatórios.") } if (typeof(hobby) != "object") { - res.status(400).send("O(s) hobby(s) deve(m) vir em forma de array!") + res.status(errorCode).send("O(s) hobby(s) deve(m) vir em forma de array!") return } @@ -53,12 +55,10 @@ export async function criarEstudante(req:Request, res:Response):Promise { id_hobby: buscaHobby[0].id }) } + res.status(200).send("Aluno cadastrado!") - return } catch (error:any) { - console.log(error) - console.error(error) res.status(errorCode).send(error.message || error.sqlMessage) } } \ No newline at end of file diff --git a/labenu-system/src/endpoints/Criar/CriarTurma.ts b/labenu-system/src/endpoints/Criar/CriarTurma.ts index ef435f4..ed48315 100644 --- a/labenu-system/src/endpoints/Criar/CriarTurma.ts +++ b/labenu-system/src/endpoints/Criar/CriarTurma.ts @@ -1,24 +1,26 @@ import { Request, Response } from "express"; import { v4 as generateId } from "uuid"; -import { Docente } from "../../classes/Docente"; import { MODULO, Turma } from "../../classes/turma"; import connection from "../../connection"; export async function criarTurma(req:Request, res:Response) :Promise { let errorCode = 400 + try { + const {nome, modulo}:Turma = req.body const id = generateId() if (!(Object.values(MODULO).includes(modulo))) { - res.send("Módulo inválido!") + errorCode = 404 + res.status(errorCode).send("Módulo inválido!") return } if(!nome) { errorCode = 400 - res.send("Insira o nome da Turma.") + res.status(errorCode).send("Insira o nome da Turma.") } const novaTurma = new Turma(id, nome, modulo) @@ -29,8 +31,6 @@ export async function criarTurma(req:Request, res:Response) :Promise { res.status(200).send("Turma criada!") } catch (error:any) { - console.log(error) - console.error(error) res.status(errorCode).send(error.message || error.sqlMessage) } } diff --git a/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts b/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts new file mode 100644 index 0000000..3011bb9 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarAlunoTurma.ts @@ -0,0 +1,41 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + +export async function MudarAlunoTurma(req:Request, res:Response) { + let errorCode = 400 + + try { + + const id = req.body.id + const turma = req.body.turma + + const idDaTurma = await connection("LS_Turma") + .select("id") + .where("nome","like", turma) + + if (idDaTurma.length == 0){ + errorCode = 404 + res.status(errorCode).send("A turma não existe.") + return + } + + const buscaAluno = await connection("LS_Estudante") + .select("*") + .where("id", "like", id) + + if (buscaAluno.length == 0) { + errorCode = 404 + res.status(errorCode).send("O aluno digitado não existe.") + return + } + + await connection("LS_Estudante") + .update("turma_id", idDaTurma[0].id) + .where("id", "like", id) + + res.status(200).send("Turma alterada!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts b/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts new file mode 100644 index 0000000..d5c2049 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarDocenteTurma.ts @@ -0,0 +1,39 @@ +import { Request, Response } from "express"; +import connection from "../../connection"; + +export async function MudarDocenteTurma(req:Request, res:Response) { + let errorCode = 400 + + try { + + const id = req.body.id + const turma = req.body.turma + + const idDaTurma = await connection("LS_Turma") + .select("id") + .where("nome","like", turma) + + if (idDaTurma.length == 0){ + res.status(errorCode).send("A turma não existe.") + return + } + + const buscaDocente = await connection("LS_Docente") + .select("*") + .where("id", "like", id) + + if (buscaDocente.length == 0) { + res.status(errorCode).send("O docente digitado não existe.") + return + } + + await connection("LS_Docente") + .update("turma_id", idDaTurma[0].id) + .where("id", "like", id) + + res.status(200).send("Turma alterada!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts b/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts new file mode 100644 index 0000000..d0ea376 --- /dev/null +++ b/labenu-system/src/endpoints/Mudar/MudarTurmaModulo.ts @@ -0,0 +1,36 @@ +import { Request, Response } from "express"; +import { MODULO } from "../../classes/turma"; +import connection from "../../connection"; + +export async function MudarTurmaModulo(req:Request, res:Response) { + let errorCode = 400 + + try { + + const nome = req.params.nome + const modulo = req.body.modulo + + if (!(Object.values(MODULO).includes(modulo))) { + res.send("Módulo inválido!") + return + } + + const buscaTurma = await connection("LS_Turma") + .select("*") + .where("nome", "like", nome) + + if (buscaTurma.length == 0) { + res.status(404).send("A turma digitada não existe.") + return + } + + await connection("LS_Turma") + .update("modulo", modulo) + .where("nome", "like", nome) + + res.status(200).send("Módulo alterado!") + + } catch (error:any) { + res.status(errorCode).send(error.message || error.sqlMessage) + } +} \ No newline at end of file diff --git a/labenu-system/src/index.ts b/labenu-system/src/index.ts index 16d3077..7b4f970 100644 --- a/labenu-system/src/index.ts +++ b/labenu-system/src/index.ts @@ -1,16 +1,24 @@ -import connection from "./connection"; import app from "./app"; -import { Request, Response } from "express"; import { criarTurma } from "./endpoints/Criar/CriarTurma"; import { criarEstudante } from "./endpoints/Criar/CriarEstudante"; import { criarDocente } from "./endpoints/Criar/CriarDocente"; -// import { v4 as generateId } from "uuid" +import { BuscarTurmasAtivas } from "./endpoints/Buscar/BuscarTurmasAtivas"; +import { BuscarTodasAsTurmas } from "./endpoints/Buscar/BuscarTodasAsTurmas"; +import { BuscarAlunos } from "./endpoints/Buscar/BuscarAlunos"; +import { BuscarDocentes } from "./endpoints/Buscar/BuscarDocentes"; +import { MudarTurmaModulo } from "./endpoints/Mudar/MudarTurmaModulo"; +import { MudarAlunoTurma } from "./endpoints/Mudar/MudarAlunoTurma"; +import { MudarDocenteTurma } from "./endpoints/Mudar/MudarDocenteTurma"; -// TESTANDO FUNCIONAMENTO DA API -app.get('/test', (req:Request, res:Response) => { - res.status(200).send("Api funcionando!") -}); +app.post('/turma/', criarTurma) +app.post("/estudante/", criarEstudante) +app.post("/docente/", criarDocente) -app.post('/turma', criarTurma) -app.post("/estudante", criarEstudante) -app.post("/docente", criarDocente) \ No newline at end of file +app.get('/turma/ativa', BuscarTurmasAtivas) +app.get('/turma/', BuscarTodasAsTurmas) +app.get('/estudante/', BuscarAlunos) +app.get('/docente/', BuscarDocentes) + +app.put('/turma/:nome', MudarTurmaModulo) +app.put('/estudante/', MudarAlunoTurma) +app.put('/docente/', MudarDocenteTurma) From efa2f144303eb1fc7222f9e2987f67c6ee58ad70 Mon Sep 17 00:00:00 2001 From: Tiago Hennig Date: Sun, 24 Jul 2022 18:05:43 -0300 Subject: [PATCH 10/11] finalizando --- labenu-system/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labenu-system/package.json b/labenu-system/package.json index d2aba23..33a3158 100644 --- a/labenu-system/package.json +++ b/labenu-system/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "dev": "ts-node-dev ./src/index.ts", - "start": "tsc && node ./build/index.js", + "start": "node ./build/index.js", "build": "tsc" }, "keywords": [], From f864d164c279d0a1f512f81e61714e2153af4423 Mon Sep 17 00:00:00 2001 From: Tiago Hennig <86529848+tiagohennig@users.noreply.github.com> Date: Sun, 24 Jul 2022 19:35:54 -0300 Subject: [PATCH 11/11] Update README.md --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 978a24d..bf6fe8a 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,62 @@ -## LabenuSystem: +

💻 LabeSystem 💻

-Você estuda na Labenu_ há tanto tempo que já parecem anos, não é? Então, hoje, vamos pedir para criar um sistema que represente o básico da nossa organização. +

📃 Sobre 📃

+

Projeto de backend desenvolvido conforme proposta da Labenu para criação de uma API para um sistema de uma escola de programação.

-Ele deve possuir, ao menos, as 3 entidades importantes: +Esse sistema possui 3 entidades importantes: -1. Estudantes +

Estudantes

- Representa estudantes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e os principais hobbies dele. +

Representa estudantes da instituição. Eles possuem: id, nome, email, data de nascimento e os principais hobbies deles.

-2. Docente +

Docente

- Representa docentes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e todas as especialidades dele. Há 7 especialidades: React, Redux, CSS, Testes, Typescript, Programação Orientada a Objetos e Backend +

Representa docentes da instituição. Eles possuem: id, nome, email, data de nascimento e todas as especialidades deles. Há 5 especialidades: React, JS, CSS, Typescript, POO.

-3. Turma +

Turma

- Toda turma é composta das seguintes características: id, nome, data de início, data de término, lista de professores responsáveis, uma lista de alunos e módulo atual em que a turma está. +

Toda turma é composta das seguintes características: id, nome e módulo atual em que a turma está.

+

O módulo pode assumir os valores de 1 a 6, ou 0, indicando que as aulas dessa turma ainda não começaram.

- O módulo pode assumir os valores de 1 a 7 ou `undefined`, indicando que as aulas dessa turma ainda não começaram. Para esse exercício, vamos considerar que existam dois tipos de turma: integral ou noturna. Há uma restrição para o nome das turmas noturnas: tem que terminar com `-na-night`. +

📝 Documentação 📝

-As funcionalidades básicas são: +

https://documenter.getpostman.com/view/19721031/UzXKXeSC

-→ Criar estudante; +

✅ O que funciona ✅

-→ Criar docente; +* Criar estudante; +* Criar docente; +* Criar turma; +* Mudar aluno de turma; +* Mudar docente de turma; +* Mudar módulo da turma; +* Buscar alunos; +* Buscar docentes; +* Buscar todas as turmas; +* Buscar turmas ativas; -→ Criar turma; +

🛠 Em desenvolvimento 🛠

-→ Adicionar estudante na turma; +* Ao buscar alunos não é exibido a lista de hobbies deles. +* Ao buscar docentes não é exibido a lista de especialidades deles. -→ Adicionar docente na turma; +

👨‍💻 Desenvolvedores 👩‍💻

-→ Pegar a idade de algum estudante a partir do id + + + + + + + + + + + +
+
+ Tiago Hennig
+
+ Raul Rita
+
+ Maria Karolina Freitas