Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0596c93
Configurado projeto.
Shidoshi93 Mar 30, 2021
782badd
Merge pull request #4 from future4code/daniel-versao-3
Shidoshi93 Mar 30, 2021
a9b4e12
parte de criar estudante, professor e turma criada, junto com seus re…
Bruno-Vallim Mar 31, 2021
65f7f93
Merge pull request #5 from future4code/bruno2
Shidoshi93 Mar 31, 2021
82662a7
Implementado funcionalidade de troca de turma.
Shidoshi93 Mar 31, 2021
8385720
Merge pull request #6 from future4code/updateClass-vesao-1
Bruno-Vallim Apr 1, 2021
de37a0d
Feito refatoramento nos códigos das funcionalidades existentes até ag…
Shidoshi93 Apr 1, 2021
ae2a469
Merge pull request #7 from future4code/refator-funcionalidades
Bruno-Vallim Apr 1, 2021
e5912d1
feito o primeiro desafio, pegar nome dos estudantes por turma
Bruno-Vallim Apr 1, 2021
2fb9a18
Resolvido bug no script de criar tabelas.
Shidoshi93 Apr 1, 2021
7deae1b
Merge pull request #8 from future4code/bruno4
Shidoshi93 Apr 1, 2021
deab8cd
Merge branch 'master' into create-table
Shidoshi93 Apr 1, 2021
a4cdd98
Merge pull request #9 from future4code/create-table
Bruno-Vallim Apr 1, 2021
0560940
Implementado funcionalidade de pegar idade.
Shidoshi93 Apr 1, 2021
21daaa3
Refatorado funcionalidade de pegar idade, para funcionar tanto para a…
Shidoshi93 Apr 4, 2021
72abadf
Merge pull request #10 from future4code/get-age
Shidoshi93 Apr 4, 2021
95c4295
Refatorado funcionalidade de pegar estudantes por turma.
Shidoshi93 Apr 4, 2021
d8fc20b
Merge pull request #13 from future4code/get-class-student-refatorado
Shidoshi93 Apr 4, 2021
ff0a679
Implementado funcionalidade de pegar professor pela classe.
Shidoshi93 Apr 4, 2021
2f4d459
Merge pull request #14 from future4code/get-teacher-by-class
Shidoshi93 Apr 4, 2021
031a85e
Implementado funcionalidade de pegar alunos por hobby.
Shidoshi93 Apr 4, 2021
3894731
Merge pull request #15 from future4code/get-students-by-hobby
Shidoshi93 Apr 4, 2021
cf7357c
Implementado funcionalidade de remover aluno de turma.
Shidoshi93 Apr 4, 2021
ef41f7f
Merge pull request #16 from future4code/remove-student-from-class
Shidoshi93 Apr 4, 2021
6b163f6
Implementado funcinalidade de remover estudante do curso.
Shidoshi93 Apr 4, 2021
01e73a8
Merge pull request #17 from future4code/remove-student
Shidoshi93 Apr 4, 2021
21e72fc
IMplementado funcionalidade de remover professor da turma.
Shidoshi93 Apr 4, 2021
53ecc86
Merge pull request #18 from future4code/remove-teacher-from-classs
Shidoshi93 Apr 4, 2021
4720896
Implementado funcionalidade de alterar módulo da turma.
Shidoshi93 Apr 4, 2021
8e7e26e
Merge pull request #19 from future4code/change-module
Shidoshi93 Apr 4, 2021
e53236d
Refatoração final. Projeto concluído.
Shidoshi93 Apr 5, 2021
4a99de1
Merge pull request #20 from future4code/refatoracao-final
Shidoshi93 Apr 5, 2021
d3cc9f3
Update README.md
Shidoshi93 Apr 5, 2021
0a57f60
Update README.md
Shidoshi93 Apr 5, 2021
712c529
Update README.md
Shidoshi93 Apr 5, 2021
4b76078
Update README.md
Shidoshi93 Apr 5, 2021
10251d0
Update README.md
Shidoshi93 Apr 5, 2021
fa3a2f3
Update README.md
Shidoshi93 Apr 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.env
package-lock.json
build
98 changes: 65 additions & 33 deletions README.md
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/)
36 changes: 36 additions & 0 deletions package.json
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"
}
}
66 changes: 66 additions & 0 deletions request.rest
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
8 changes: 8 additions & 0 deletions src/GlobalFunctions/aboutDate/addZero.ts
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;
}
11 changes: 11 additions & 0 deletions src/GlobalFunctions/aboutDate/convertDate.ts
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
}
9 changes: 9 additions & 0 deletions src/GlobalFunctions/aboutDate/convertDateToTimestamp.ts
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()
}
9 changes: 9 additions & 0 deletions src/GlobalFunctions/aboutDate/currentDate.ts
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
}
28 changes: 28 additions & 0 deletions src/GlobalFunctions/aboutDate/getAge.ts
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}"
`)
Comment on lines +9 to +14
Copy link
Author

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


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;
7 changes: 7 additions & 0 deletions src/GlobalFunctions/aboutDate/timestampToYear.ts
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
}
4 changes: 4 additions & 0 deletions src/GlobalFunctions/capitalize/capitalize.ts
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)
}
3 changes: 3 additions & 0 deletions src/GlobalFunctions/error/notFound.ts
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')
}
10 changes: 10 additions & 0 deletions src/GlobalFunctions/updateClass.ts
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;
16 changes: 16 additions & 0 deletions src/TypesAndEnums/Enums.ts
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"
}
36 changes: 36 additions & 0 deletions src/TypesAndEnums/Types.ts
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
}
18 changes: 18 additions & 0 deletions src/app.ts
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;
Loading