Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: listar perguntas e correcoes #147

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 0 additions & 20 deletions api/src/Controllers/PerguntaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ private function processResourceRequest(string $method, string $id): void
return;
}

if ($usuarioLogado["cargo"] == CargoEnum::MODERADOR && $pergunta["criado_por"] != $usuarioLogado["id"]) {
http_response_code(403);
echo json_encode([
"status" => "error",
"errors" => ["Não permitido alterar pergunta de outro usuário"]
]);

return;
}

$data = (array) json_decode(file_get_contents("php://input"), true);
$data["usuarioId"] = $usuarioLogado["id"];

Expand Down Expand Up @@ -87,16 +77,6 @@ private function processResourceRequest(string $method, string $id): void
return;
}

if ($usuarioLogado["cargo"] == CargoEnum::MODERADOR && $pergunta["criado_por"] != $usuarioLogado["id"]) {
http_response_code(403);
echo json_encode([
"status" => "error",
"errors" => ["Não permitido deletar pergunta de outro usuário"]
]);

return;
}

$this->gateway->delete($id);

http_response_code(204);
Expand Down
6 changes: 3 additions & 3 deletions api/src/Gateways/PerguntaGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getAll(array $ordenacao): array
ue.foto_uri AS foto_usuario_editado
FROM pergunta p
LEFT JOIN usuario u ON p.criado_por = u.id
LEFT JOIN pergunta_editada_por pe ON u.id = pe.usuario_id
LEFT JOIN pergunta_editada_por pe ON p.id = pe.pergunta_id
LEFT JOIN usuario ue ON pe.usuario_id = ue.id";

if (isset($ordenacao["MaisAlta"]) && $ordenacao["MaisAlta"]) {
Expand All @@ -37,7 +37,7 @@ public function getAll(array $ordenacao): array
ue.foto_uri AS foto_usuario_editado
FROM pergunta p
LEFT JOIN usuario u ON p.criado_por = u.id
LEFT JOIN pergunta_editada_por pe ON u.id = pe.usuario_id
LEFT JOIN pergunta_editada_por pe ON p.id = pe.pergunta_id
LEFT JOIN usuario ue ON pe.usuario_id = ue.id
ORDER BY
CASE
Expand All @@ -59,7 +59,7 @@ public function getAll(array $ordenacao): array
ue.foto_uri AS foto_usuario_editado
FROM pergunta p
LEFT JOIN usuario u ON p.criado_por = u.id
LEFT JOIN pergunta_editada_por pe ON u.id = pe.usuario_id
LEFT JOIN pergunta_editada_por pe ON p.id = pe.pergunta_id
LEFT JOIN usuario ue ON pe.usuario_id = ue.id
ORDER BY curtidas DESC";
}
Expand Down
2 changes: 2 additions & 0 deletions sistema/colaboradores/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ const execute = async () => {
showCancelButton: true,
confirmButtonText: 'Sim, confirmar!',
cancelButtonText: 'Não',
allowEnterKey: false,
icon: 'question',
}).then(async (result) => {
if (result.isConfirmed) {
Expand All @@ -325,6 +326,7 @@ const execute = async () => {
showCancelButton: true,
confirmButtonText: 'Sim, irei anotar!',
cancelButtonText: 'Não',
allowEnterKey: false,
icon: 'info',
}).then(async (result) => {
if (result.isConfirmed) {
Expand Down
46 changes: 18 additions & 28 deletions sistema/curtidas/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ const execute = async () => {
<td>
<div id="colaborador">
<div class="avatar">
<img src="${pergunta.foto_usuario ?? '../../img/userFallback.jpg'}" />
<img title="${pergunta.nome_usuario ?? 'N/A'}" src="${
pergunta.foto_usuario ?? '../../img/userFallback.jpg'
}" />
</div>
<div class="nome">
<span>${pergunta.nome_usuario ?? 'Sem usuário'}</span>
<span>${pergunta.nome_usuario ?? 'N/A'}</span>
</div>
</div>
</td>
Expand All @@ -76,19 +78,12 @@ const execute = async () => {
<div id="curtidas"><span>${pergunta.curtidas}</span></div>
</td>
<td>
${
user.cargo === 'Administrador'
? `<div id="acao">
<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: pergunta.criado_por === user.id
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: ''
}
<button class='click' data-id=${
pergunta.id
} href="#"><i class="fas fa-trash-can"></i></button>
</div>
</td>
</tr>
`,
Expand Down Expand Up @@ -144,10 +139,12 @@ const execute = async () => {
<td>
<div id="colaborador">
<div class="avatar">
<img src="${pergunta.foto_usuario ?? '../../img/userFallback.jpg'}" />
<img title="${pergunta.nome_usuario ?? 'N/A'}" src="${
pergunta.foto_usuario ?? '../../img/userFallback.jpg'
}" />
</div>
<div class="nome">
<span>${pergunta.nome_usuario ?? 'Sem usuário'}</span>
<span>${pergunta.nome_usuario ?? 'N/A'}</span>
</div>
</div>
</td>
Expand All @@ -160,19 +157,12 @@ const execute = async () => {
<div id="curtidas"><span>${pergunta.curtidas}</span></div>
</td>
<td>
${
user.cargo === 'Administrador'
? `<div id="acao">
<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: pergunta.criado_por === user.id
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: ''
}
<button class='click' data-id=${
pergunta.id
} href="#"><i class="fas fa-trash-can"></i></button>
</div>
</td>
</tr>
`,
Expand Down
Loading