Using champions alias instead of id in urls
All checks were successful
pipeline / build-and-push-images (push) Successful in 25s
All checks were successful
pipeline / build-and-push-images (push) Successful in 25s
This commit is contained in:
@@ -17,7 +17,7 @@ watch(searchText, (newT, oldT) => {
|
||||
<input v-model="searchText" ref="searchBar" class="search-bar" type="text" placeholder="Champion name..."/>
|
||||
</div>
|
||||
<div class="champion-container" style="margin-top: 20px;">
|
||||
<RouterLink style="margin-left: 5px; margin-right: 5px;" v-for="champion in filteredChampions" :to="'/champion/' + champion.id">
|
||||
<RouterLink style="margin-left: 5px; margin-right: 5px;" v-for="champion in filteredChampions" :to="'/champion/' + champion.alias.toLowerCase()">
|
||||
<img :src="CDRAGON_BASE + mapPath(champion.squarePortraitPath)" :alt="champion.name"/>
|
||||
</RouterLink>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
<script setup>
|
||||
const route = useRoute()
|
||||
const championId = route.params.id
|
||||
const championAlias = route.params.alias
|
||||
|
||||
const { data : championData } = await useFetch("/api/champion/" + championId)
|
||||
const { data : championData } = await useFetch("/api/champion/" + championAlias.toLowerCase())
|
||||
const championId = championData.value.id
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head>
|
||||
<Title>{{ championData.name }} builds</Title>
|
||||
</Head>
|
||||
|
||||
<div style="display: flex; width: fit-content; margin: auto;">
|
||||
<div style="margin-top: 64px;">
|
||||
<ChampionTitle :champion-id="championId" :winrate="championData.winrate" :pickrate="championData.pickrate" :game-count="championData.gameCount" />
|
||||
@@ -12,19 +12,19 @@ async function fetchLatestPatch(client) {
|
||||
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
|
||||
return latestPatch.patch
|
||||
}
|
||||
async function championInfos(client, patch, championId) {
|
||||
async function championInfos(client, patch, championAlias) {
|
||||
const database = client.db("champions");
|
||||
const collection = database.collection(patch);
|
||||
const query = { id:Number(championId) };
|
||||
const query = { alias:championAlias };
|
||||
const championInfo = await collection.findOne(query);
|
||||
return championInfo
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const championId = getRouterParam(event, "id")
|
||||
const championAlias = getRouterParam(event, "alias").toLowerCase()
|
||||
const client = await connectToDatabase();
|
||||
const latestPatch = await fetchLatestPatch(client);
|
||||
const data = await championInfos(client, latestPatch, championId);
|
||||
const data = await championInfos(client, latestPatch, championAlias);
|
||||
await client.close()
|
||||
return data
|
||||
})
|
||||
Reference in New Issue
Block a user