From 529dd6b3a8e01e7b5399992b50a818864739327e Mon Sep 17 00:00:00 2001 From: Daniel-Alvarenga Date: Sat, 23 Nov 2024 09:22:13 -0300 Subject: [PATCH] Load ranking from server on public pages --- client/src/router/routes/shared.js | 9 ++ client/src/services/api/shared.js | 11 ++ client/src/views/aluno/Ranking.vue | 81 ++++++-------- client/src/views/shared/Ranking.vue | 105 ++++++++++++++++++ .../src/modules/services/shared/GetRanking.ts | 39 +++++-- 5 files changed, 194 insertions(+), 51 deletions(-) create mode 100644 client/src/views/shared/Ranking.vue diff --git a/client/src/router/routes/shared.js b/client/src/router/routes/shared.js index 65bdc90..4876efe 100644 --- a/client/src/router/routes/shared.js +++ b/client/src/router/routes/shared.js @@ -5,6 +5,7 @@ import PublicPerfilProfessor from '../../views/shared/PerfilProfessor.vue'; import Pesquisa from '../../views/shared/Pesquisa.vue'; import Vagas from '../../views/shared/Vagas.vue'; import Vaga from '../../views/shared/Vaga.vue'; +import Ranking from '../../views/shared/Ranking.vue'; import { isAuthAluno, isAuthSomebody } from '../guards/guards'; export const sharedRoutes = [ @@ -58,6 +59,14 @@ export const sharedRoutes = [ (await isAuthAluno()) ? next(`/aluno/vaga/${to.params.id}`) : next(); } }, + { + path: '/ranking', + name: 'RankingPublico', + component: Ranking, + beforeEnter: async (to, from, next) => { + (await isAuthAluno()) ? next(`/aluno/ranking}`) : next(); + } + }, { path: '/:pathMatch(.*)*', name: 'NotFound', diff --git a/client/src/services/api/shared.js b/client/src/services/api/shared.js index d13641e..a8d4418 100644 --- a/client/src/services/api/shared.js +++ b/client/src/services/api/shared.js @@ -75,4 +75,15 @@ export const getExtracurriculares = async (rm) => { console.log('Erro: ' + error); return error.response.data; } +} + +export const getNotaRanking = async (rm) => { + try { + const response = await api.get('/shared/ranking/boletim', { + }); + return response; + } catch (error) { + console.log('Erro: ' + error); + return error.response.data; + } } \ No newline at end of file diff --git a/client/src/views/aluno/Ranking.vue b/client/src/views/aluno/Ranking.vue index 9ccb368..199393f 100644 --- a/client/src/views/aluno/Ranking.vue +++ b/client/src/views/aluno/Ranking.vue @@ -6,51 +6,18 @@

Rankings

-

Rankings gerados a partir das atividades dos alunos. O objetivo desses rankings é proporcionar competitividade e destacar os alunos para as empresas.

+

Ranking gerados a partir das notas dos alunos. O objetivo desse ranking é proporcionar competitividade e destacar os alunos para as empresas.

Ranking geral:

- - #1 - - -

Beatriz Rodriges de Oliveira - 3º DS

-

XXXX pontos

-
- - #2 - - -

Maria Clara Dias Soares De Souza - 3º DS

-

XXXX pontos

-
- - #3 - - -

Daniel Rocha Alvarenga - 3º DS

-

XXXX pontos

-
- - #4 - - -

Amanda Barbosa Godinho - 3º DS

-

XXXX pontos

-
- - #5 - - -

Gustavo do Nascimento Paulo - 3º DS

-

XXXX pontos

-
- - #6 - - -

Guilherme de Almeida Rodrigues - 3º DS

-

XXXX pontos

+ + + #{{ index + 1 }} + + Foto do aluno + Foto padrão +

{{ item.aluno.nome }} - 3º DS

+

{{ (item.rankingNota * 1000).toFixed(2) }} pontos

@@ -66,6 +33,8 @@ import searchIcon from '../../assets/icons/procurar.png'; import Cookies from 'js-cookie'; +import { getNotaRanking } from '../../services/api/shared'; + export default { name: 'Ranking', components: { @@ -76,12 +45,36 @@ export default { return { aluno: { token: '' + }, + ranking: { + } }; }, methods: { - - } + async getRanking() { + try { + const response = await getNotaRanking(); + if (response.status >= 200 && response.status < 300) { + this.ranking = response.data; + console.log(this.ranking) + } else { + console.error( + "Erro ao carregar ranking", + response.message, + ); + } + } catch (error) { + console.error( + "Erro ao carregar ranking", + error.message, + ); + } + }, + }, + async created() { + await this.getRanking(); + }, }; diff --git a/client/src/views/shared/Ranking.vue b/client/src/views/shared/Ranking.vue new file mode 100644 index 0000000..ccc0654 --- /dev/null +++ b/client/src/views/shared/Ranking.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/server/src/modules/services/shared/GetRanking.ts b/server/src/modules/services/shared/GetRanking.ts index 325bd08..49adac3 100644 --- a/server/src/modules/services/shared/GetRanking.ts +++ b/server/src/modules/services/shared/GetRanking.ts @@ -1,5 +1,6 @@ import { prisma } from "../../../prisma/client"; import { AppError } from "../../../errors/error"; +import { minioClient } from "../../../minioService"; const notaValores: { [key: string]: number } = { MB: 10, @@ -58,13 +59,37 @@ export class GetRankingUseCase { } }); - const rankingDetalhado = ranking.map(rank => { - const aluno = alunos.find(a => a.id === rank.alunoId); - return { - aluno, - rankingNota: rank.rankingNota - }; - }); + const rankingDetalhado = await Promise.all( + ranking.map(async rank => { + const aluno = alunos.find(a => a.id === rank.alunoId); + if (aluno) { + const bucketName = 'boot'; + const imageName = aluno.imagem as string; + + let entityUrl = "default"; + + if (imageName) { + try { + await minioClient.statObject(bucketName, imageName); + entityUrl = await minioClient.presignedUrl('GET', bucketName, imageName, 24 * 60 * 60); + } catch (error) { + console.error(`Erro ao verificar objeto ${imageName}:`, error); + } + } + + return { + aluno: { + nome: aluno.name, + rm: aluno.rm, + imagem: entityUrl, + }, + rankingNota: rank.rankingNota, + }; + } + + return null; // Retorna null caso não encontre o aluno + }) + ); return rankingDetalhado; }