Skip to content

Commit

Permalink
Ajustes de endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovannaNaves committed Jul 1, 2024
1 parent 861a737 commit fb09a37
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/pages/app_createtopic.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h1>Criar Tópico</h1>
const formObject = Object.fromEntries(formData.entries());
formObject.categorias = categorias;

fetch('http://localhost:3000/topicos', {
fetch('http://localhost:3001/topicos', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
36 changes: 17 additions & 19 deletions docs/pages/app_edittopic.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@
}

form button {
background-color: blue; /* Mesma cor da navbar */
background-color: blue;
color: white;
border: none;
padding: 10px;
cursor: pointer;
}

#backToForum {
background-color: blue; /* Mesma cor da navbar */
background-color: blue;
color: white;
border: none;
padding: 10px;
cursor: pointer;
width: 100%; /* Largura total do formulário */
margin-top: 20px; /* Espaço extra acima do botão */
text-align: center; /* Centralizar texto */
width: 100%;
margin-top: 20px;
text-align: center;
}
</style>
</head>
Expand All @@ -123,13 +123,13 @@
<div class="logo">
<img src="img/logo_redonda.png" alt="Logo do Site">
</div>
<ul id="lista-menu">
<li><a href="conteudo.html">Menu Principal</a></li>
<li><a href="app_createtopic.html">Adicionar conteúdo</a></li>
<li><a href="app_edittopic.html">Editar tópico</a></li>
<li><a href="sendmessage_staff.html">Criar Mensagem</a></li>
<li><a href="index.html">Sair</a></li>
</ul>
<ul id="lista-menu">
<li><a href="conteudo_staff.html">Meu Conteúdo</a></li>
<li><a href="app_createtopic.html">Adicionar Conteúdo</a></li>
<li><a href="forum_staff.html">Fórum</a></li>
<li><a href="perfil_staff.html">Meu Perfil</a></li>
<li><a href="index.html">Sair</a></li>
</ul>
</div>

<div class="content">
Expand Down Expand Up @@ -160,17 +160,16 @@ <h1>Editar Tópico</h1>
<script>
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
//const topicId = urlParams.get('id');
const topicId = 3;
// Buscar os dados do tópico existente
fetch(`http://localhost:3000/topicos/${topicId}`)
const topicId = urlParams.get('id');
console.log(topicId);

fetch(`http://localhost:3001/topicos/${topicId}`)
.then(response => response.json())
.then(data => {
document.getElementById('titulo').value = data.titulo;
document.getElementById('conteudo').value = data.conteudo;
document.getElementById('imagem').value = data.imagem;

// Selecionar as categorias atuais
const categoriasElement = document.getElementById('categorias');
data.categorias.forEach(categoria => {
for (const option of categoriasElement.options) {
Expand All @@ -184,15 +183,14 @@ <h1>Editar Tópico</h1>
console.error('Erro ao carregar o tópico:', error);
});

// Enviar os dados atualizados do formulário

document.getElementById('topicForm').addEventListener('submit', function(event) {
event.preventDefault();

const form = event.target;
const formData = new FormData(form);
const categorias = Array.from(formData.getAll('categorias'));

// Criar um objeto a partir dos dados do formulário
const formObject = Object.fromEntries(formData.entries());
formObject.categorias = categorias;

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/app_sendmessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h1>Digite aqui sua dúvida</h1>
const messageObject = Object.fromEntries(formData.entries());
messageObject.autor = userName;

fetch('http://localhost:3000/mensagens', {
fetch('http://localhost:3001/mensagens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/conteudo_staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h5 class="card-title">${item.titulo}</h5>
}

function redirectToRepo(id) {
window.location.href = `repo_staff.html?id=${id}`;
window.location.href = `app_edittopic.html?id=${id}`;
}
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ async function handleLogin(event) {
var usuario = data.find(usuario => usuario.nome_usuario === nome_usuario && usuario.senha === senha);

if (usuario) {
localStorage.setItem("UserId", usuario.UserId); // Armazenar o UserId no localStorage
localStorage.setItem("UserId", usuario.UserId);
if (usuario.tipo_usuario == 'cliente') {
localStorage.setItem("tipoUsuario", "cliente");
window.location.href = './conteudo.html';
} else if (usuario.tipo_usuario == 'admin') {
localStorage.setItem("tipoUsuario", "admin");
window.location.href = './conteudo.html';
window.location.href = './conteudo_staff.html';
} else {
alert('Tipo de usuário desconhecido');
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/sendmessage_staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h1>Digite aqui sua dúvida</h1>
const messageObject = Object.fromEntries(formData.entries());
messageObject.autor = userName;

fetch('http://localhost:3000/mensagens', {
fetch('http://localhost:3001/mensagens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit fb09a37

Please sign in to comment.