-
Notifications
You must be signed in to change notification settings - Fork 0
PR de Correção #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jvpalves
wants to merge
38
commits into
correcao-projeto
Choose a base branch
from
master
base: correcao-projeto
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PR de Correção #21
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
0596c93
Configurado projeto.
Shidoshi93 782badd
Merge pull request #4 from future4code/daniel-versao-3
Shidoshi93 a9b4e12
parte de criar estudante, professor e turma criada, junto com seus re…
Bruno-Vallim 65f7f93
Merge pull request #5 from future4code/bruno2
Shidoshi93 82662a7
Implementado funcionalidade de troca de turma.
Shidoshi93 8385720
Merge pull request #6 from future4code/updateClass-vesao-1
Bruno-Vallim de37a0d
Feito refatoramento nos códigos das funcionalidades existentes até ag…
Shidoshi93 ae2a469
Merge pull request #7 from future4code/refator-funcionalidades
Bruno-Vallim e5912d1
feito o primeiro desafio, pegar nome dos estudantes por turma
Bruno-Vallim 2fb9a18
Resolvido bug no script de criar tabelas.
Shidoshi93 7deae1b
Merge pull request #8 from future4code/bruno4
Shidoshi93 deab8cd
Merge branch 'master' into create-table
Shidoshi93 a4cdd98
Merge pull request #9 from future4code/create-table
Bruno-Vallim 0560940
Implementado funcionalidade de pegar idade.
Shidoshi93 21daaa3
Refatorado funcionalidade de pegar idade, para funcionar tanto para a…
Shidoshi93 72abadf
Merge pull request #10 from future4code/get-age
Shidoshi93 95c4295
Refatorado funcionalidade de pegar estudantes por turma.
Shidoshi93 d8fc20b
Merge pull request #13 from future4code/get-class-student-refatorado
Shidoshi93 ff0a679
Implementado funcionalidade de pegar professor pela classe.
Shidoshi93 2f4d459
Merge pull request #14 from future4code/get-teacher-by-class
Shidoshi93 031a85e
Implementado funcionalidade de pegar alunos por hobby.
Shidoshi93 3894731
Merge pull request #15 from future4code/get-students-by-hobby
Shidoshi93 cf7357c
Implementado funcionalidade de remover aluno de turma.
Shidoshi93 ef41f7f
Merge pull request #16 from future4code/remove-student-from-class
Shidoshi93 6b163f6
Implementado funcinalidade de remover estudante do curso.
Shidoshi93 01e73a8
Merge pull request #17 from future4code/remove-student
Shidoshi93 21e72fc
IMplementado funcionalidade de remover professor da turma.
Shidoshi93 53ecc86
Merge pull request #18 from future4code/remove-teacher-from-classs
Shidoshi93 4720896
Implementado funcionalidade de alterar módulo da turma.
Shidoshi93 8e7e26e
Merge pull request #19 from future4code/change-module
Shidoshi93 e53236d
Refatoração final. Projeto concluído.
Shidoshi93 4a99de1
Merge pull request #20 from future4code/refatoracao-final
Shidoshi93 d3cc9f3
Update README.md
Shidoshi93 0a57f60
Update README.md
Shidoshi93 712c529
Update README.md
Shidoshi93 4b76078
Update README.md
Shidoshi93 10251d0
Update README.md
Shidoshi93 fa3a2f3
Update README.md
Shidoshi93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| node_modules | ||
| .env | ||
| package-lock.json | ||
| build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,65 @@ | ||
| ## LabenuSystem: | ||
|
|
||
| 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. | ||
|
|
||
| Ele deve possuir, ao menos, as 3 entidades importantes: | ||
|
|
||
| 1. Estudantes | ||
|
|
||
| Representa estudantes da nossa instituição. Eles devem possuir: id, nome, email, data de nascimento e os principais hobbies dele. | ||
|
|
||
| 2. 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 | ||
|
|
||
| 3. 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á. | ||
|
|
||
| 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`. | ||
|
|
||
| As funcionalidades básicas são: | ||
|
|
||
| → Criar estudante; | ||
|
|
||
| → Criar docente; | ||
|
|
||
| → Criar turma; | ||
|
|
||
| → Adicionar estudante na turma; | ||
|
|
||
| → Adicionar docente na turma; | ||
|
|
||
| → Pegar a idade de algum estudante a partir do id | ||
| # LabenuSystem | ||
|
|
||
| ## :memo: Funcionalidades | ||
| * Criar estudante | ||
| * Criar docente | ||
| * Criar turma | ||
| * Adicionar estudante a turma | ||
| * Adicionar docente a turma | ||
| * Pegar a idade de algum estudante a partir do ID | ||
| * Exibir estudantes de uma turma | ||
| * Exibir docentes de uma turma | ||
| * Exibir estudantes que possuam o mesmo hobby | ||
| * Remover estudante de uma turma | ||
| * Remover estudante do curso | ||
| * Remover docente de uma turma | ||
| * Mudar turma de módulo | ||
|
|
||
| ## 💻 Documentação | ||
| Teste as rotas com a documentação, basta importar ela para seu postman. | ||
|
|
||
| [Postman - LabenuSystem](https://documenter.getpostman.com/view/14146800/TzCQb737) | ||
|
|
||
| ## ✨ Tecnologias | ||
| Esse projeto foi desenvolvido com as seguintes tecnologias: | ||
|
|
||
| * Node | ||
| * Express | ||
| * Typescript | ||
| * Cors | ||
| * Knex | ||
| * MySQL | ||
| * Dotenv | ||
|
|
||
| ## 🚀 Como executar | ||
| * Clone o repositório: | ||
|
|
||
| https://github.com/future4code/epps-labenu-system8 | ||
|
|
||
| * Instale as dependências com | ||
| ``` | ||
| npm install | ||
| ``` | ||
| * Crie um arquivo .env | ||
| ``` | ||
| touch .env | ||
| ``` | ||
| * Preencha o arquivo .env | ||
| ``` | ||
| DB_HOST = Coloque aqui seu endereço do banco de dados | ||
| DB_USER = Coloque aqui seu usuário | ||
| DB_PASSWORD = Coloque aqui sua senha | ||
| DB_NAME = Coloque aqui o nome do banco de dados | ||
| ``` | ||
| * Crie as tabelas com | ||
| ``` | ||
| npm run tables | ||
| ``` | ||
| * Inicie o servidor com | ||
| ``` | ||
| npm run dev | ||
| ``` | ||
|
|
||
| ## Desenvolvido por: | ||
| - Bruno Vallim | ||
| - [Daniel Ribeiro](https://www.linkedin.com/in/daniel-ribeiro-59b739140/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "name": "epps-labenu-system8", | ||
| "version": "1.0.0", | ||
| "description": "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.", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "tables": "clear && tsc && node ./build/createTables/createTables.js", | ||
| "dev": "clear && ts-node-dev ./src/index.ts", | ||
| "start": "clear && tsc && node ./build/index.js" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/future4code/epps-labenu-system8.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/future4code/epps-labenu-system8/issues" | ||
| }, | ||
| "homepage": "https://github.com/future4code/epps-labenu-system8#readme", | ||
| "devDependencies": { | ||
| "@types/cors": "^2.8.10", | ||
| "@types/express": "^4.17.11", | ||
| "cors": "^2.8.5", | ||
| "express": "^4.17.1", | ||
| "ts-node-dev": "^1.1.6", | ||
| "typescript": "^4.2.3" | ||
| }, | ||
| "dependencies": { | ||
| "@types/knex": "^0.16.1", | ||
| "dotenv": "^8.2.0", | ||
| "knex": "^0.95.4", | ||
| "mysql": "^2.18.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| ### | ||
| POST http://localhost:3003/student/create | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name":"Daniel", | ||
| "email":"daniel@gmail.com", | ||
| "birthdate":"1993-05-19", | ||
| "hobbies": "Patinar." | ||
| } | ||
|
|
||
| #### | ||
| POST http://localhost:3003/class/create | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name":"Turma Neil-na-night.", | ||
| "start_date":"2022-03-01", | ||
| "end_date":"2022-09-01", | ||
| "type_class": "Noturna" | ||
| } | ||
|
|
||
| ### | ||
| POST http://localhost:3003/teacher/create | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "name":"Neil", | ||
| "email":"Neil@gmail.com", | ||
| "birthdate":"1970-04-15", | ||
| "speciality": "Redux" | ||
| } | ||
|
|
||
| ### | ||
| PUT http://localhost:3003/update/class | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "tableName": "Students", | ||
| "peapleClassId": "1617566013084", | ||
| "peapleNewClassId": "1617619560126" | ||
| } | ||
|
|
||
| ### | ||
| GET http://localhost:3003/students/1617547014022 | ||
|
|
||
| ### | ||
| GET http://localhost:3003/teachers/1617547014022 | ||
|
|
||
| ### | ||
| GET http://localhost:3003/search/age?id=1617546212494&&tableName=teachers | ||
|
|
||
| ### | ||
| GET http://localhost:3003/students/hobbies | ||
|
|
||
| ### | ||
| PUT http://localhost:3003/class/change-module?id=1617547014022&&module=1 | ||
|
|
||
| ### | ||
| DELETE http://localhost:3003/student/remove-class/1617566013084 | ||
|
|
||
| ### | ||
| DELETE http://localhost:3003/teacher/remove-class/:id | ||
|
|
||
| ### | ||
| DELETE http://localhost:3003/student/remove/1617312546437 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // adiciona 0 nos dates e nos months quando eles estão na casa de unidade. | ||
|
|
||
| export const addZero = (numero: number) => { | ||
| if (numero <= 9) | ||
| return "0" + numero; | ||
| else | ||
| return numero; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { addZero } from './addZero' | ||
|
|
||
| // formata data para dd/mm/yyyy | ||
|
|
||
| export const convertDate = (valueDate: string) => { | ||
| let data = new Date(valueDate.toString()); | ||
| let dataFormatada = (addZero((data.getDate()))) + "/" + | ||
| (addZero((data.getMonth() + 1))) + "/" + | ||
| data.getFullYear(); | ||
| return dataFormatada | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // converte datas para timestamp | ||
|
|
||
| export const convertDateToTimestamp = (date: string) => { | ||
| const myDate = date | ||
| const newMyDate = myDate.split("/") | ||
| const newDate = new Date(Number(newMyDate[2]), (Number(newMyDate[1]) -1), Number(newMyDate[0])) | ||
|
|
||
| return newDate.getTime() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import {convertDate} from './convertDate' | ||
|
|
||
| // pegando a data atual | ||
|
|
||
| export const currentDate = () =>{ | ||
| const date = new Date | ||
| const newDate = convertDate(String(date)) | ||
| return newDate | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { connection } from '../../connection' | ||
| import { convertDate } from './convertDate' | ||
| import { convertDateToTimestamp } from './convertDateToTimestamp' | ||
| import { currentDate } from './currentDate' | ||
| import { timestampToYear } from './timestampToYear' | ||
|
|
||
| // pegando idade da pessoa | ||
|
|
||
| export const getAge = async (idUser: string, tableName: string) => { | ||
| const birthdate = await connection.raw(` | ||
| SELECT birthdate | ||
| FROM ${tableName} | ||
| WHERE id = "${idUser}" | ||
| `) | ||
|
|
||
| const dateNow = currentDate() | ||
| const dataFormatada = convertDate(birthdate[0][0].birthdate) | ||
|
|
||
| const timestampNow = convertDateToTimestamp(dateNow) | ||
| const timestampAgePeople = convertDateToTimestamp(dataFormatada) | ||
|
|
||
| const dateMilisecunds = timestampNow - timestampAgePeople | ||
| const ageInYears = timestampToYear(dateMilisecunds) | ||
|
|
||
|
|
||
| return Math.floor(ageInYears) | ||
| } | ||
| export default getAge; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // convertendo timestamp para ano | ||
|
|
||
| export const timestampToYear = (timestamp: number) =>{ | ||
| const ageinYears = timestamp / 1000 / 60 / 60 / 24 / 365 | ||
|
|
||
| return ageinYears | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const capitalize = (string: string) => { | ||
| if (typeof string !== 'string') return '' | ||
| return string.charAt(0).toUpperCase() + string.slice(1) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const notFound = (value: string[]) =>{ | ||
| if(value.length === 0) throw new Error('No teacher found') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import {connection} from '../connection' | ||
|
|
||
| const updateClassStudant = async (classId: string, newClassId: string, tableName: string) =>{ | ||
| await connection.raw(` | ||
| UPDATE ${tableName} | ||
| SET class_id = "${newClassId}" | ||
| WHERE id = "${classId}"; | ||
| `) | ||
| } | ||
| export default updateClassStudant; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export enum Especialidades{ | ||
|
|
||
| REACT="react", | ||
| REDUX="redux", | ||
| CSS="css", | ||
| TESTES="testes", | ||
| TYPESCRIPT="typescript", | ||
| PROGRAMACAO_ORIENTADA_OBJETOS="programacao orientada objetos", | ||
| BACKEND="backend" | ||
|
|
||
| } | ||
|
|
||
| export enum Type{ | ||
| TEACHER = "Teachers", | ||
| STUDENT = "Students" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Especialidades, Type } from './Enums' | ||
|
|
||
| export type Docentes = { | ||
| nome:string, | ||
| email:string, | ||
| data_nasc:string, | ||
| turma_id:number, | ||
| especialidade:Especialidades | ||
| } | ||
|
|
||
| export type updateClass = { | ||
| tableName: Type, | ||
| peapleClassId: string, | ||
| peapleNewClassId: string | ||
| } | ||
|
|
||
| export type data = { | ||
| id: string, | ||
| tableName: string | ||
| } | ||
|
|
||
| export type student = { | ||
| id: string, | ||
| student_name: string, | ||
| email: string, | ||
| hobbies: string, | ||
| birthdate: string | ||
| } | ||
|
|
||
| export type teacher = { | ||
| id: string, | ||
| teachers_name: string, | ||
| email: string, | ||
| speciality: string, | ||
| birthdate: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import express, {Express} from 'express' | ||
| import cors from 'cors' | ||
| import { AddressInfo } from "net"; | ||
|
|
||
| const app: Express = 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O cálculo da idade podia ser feito direto no banco, sem problemas