Skip to content

Commit

Permalink
Learning Path
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMEsteves committed Nov 22, 2023
1 parent c493f7c commit a118acb
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 8 deletions.
12 changes: 6 additions & 6 deletions backend/config/config.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 13 additions & 1 deletion backend/controllers/LearningPathsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ exports.deleteLearningPaths = async(req, res) => {
res.status(400).json({error: err});
};
});
};

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' });
}


}
};
12 changes: 12 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions backend/views/routes/LearningPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 16 additions & 0 deletions backend/views/routes/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 7 additions & 1 deletion frontend/src/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -71,7 +77,7 @@ const Header = () => {
</StyledMenuItem>
<StyledMenuItem>
<StyledImage src={logoutIcon} alt='Logout Icon' />
Sair
<button>Sair</button>
</StyledMenuItem>
</StyledMenuList>
</Menu>
Expand Down
99 changes: 99 additions & 0 deletions frontend/src/pages/PathExclusion/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Header />
<h1 style={{ textAlign: 'center' }}>Lista de Trilhas</h1>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
{trilhas.map((trilha) => (
<div
key={trilha.id}
style={{
display: 'flex',
alignItems: 'center',
border: '1px solid #ccc',
borderRadius: '5px',
padding: '10px',
marginBottom: '10px',
width: '300px', // largura do quadrado
}}
>
<div style={{ marginRight: '10px' }}>
<input
type="checkbox"
onChange={() => toggleSelecionada(trilha.id)}
checked={trilhasSelecionadas.includes(trilha.id)}
/>
</div>
<div>
<p>Trilha: {trilha.numero}</p>
<p>Título: {trilha.titulo}</p>
{/* Adicione mais informações da trilha conforme necessário */}
</div>
<div
style={{
marginLeft: 'auto',
width: '20px', // largura do círculo de seleção
height: '20px', // altura do círculo de seleção
borderRadius: '50%',
border: '1px solid #000',
background: trilhasSelecionadas.includes(trilha.id) ? '#000' : 'transparent',
}}
></div>
</div>
))}
<button onClick={handleExcluirTrilhas} style={{ marginTop: '20px' }}>
Excluir Trilhas Selecionadas
</button>
</div>
</div>
);
};

export default TrilhasList;
12 changes: 12 additions & 0 deletions frontend/src/pages/PathExclusion/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const styles = {
ul: {
listStyle: 'none',
padding: 0,
},
li: {
marginBottom: '100px',
},
};

export default styles;

2 changes: 2 additions & 0 deletions frontend/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -20,6 +21,7 @@ const RoutesApp = () => {
<Route path="/" element={<Signin />} />
<Route exact path="/signup" element={<Signup />} />
<Route path="*" element={<Signin />} />
<Route path="/trilhas" element={<TrilhasList />} />
</Routes>
</Fragment>
</BrowserRouter>
Expand Down

0 comments on commit a118acb

Please sign in to comment.