From b5c3148e23284eee0809eeff6e989d19b1bcc6bb Mon Sep 17 00:00:00 2001 From: Konrad Mohrfeldt <km@roko.li> Date: Tue, 23 Jul 2024 17:55:50 +0200 Subject: [PATCH] feat: implement request aggregation for schedule, show and timeslot stores refs #301 --- src/stores/schedules.ts | 7 ++++++- src/stores/shows.ts | 8 ++++++-- src/stores/timeslots.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/stores/schedules.ts b/src/stores/schedules.ts index d4c03d86..73760931 100644 --- a/src/stores/schedules.ts +++ b/src/stores/schedules.ts @@ -12,16 +12,21 @@ import { createSteeringURL } from '@/api' import { steeringAuthInit } from '@/stores/auth' import { Schedule, ScheduleConflictSolution, ScheduleCreateData } from '@/types' import { computed } from 'vue' +import { aggregateWithIdsParameter } from '@/util/api' export const useScheduleStore = defineStore('schedules', () => { const endpoint = createSteeringURL.prefix('schedules') const { api, base } = createExtendableAPI<Schedule>(endpoint, steeringAuthInit) + const listOperations = APIListPaginated(api) const { update } = APIUpdate<Schedule, ScheduleCreateData>(api) return { ...base, update, + ...listOperations, + ...APIRetrieve(api, { + aggregate: aggregateWithIdsParameter(listOperations.listIsolated), + }), ...APICreate<Schedule, ScheduleCreateData>(api), - ...APIListPaginated(api), ...APIRetrieve(api), ...APIRemove(api), } diff --git a/src/stores/shows.ts b/src/stores/shows.ts index 126841a6..cead1012 100644 --- a/src/stores/shows.ts +++ b/src/stores/shows.ts @@ -17,6 +17,7 @@ import { createSteeringURL } from '@/api' import { components } from '@/steering-types' import { steeringAuthInit, useAuthStore, useOnAuthBehaviour } from '@/stores/auth' import { KeysFrom, Show } from '@/types' +import { aggregateWithIdsParameter } from '@/util/api' type ReadonlyAttrs = KeysFrom<Show, 'id' | 'createdAt' | 'createdBy' | 'updatedAt' | 'updatedBy'> type ShowCreateData = Omit<Show, ReadonlyAttrs | 'slug'> & { slug?: string } @@ -115,6 +116,7 @@ export const useShowStore = defineStore('shows', () => { const endpoint = createSteeringURL.prefix('shows') const { api, base } = createExtendableAPI<Show>(endpoint, steeringAuthInit) const { selectedShow, selectedShowId } = useSelectedShowBehaviour(api) + const listOperations = APIListPaginated(api) useRouteSyncBehaviour(selectedShowId, selectedShow) // Make sure the store contains a list of all shows, which are @@ -123,8 +125,10 @@ export const useShowStore = defineStore('shows', () => { return { ...base, - ...APIListPaginated(api), - ...APIRetrieve(api), + ...listOperations, + ...APIRetrieve(api, { + aggregate: aggregateWithIdsParameter(listOperations.listIsolated), + }), ...APICreate<Show, ShowCreateData>(api), ...APIUpdate<Show, ShowUpdateData, ShowPartialUpdateData>(api), ...APIRemove(api), diff --git a/src/stores/timeslots.ts b/src/stores/timeslots.ts index a34d1d34..716d6b57 100644 --- a/src/stores/timeslots.ts +++ b/src/stores/timeslots.ts @@ -11,6 +11,7 @@ import { createSteeringURL } from '@/api' import { components } from '@/steering-types' import { steeringAuthInit } from '@/stores/auth' import { KeysFrom, TimeSlot } from '@/types' +import { aggregateWithIdsParameter } from '@/util/api' type ReadonlyAttrs = KeysFrom<TimeSlot, 'id'> type TimeSlotUpdateData = Omit<TimeSlot, ReadonlyAttrs> @@ -19,10 +20,13 @@ type TimeSlotPartialUpdateData = components['schemas']['PatchedTimeSlot'] export const useTimeSlotStore = defineStore('timeslots', () => { const endpoint = createSteeringURL.prefix('timeslots') const { api, base } = createExtendableAPI<TimeSlot>(endpoint, steeringAuthInit) + const listOperations = APIListPaginated(api) return { ...base, - ...APIListPaginated(api), - ...APIRetrieve(api), + ...listOperations, + ...APIRetrieve(api, { + aggregate: aggregateWithIdsParameter(listOperations.listIsolated), + }), ...APIUpdate<TimeSlot, TimeSlotUpdateData, TimeSlotPartialUpdateData>(api), ...APIRemove(api), } -- GitLab