Skip to content

Commit

Permalink
feat: competitor pool league link
Browse files Browse the repository at this point in the history
- link to actual league linked with pool rather than guessing based on name
- still mostly assuming there is only 1 related league
  • Loading branch information
brownben committed Jan 30, 2024
1 parent 8590104 commit 27b5de1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
10 changes: 10 additions & 0 deletions backend/src/database/leagues.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ async def get_by_name(name: str) -> Optional[League]:
.run()
)

@staticmethod
async def get_by_competitor_pool(competitor_pool: str) -> Iterable[League]:
return (
League.parse_obj(league)
for league in await LeagueTable.select(*league_fields)
.where(LeagueTable.competitor_pool == competitor_pool)
.order_by(LeagueTable.year, ascending=False)
.run()
)

@staticmethod
async def delete_by_name(name: str) -> None:
await LeagueTable.delete().where(LeagueTable.name == name).run()
Expand Down
16 changes: 13 additions & 3 deletions backend/src/routes/competitor_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from fastapi import Path
from fastapi.routing import APIRouter

from ..database import Competitors, Events
from ..schemas import Competitor, Event, EventWithUploadKey
from ..database import Competitors, Events, Leagues
from ..schemas import Competitor, Event, EventWithUploadKey, League

router = APIRouter(
prefix="/competitor-pools",
Expand All @@ -17,8 +17,18 @@ async def get_all_competitor_pools() -> Iterable[str]:
return await Competitors.get_all_pools()


@router.get("/{name}/leagues", response_model=list[League])
async def get_leagues_in_competitor_pool(
name: str = Path(
title="Competitor Pool Name",
example="Edinburgh Winter 2020",
),
) -> Iterable[League]:
return await Leagues.get_by_competitor_pool(name)


@router.get("/{name}/competitors", response_model=list[Competitor])
async def get_competitor_details(
async def get_competitors_in_competitor_pool(
name: str = Path(
title="Competitor Pool Name",
example="Edinburgh Winter 2020",
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/League.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defineProps({
:to="`/leagues/${league.name}`"
class="mt-6 inline-block text-main-700 hover:text-main-800"
>
View More
View details
</NuxtLink>
</article>
</template>
27 changes: 18 additions & 9 deletions frontend/pages/competitor-pools/[name].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
import {
UserGroupIcon,
AdjustmentsVerticalIcon,
TrophyIcon,
} from '@heroicons/vue/24/outline'
import type { Filters } from '~/utils/filter'
import type { Competitor } from '~/api-types'
import type { Competitor, League } from '~/api-types'
const loggedIn = useLoggedIn()
if (!loggedIn.value) await redirect('/login')
const route = useRoute()
const pool_name = queryToString(route.params.name)
const { data } = await useData<Competitor[]>(
`competitor-pools/${route.params.name}/competitors`,
`competitor-pools/${pool_name}/competitors`,
)
const { data: leagues } = await useData<League[]>(
`competitor-pools/${pool_name}/leagues`,
)
const competitors = computed(
() => data.value?.map(competitorWithAgeGender) ?? [],
)
const name = queryToString(route.params.name)
const show = ref(false)
const filters = reactive<Filters>({
Expand All @@ -37,10 +42,14 @@ useTitle({
<template>
<div>
<Heading
:title="name"
link-text="← League Home"
:link-location="`/leagues/${route.params.name}`"
title="Competitors"
:link-text="leagues?.[0]?.name"
:link-location="`/leagues/${leagues?.[0]?.name}`"
>
<ImageRow v-if="leagues && leagues.length > 1" :icon="TrophyIcon">
<strong class="font-medium">{{ leagues.length }}</strong>
Leagues
</ImageRow>
<ImageRow :icon="UserGroupIcon">
<strong class="font-medium">{{ competitors.length }}</strong>
Competitors
Expand Down Expand Up @@ -97,15 +106,15 @@ useTitle({
:links="[
{
text: 'Add Competitor',
location: `/competitors/create?competitor_pool=${name}`,
location: `/competitors/create?competitor_pool=${pool_name}`,
},
{
text: 'Merge Competitors',
location: `/competitors/merge?competitor_pool=${name}`,
location: `/competitors/merge?competitor_pool=${pool_name}`,
},
{
text: 'Add Result',
location: `/results/manual?competitor_pool=${name}`,
location: `/results/manual?competitor_pool=${pool_name}`,
},
]"
dark
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/competitors/merge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ useTitle({

<template>
<div>
<Heading title="Merge Competitors" />
<Heading
title="Merge Competitors"
tagline="Combine two competitor records into one."
/>

<Form button="Merge" :action="action">
<InputDropdown
Expand Down

0 comments on commit 27b5de1

Please sign in to comment.