Skip to content

Commit

Permalink
refactor: to use new locationinfo model
Browse files Browse the repository at this point in the history
  • Loading branch information
JTraill committed Feb 24, 2025
1 parent 0ff4602 commit dd8b670
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 134 deletions.
24 changes: 15 additions & 9 deletions web/src/components/courtlist/CourtListSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@update:modelValue="selectedCourtRoom = ''"
:items="locationsAndCourtRooms"
return-object
item-title="locationNm"
item-title="name"
item-value="locationId"
label="Location"
:loading="!isLocationDataMounted"
Expand All @@ -32,8 +32,8 @@
: ['']
"
label="Room"
item-title="courtRoomCd"
item-value="courtRoomCd"
item-title="room"
item-value="room"
:error-messages="
errors.isMissingRoom ? ['Room is required'] : []
"
Expand Down Expand Up @@ -93,22 +93,24 @@
import { LocationService } from '@/services';
import { HttpService } from '@/services/HttpService';
import { useCommonStore, useCourtListStore } from '@/stores';
import { PCSSLocationCourtRooms } from '@/types/courtlist';
import { LocationInfo } from '@/types/courtlist';
import { courtListType } from '@/types/courtlist/jsonTypes';
import { mdiClose } from '@mdi/js';
import { computed, inject, onMounted, reactive, ref, watch } from 'vue';
// Component v-models
const showDropdown = defineModel<boolean>('showDropdown');
const isSearching = defineModel<boolean>('isSearching');
const date = defineModel<Date>('date');
const bannerDate = defineModel<Date | null>('bannerDate');
watch(bannerDate, (newValue, oldValue) => {
if (oldValue != null && newValue !== oldValue) {
searchForCourtList();
}
});
const GREEN = '#62d3a4';
const emit = defineEmits(['courtListSearched']);
const GREEN = '#62d3a4';
const commonStore = useCommonStore();
const courtListStore = useCourtListStore();
// State variables
Expand All @@ -126,21 +128,23 @@
isMissingRoom: false,
isMissingLocation: false,
});
const selectedCourtLocation = ref<PCSSLocationCourtRooms>();
const selectedCourtLocation = ref<LocationInfo>();
const httpService = inject<HttpService>('httpService');
const locationsAndCourtRooms = ref<PCSSLocationCourtRooms[]>();
const locationsAndCourtRooms = ref<LocationInfo[]>();
const locationsService = inject<LocationService>('locationService');
if (!httpService) {
throw new Error('Service is undefined.');
}
onMounted(async () => {
getListOfAvailableCourts();
await getListOfAvailableCourts();
isLoading.value = false;
});
const getListOfAvailableCourts = async () => {
locationsAndCourtRooms.value = await locationsService?.getPCSSCourtRooms();
locationsAndCourtRooms.value =
await locationsService?.getLocationsAndCourtRooms();
commonStore.updateCourtRoomsAndLocations(locationsAndCourtRooms.value);
isLocationDataMounted.value = true;
};
Expand All @@ -166,8 +170,10 @@
.then((Response) => Response)
.then((data) => {
if (data) {
courtListStore.courtListInformation.detailsData = data;
isDataReady.value = true;
isSearching.value = false;
emit('courtListSearched', data);
}
isMounted.value = true;
Expand Down
39 changes: 38 additions & 1 deletion web/src/services/LocationService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Location } from '@/types';
import { CourtRoomsJsonInfoType } from '../types/common';
import { roomsInfoType } from '../types/courtlist';
import { LocationInfo, roomsInfoType } from '../types/courtlist';
import { HttpService } from './HttpService';

export class LocationService {
Expand Down Expand Up @@ -33,4 +33,41 @@ export class LocationService {
async getDashboardLocations(): Promise<Location[]> {
return await this.httpService.get<Location[]>('api/location/pcss');
}

async getLocationsAndCourtRooms(): Promise<LocationInfo[]> {
// todo: replace this test data with actual api call
const testData = [
{
name: 'Test Court',
code: '1',
locationId: '1',
justinLocationName: 'Test Court',
justinLocationId: '2',
active: true,
courtRooms: [
{
room: '1',
locationId: '1',
type: 'Courtroom',
},
{
room: '2',
locationId: '1',
type: 'Courtroom',
},
{
room: '3',
locationId: '1',
type: 'Courtroom',
},
{
room: '4',
locationId: '1',
type: 'Courtroom',
},
],
},
] as LocationInfo[];
return testData;
}
}
Loading

0 comments on commit dd8b670

Please sign in to comment.