Skip to content

Commit

Permalink
Adicionar rota de exclusão de categoria e corrigir estilos da tabela …
Browse files Browse the repository at this point in the history
…de categorias
  • Loading branch information
BDBento committed Apr 27, 2024
1 parent 56b7194 commit 4ae1068
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
25 changes: 25 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ app.post('/nova-categoria', async (req, res) => {
}
});

app.post('/deletarCategoria', async (req, res) => {
const { id } = req.body;

try {
// Busca a categoria no banco de dados pelo ID
const categoria = await Categoria.findByPk(id);

if (!categoria) {
return res.status(404).send('Categoria não encontrada');
}

// Atualiza o campo 'excluido' para true
categoria.excluido = true;

// Salva a categoria atualizada no banco de dados
await categoria.save();

// Redireciona para a página de categorias após a exclusão da categoria
res.redirect('/categoria');
} catch (error) {
console.error('Erro ao excluir categoria:', error);
res.status(500).send('Erro ao excluir categoria');
}
});


app.listen(8081, function () {
console.log("https://localhost:8081/")
Expand Down
3 changes: 2 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
/*-------------------------listar categorias-----------------------------------------*/
/*-----------------------------------------------------------------------------------*/

.titulo-categoria {
.titulo-categoria,
.titulo-filme {
color: white;
text-align: center;
margin: 30px auto;
Expand Down
8 changes: 6 additions & 2 deletions views/listaCategorias.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
<td>{{id}}</td>
<td>{{genero}}</td>
<td>
<a href="/editaCategoria/{{id}}">Editar</a>
<a href="/deletaCategoria/{{id}}">Deletar</a>
<a href="/editaCategoria/{{id}}">Editar</a>
<form action="/deletarCategoria" method="POST" style="display: inline;">
<input type="hidden" name="id" value="{{id}}">
<button type="submit" class="btn btn-danger">Deletar</button>
</form>

</td>
</tr>
{{/each}}
Expand Down

0 comments on commit 4ae1068

Please sign in to comment.