Skip to content

Commit

Permalink
Load ranking from server on public pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Alvarenga committed Nov 23, 2024
1 parent e5ddfd1 commit 529dd6b
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 51 deletions.
9 changes: 9 additions & 0 deletions client/src/router/routes/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions client/src/services/api/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
81 changes: 37 additions & 44 deletions client/src/views/aluno/Ranking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,18 @@
<section class="content">
<div class="box" id="box1">
<H1>Rankings</H1>
<h2>Rankings gerados a partir das atividades dos alunos. O objetivo desses rankings é proporcionar competitividade e destacar os alunos para as empresas.</h2>
<h2>Ranking gerados a partir das notas dos alunos. O objetivo desse ranking é proporcionar competitividade e destacar os alunos para as empresas.</h2>

<div class="alunos">
<p class="info">Ranking geral:</p>
<router-link to="" class="aluno">
<b>#1</b>
<img src="../../assets/icons/m1.png" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Beatriz Rodriges de Oliveira - 3º DS</p>
<p class="pontos">XXXX pontos</p>
</router-link>
<router-link to="" class="aluno">
<b>#2</b>
<img src="../../assets/icons/m2.png" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Maria Clara Dias Soares De Souza - 3º DS</p>
<p class="pontos">XXXX pontos</p>
</router-link>
<router-link to="" class="aluno">
<b>#3</b>
<img src="../../assets/icons/m3.png" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Daniel Rocha Alvarenga - 3º DS</p>
<p class="pontos">XXXX pontos</p>
</router-link>
<router-link to="" class="aluno">
<b>#4</b>
<img src="../../assets/icons/m3.png" class="normal" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Amanda Barbosa Godinho - 3º DS</p>
<p class="pontos">XXXX pontos</p>
</router-link>
<router-link to="" class="aluno">
<b>#5</b>
<img src="../../assets/icons/m3.png" class="normal" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Gustavo do Nascimento Paulo - 3º DS</p>
<p class="pontos">XXXX pontos</p>
</router-link>
<router-link to="" class="aluno">
<b>#6</b>
<img src="../../assets/icons/m3.png" class="normal" alt="">
<img src="../../assets/icons/artwork.png" alt="">
<p class="name">Guilherme de Almeida Rodrigues - 3º DS</p>
<p class="pontos">XXXX pontos</p>

<router-link v-for="(item, index) in ranking" :key="index" :to="`/aluno/profile/${item.aluno.rm}`" class="aluno">
<b>#{{ index + 1 }}</b>
<img :src="(index + 1 < 4) ? '../assets/icons/m' + (index + 1) + '.png' : '../../assets/icons/m3.png'" :class="(index + 1 < 4) ? 'medalha' : 'medalha normal' " alt="">
<img v-if="item.aluno.imagem != 'default'" :src="item.aluno.imagem" alt="Foto do aluno">
<img v-else src="../../assets/icons/artwork.png" alt="Foto padrão">
<p class="name">{{ item.aluno.nome }} - 3º DS</p>
<p class="pontos">{{ (item.rankingNota * 1000).toFixed(2) }} pontos</p>
</router-link>
</div>
</div>
Expand All @@ -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: {
Expand All @@ -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();
},
};
</script>

Expand Down
105 changes: 105 additions & 0 deletions client/src/views/shared/Ranking.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<Header />
<div id="app">
<main>
<section class="content">
<div class="box" id="box1">
<H1>Rankings</H1>
<h2>Ranking gerados a partir das notas dos alunos. O objetivo desse ranking é proporcionar competitividade e destacar os alunos para as empresas.</h2>

<div class="alunos">
<p class="info">Ranking geral:</p>

<router-link v-for="(item, index) in ranking" :key="index" :to="`/aluno/profile/${item.aluno.rm}`" class="aluno">
<b>#{{ index + 1 }}</b>
<img :src="(index + 1 < 4) ? '../assets/icons/m' + (index + 1) + '.png' : '../../assets/icons/m3.png'" :class="(index + 1 < 4) ? 'medalha' : 'medalha normal' " alt="">
<img v-if="item.aluno.imagem != 'default'" :src="item.aluno.imagem" alt="Foto do aluno">
<img v-else src="../../assets/icons/artwork.png" alt="Foto padrão">
<p class="name">{{ item.aluno.nome }} - 3º DS</p>
<p class="pontos">{{ (item.rankingNota * 1000).toFixed(2) }} pontos</p>
</router-link>
</div>
</div>
</section>
</main>
</div>
</template>

<script>
import Header from '../../components/aluno/Header.vue';
import searchIcon from '../../assets/icons/procurar.png';
import Cookies from 'js-cookie';
import { getNotaRanking } from '../../services/api/shared';
export default {
name: 'Ranking',
components: {
Header,
},
data() {
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();
},
};
</script>

<style lang="scss" scoped>
@import "../../scss/pages/shared/_ranking.scss";
#app {
display: flex;
flex-direction: column;
min-height: calc(100vh - 80px);
min-height: 510px;
main {
display: flex;
flex: 1;
min-height: calc(100vh - 80px);
overflow: hidden;
.content {
flex: 1;
min-height: calc(100vh - 80px);
padding: 20px;
overflow-y: auto;
@media (max-width: 1000px) {
width: calc(100% - 100px);
}
}
}
}
</style>
39 changes: 32 additions & 7 deletions server/src/modules/services/shared/GetRanking.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 529dd6b

Please sign in to comment.