Skip to content

Commit

Permalink
Add get and fetch collection to store actions
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Sep 26, 2023
1 parent f72908a commit 69e924d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions client/src/stores/collectionElementsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,32 @@ export const useCollectionElementsStore = defineStore("collectionElementsStore",
}
}

async function getCollection(collectionId: string) {
const collection = storedCollections.value[collectionId];
if (!collection) {
return await fetchCollection({ id: collectionId });
}
return collection;
}

async function fetchCollection(params: { id: string }) {
Vue.set(loadingCollectionElements.value, params.id, true);
try {
const collection = await Service.fetchCollectionDetails({ hdcaId: params.id });
Vue.set(storedCollections.value, collection.id, collection);
return collection;
} finally {
Vue.delete(loadingCollectionElements.value, params.id);
}
}

return {
storedCollections,
storedCollectionElements,
getCollectionElements,
isLoadingCollectionElements,
getCollection,
fetchCollection,
loadCollectionElements,
saveCollections,
};
Expand Down
9 changes: 8 additions & 1 deletion client/src/stores/services/datasetCollection.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { fetcher } from "@/schema";

import { DCESummary, HDCASummary } from ".";
import { DCESummary, HDCADetailed, HDCASummary } from ".";

const DEFAULT_LIMIT = 50;

const getCollectionDetails = fetcher.path("/api/dataset_collections/{id}").method("get").create();

export async function fetchCollectionDetails(params: { hdcaId: string }): Promise<HDCADetailed> {
const { data } = await getCollectionDetails({ id: params.hdcaId });
return data;
}

const getCollectionContents = fetcher
.path("/api/dataset_collections/{hdca_id}/contents/{parent_id}")
.method("get")
Expand Down

0 comments on commit 69e924d

Please sign in to comment.