From a118acb22612b48128fecfba65e2c80e6b4b252d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Nov 2023 18:11:00 -0300 Subject: [PATCH] Learning Path --- backend/config/config.json | 12 +-- .../controllers/LearningPathsController.js | 14 ++- backend/index.js | 12 +++ backend/views/routes/LearningPaths.js | 1 + backend/views/routes/Users.js | 16 +++ frontend/src/pages/Home/index.js | 8 +- frontend/src/pages/PathExclusion/index.js | 99 +++++++++++++++++++ frontend/src/pages/PathExclusion/style.js | 12 +++ frontend/src/routes/index.js | 2 + 9 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 frontend/src/pages/PathExclusion/index.js create mode 100644 frontend/src/pages/PathExclusion/style.js diff --git a/backend/config/config.json b/backend/config/config.json index 00939f6b..18aacce8 100644 --- a/backend/config/config.json +++ b/backend/config/config.json @@ -1,11 +1,11 @@ { "development": { - "username": "root", - "password": "julia12345", - "database": "matriculai", - "host": "localhost", - "dialect": "mysql" - }, + "username": "root", + "password": "123456", + "database": "banch", + "host": "localhost", + "dialect": "mysql" +}, "test": { "username": "root", "password": null, diff --git a/backend/controllers/LearningPathsController.js b/backend/controllers/LearningPathsController.js index 277bb464..faff76ae 100644 --- a/backend/controllers/LearningPathsController.js +++ b/backend/controllers/LearningPathsController.js @@ -27,4 +27,16 @@ exports.deleteLearningPaths = async(req, res) => { res.status(400).json({error: err}); }; }); -}; \ No newline at end of file + + exports.LearningPath = async (req, res) => { + try { + const trilhas = await LearningPath.findAll(); + res.json(trilhas); + } catch (error) { + console.error('Erro ao buscar trilhas:', error); + res.status(500).json({ message: 'Erro ao buscar trilhas' }); + } + + + } +}; diff --git a/backend/index.js b/backend/index.js index 67afc75f..ada751a2 100644 --- a/backend/index.js +++ b/backend/index.js @@ -4,6 +4,8 @@ const database = require('./models/schemas'); const userRoute = require('./views/routes/Users'); const electiveRoute = require('./views/routes/Electives') const learningPathRoute = require('./views/routes/LearningPaths') +const logoutRoutes = require('./views/routes/Users'); +const sequelize = require('sequelize'); require("dotenv").config(); const app = express(); @@ -14,6 +16,16 @@ app.use(cors()); app.use('/auth', userRoute); app.use('/elective', electiveRoute); app.use('/learning_paths', learningPathRoute); +app.use('/api', logoutRoutes); + +sequelize + .sync() + .then(() => { + console.log('Conexão bem-sucedida com o banco de dados'); + }) + .catch((error) => { + console.error('Erro ao conectar-se ao banco de dados:', error); + }); database.sequelize.sync().then(() => { diff --git a/backend/views/routes/LearningPaths.js b/backend/views/routes/LearningPaths.js index 51588998..8dbcd871 100644 --- a/backend/views/routes/LearningPaths.js +++ b/backend/views/routes/LearningPaths.js @@ -4,5 +4,6 @@ const learningPathsController = require('../../controllers/LearningPathsControl router.post("/createLearningPaths", learningPathsController.createLearningPaths); router.delete("/deleteLearningPaths", learningPathsController.deleteLearningPaths) +router.get('/trilhas', learningPathsController.LearningPath); module.exports = router; diff --git a/backend/views/routes/Users.js b/backend/views/routes/Users.js index ccbe2d81..9369e4d0 100644 --- a/backend/views/routes/Users.js +++ b/backend/views/routes/Users.js @@ -13,4 +13,20 @@ router.get('/profile', validateToken, (req, res) => { router.post('/register', userController.userRegister); router.post('/login', userController.userLogin); +// Rota para logout +router.post('/logout', (req, res) => { + // Lógica para fazer logout do usuário + req.session.destroy((err) => { + if (err) { + return res.status(500).json({ message: 'Erro ao fazer logout' }); + } + res.clearCookie('cookieName'); // Limpeza de cookies, se necessário + return res.status(200).json({ message: 'Logout realizado com sucesso' }); + }); + }); + +router.get('/profile', validateToken, (req, res) => { + res.json('profile'); +}); + module.exports = router; diff --git a/frontend/src/pages/Home/index.js b/frontend/src/pages/Home/index.js index 92dfa9c4..932862c0 100644 --- a/frontend/src/pages/Home/index.js +++ b/frontend/src/pages/Home/index.js @@ -1,4 +1,5 @@ import React from "react"; +import axios from "axios" import styled from "styled-components"; import { Link } from "react-router-dom"; import { Flex, Box, Heading, Spacer, Menu, MenuButton, MenuList, MenuItem } from "@chakra-ui/react"; @@ -10,7 +11,12 @@ import settingsIcon from '../../icon/definicoes 1.png'; import helpIcon from '../../icon/interrogatorio 1.png'; import logoutIcon from '../../icon/sair-alt 1.png'; + + const Header = () => { + + + const StyledMenuList = styled(MenuList)` list-style: 'circle'; padding: 0; @@ -71,7 +77,7 @@ const Header = () => { - Sair + diff --git a/frontend/src/pages/PathExclusion/index.js b/frontend/src/pages/PathExclusion/index.js new file mode 100644 index 00000000..73f8226c --- /dev/null +++ b/frontend/src/pages/PathExclusion/index.js @@ -0,0 +1,99 @@ +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import Header from '../Home/index'; + +const TrilhasList = () => { + const [trilhas, setTrilhas] = useState([]); + const [trilhasSelecionadas, setTrilhasSelecionadas] = useState([]); + + // Carregar trilhas do backend ao carregar o componente + useEffect(() => { + async function fetchTrilhas() { + try { + const response = await axios.get('http://localhost:3000/api/trilhas'); // Endpoint para buscar trilhas + setTrilhas(response.data); // Define as trilhas na state 'trilhas' + } catch (error) { + console.error('Erro ao buscar trilhas:', error); + } + } + fetchTrilhas(); + }, []); + + // Função para marcar/desmarcar trilha selecionada + const toggleSelecionada = (id) => { + const isSelected = trilhasSelecionadas.includes(id); + if (isSelected) { + const updatedSelection = trilhasSelecionadas.filter((trilhaId) => trilhaId !== id); + setTrilhasSelecionadas(updatedSelection); + } else { + setTrilhasSelecionadas([...trilhasSelecionadas, id]); + } + }; + + // Função para excluir trilhas selecionadas + const handleExcluirTrilhas = async () => { + try { + await axios.delete('http://localhost:3000/api/deleteLearningPaths', { + data: { id: trilhasSelecionadas }, // Envia os IDs das trilhas selecionadas para exclusão + }); + // Atualiza a lista de trilhas após a exclusão + const updatedTrilhas = trilhas.filter((trilha) => !trilhasSelecionadas.includes(trilha.id)); + setTrilhas(updatedTrilhas); + setTrilhasSelecionadas([]); // Limpa as trilhas selecionadas após a exclusão + alert('Trilhas excluídas com sucesso!'); + } catch (error) { + console.error('Erro ao excluir trilhas:', error); + } + }; + + return ( +
+
+

Lista de Trilhas

+
+ {trilhas.map((trilha) => ( +
+
+ toggleSelecionada(trilha.id)} + checked={trilhasSelecionadas.includes(trilha.id)} + /> +
+
+

Trilha: {trilha.numero}

+

Título: {trilha.titulo}

+ {/* Adicione mais informações da trilha conforme necessário */} +
+
+
+ ))} + +
+
+ ); +}; + +export default TrilhasList; diff --git a/frontend/src/pages/PathExclusion/style.js b/frontend/src/pages/PathExclusion/style.js new file mode 100644 index 00000000..78dd698f --- /dev/null +++ b/frontend/src/pages/PathExclusion/style.js @@ -0,0 +1,12 @@ +const styles = { + ul: { + listStyle: 'none', + padding: 0, + }, + li: { + marginBottom: '100px', + }, + }; + + export default styles; + \ No newline at end of file diff --git a/frontend/src/routes/index.js b/frontend/src/routes/index.js index 7a4b9d77..3b5d3020 100644 --- a/frontend/src/routes/index.js +++ b/frontend/src/routes/index.js @@ -4,6 +4,7 @@ import useAuth from "../hooks/useAuth"; import Home from "../pages/Home"; import Signin from "../pages/Signin"; import Signup from "../pages/Signup"; +import TrilhasList from "../pages/PathExclusion"; const Private = ({ Item }) => { const { signed } = useAuth(); @@ -20,6 +21,7 @@ const RoutesApp = () => { } /> } /> } /> + } />