From 43a2b9699e73dcfa64a879963cdbe3697d833818 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Thu, 16 Feb 2017 15:25:18 +0100 Subject: [PATCH] Made a clear distinction between IDs and UUIDs - as IDs will probably change in the future to be easier to work with (shorter urls) and applicable to multiple versions of a resource --- .../collection/collection-data.effects.ts | 8 ++++---- .../collection/collection-data.service.ts | 7 +++++-- .../collection/collection-find-multiple.actions.ts | 4 ++-- .../collection/collection-find-multiple.reducer.ts | 8 ++++---- .../collection/collection-find-single.actions.ts | 8 ++++---- .../collection/collection-find-single.reducer.ts | 9 ++++++--- src/app/core/data-services/item/item-data.effects.ts | 8 ++++---- src/app/core/data-services/item/item-data.service.ts | 11 +++++++---- .../data-services/item/item-find-multiple.actions.ts | 4 ++-- .../data-services/item/item-find-multiple.reducer.ts | 8 ++++---- .../data-services/item/item-find-single.actions.ts | 8 ++++---- .../data-services/item/item-find-single.reducer.ts | 9 ++++++--- 12 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/app/core/data-services/collection/collection-data.effects.ts b/src/app/core/data-services/collection/collection-data.effects.ts index a9bb37c231..2b2d468a5c 100644 --- a/src/app/core/data-services/collection/collection-data.effects.ts +++ b/src/app/core/data-services/collection/collection-data.effects.ts @@ -40,8 +40,8 @@ export class CollectionDataEffects { this.cache.add(collection, GlobalConfig.cache.msToLive); }); }) - .map((collections: Array) => collections.map(collection => collection.id)) - .map((ids: Array) => new CollectionFindMultipleSuccessAction(ids)) + .map((collections: Array) => collections.map(collection => collection.uuid)) + .map((uuids: Array) => new CollectionFindMultipleSuccessAction(uuids)) .catch((errorMsg: string) => Observable.of(new CollectionFindMultipleErrorAction(errorMsg))); }); @@ -50,7 +50,7 @@ export class CollectionDataEffects { .switchMap(action => { if (this.cache.has(action.payload)) { return this.cache.get(action.payload) - .map(collection => new CollectionFindByIdSuccessAction(collection.id)); + .map(collection => new CollectionFindByIdSuccessAction(collection.uuid)); } else { return this.restApi.get(`/collections/${action.payload}`) @@ -58,7 +58,7 @@ export class CollectionDataEffects { .do((collection: Collection) => { this.cache.add(collection, GlobalConfig.cache.msToLive); }) - .map((collection: Collection) => new CollectionFindByIdSuccessAction(collection.id)) + .map((collection: Collection) => new CollectionFindByIdSuccessAction(collection.uuid)) .catch((errorMsg: string) => Observable.of(new CollectionFindByIdErrorAction(errorMsg))); } }); diff --git a/src/app/core/data-services/collection/collection-data.service.ts b/src/app/core/data-services/collection/collection-data.service.ts index 7f191eb603..3a7d69a724 100644 --- a/src/app/core/data-services/collection/collection-data.service.ts +++ b/src/app/core/data-services/collection/collection-data.service.ts @@ -18,7 +18,7 @@ export class CollectionDataService { findAll(scopeID?: string): Observable { this.store.dispatch(new CollectionFindMultipleRequestAction(scopeID)); //get an observable of the IDs from the collectionData store - return this.store.select>('core', 'collectionData', 'findMultiple', 'collectionsIDs') + return this.store.select>('core', 'collectionData', 'findMultiple', 'collectionUUIDs') .flatMap((collectionIds: Array) => { // use those IDs to fetch the actual collection objects from the cache return this.cache.getList(collectionIds); @@ -27,7 +27,10 @@ export class CollectionDataService { findById(id: string): Observable { this.store.dispatch(new CollectionFindByIdRequestAction(id)); - return this.cache.get(id); + return this.store.select('core', 'collectionData', 'findSingle', 'collectionUUID') + .flatMap((collectionUUID: string) => { + return this.cache.get(collectionUUID); + }); } } diff --git a/src/app/core/data-services/collection/collection-find-multiple.actions.ts b/src/app/core/data-services/collection/collection-find-multiple.actions.ts index bdd657dc0f..dd79b274c0 100644 --- a/src/app/core/data-services/collection/collection-find-multiple.actions.ts +++ b/src/app/core/data-services/collection/collection-find-multiple.actions.ts @@ -34,8 +34,8 @@ export class CollectionFindMultipleSuccessAction implements Action { type = CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS; payload: Array; - constructor(collectionIDs: Array) { - this.payload = collectionIDs; + constructor(collectionUUIDs: Array) { + this.payload = collectionUUIDs; } } diff --git a/src/app/core/data-services/collection/collection-find-multiple.reducer.ts b/src/app/core/data-services/collection/collection-find-multiple.reducer.ts index 2a3cf6776d..e64ce5011b 100644 --- a/src/app/core/data-services/collection/collection-find-multiple.reducer.ts +++ b/src/app/core/data-services/collection/collection-find-multiple.reducer.ts @@ -7,7 +7,7 @@ import { export interface CollectionFindMultipleState { scopeID: string; - collectionsIDs: Array; + collectionUUIDs: Array; isLoading: boolean; errorMessage: string; paginationOptions: PaginationOptions; @@ -16,7 +16,7 @@ export interface CollectionFindMultipleState { const initialState: CollectionFindMultipleState = { scopeID: undefined, - collectionsIDs: [], + collectionUUIDs: [], isLoading: false, errorMessage: undefined, paginationOptions: undefined, @@ -29,7 +29,7 @@ export const findMultipleReducer = (state = initialState, action: CollectionFind case CollectionFindMultipleActionTypes.FIND_MULTI_REQUEST: { return Object.assign({}, state, { scopeID: action.payload.scopeID, - collectionsIDs: [], + collectionUUIDs: [], isLoading: true, errorMessage: undefined, paginationOptions: action.payload.paginationOptions, @@ -40,7 +40,7 @@ export const findMultipleReducer = (state = initialState, action: CollectionFind case CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS: { return Object.assign({}, state, { isLoading: false, - collectionsIDs: action.payload, + collectionUUIDs: action.payload, errorMessage: undefined }); } diff --git a/src/app/core/data-services/collection/collection-find-single.actions.ts b/src/app/core/data-services/collection/collection-find-single.actions.ts index 92335cd49e..392dbe3482 100644 --- a/src/app/core/data-services/collection/collection-find-single.actions.ts +++ b/src/app/core/data-services/collection/collection-find-single.actions.ts @@ -12,8 +12,8 @@ export class CollectionFindByIdRequestAction implements Action { type = CollectionFindSingleActionTypes.FIND_BY_ID_REQUEST; payload: string; - constructor(id: string) { - this.payload = id; + constructor(requestID: string) { + this.payload = requestID; } } @@ -21,8 +21,8 @@ export class CollectionFindByIdSuccessAction implements Action { type = CollectionFindSingleActionTypes.FIND_BY_ID_SUCCESS; payload: string; - constructor(collectionID: string) { - this.payload = collectionID; + constructor(collectionUUID: string) { + this.payload = collectionUUID; } } diff --git a/src/app/core/data-services/collection/collection-find-single.reducer.ts b/src/app/core/data-services/collection/collection-find-single.reducer.ts index 720efdbca1..49c330cdfb 100644 --- a/src/app/core/data-services/collection/collection-find-single.reducer.ts +++ b/src/app/core/data-services/collection/collection-find-single.reducer.ts @@ -7,13 +7,15 @@ import { export interface CollectionFindSingleState { isLoading: boolean; errorMessage: string; - collectionID: string; + requestedID: string; + collectionUUID: string; } const initialState: CollectionFindSingleState = { isLoading: false, errorMessage: undefined, - collectionID: undefined + requestedID: undefined, + collectionUUID: undefined }; export const findSingleReducer = (state = initialState, action: CollectionFindSingleAction): CollectionFindSingleState => { @@ -23,7 +25,7 @@ export const findSingleReducer = (state = initialState, action: CollectionFindSi return Object.assign({}, state, { isLoading: true, errorMessage: undefined, - collectionID: action.payload + requestedID: action.payload }); } @@ -31,6 +33,7 @@ export const findSingleReducer = (state = initialState, action: CollectionFindSi return Object.assign({}, state, { isLoading: false, errorMessage: undefined, + collectionUUID: action.payload }); } diff --git a/src/app/core/data-services/item/item-data.effects.ts b/src/app/core/data-services/item/item-data.effects.ts index 41554453d3..63336df3e9 100644 --- a/src/app/core/data-services/item/item-data.effects.ts +++ b/src/app/core/data-services/item/item-data.effects.ts @@ -40,8 +40,8 @@ export class ItemDataEffects { this.cache.add(item, GlobalConfig.cache.msToLive); }); }) - .map((items: Array) => items.map(item => item.id)) - .map((ids: Array) => new ItemFindMultipleSuccessAction(ids)) + .map((items: Array) => items.map(item => item.uuid)) + .map((uuids: Array) => new ItemFindMultipleSuccessAction(uuids)) .catch((errorMsg: string) => Observable.of(new ItemFindMultipleErrorAction(errorMsg))); }); @@ -50,7 +50,7 @@ export class ItemDataEffects { .switchMap(action => { if (this.cache.has(action.payload)) { return this.cache.get(action.payload) - .map(item => new ItemFindByIdSuccessAction(item.id)); + .map(item => new ItemFindByIdSuccessAction(item.uuid)); } else { return this.restApi.get(`/items/${action.payload}`) @@ -58,7 +58,7 @@ export class ItemDataEffects { .do((item: Item) => { this.cache.add(item, GlobalConfig.cache.msToLive); }) - .map((item: Item) => new ItemFindByIdSuccessAction(item.id)) + .map((item: Item) => new ItemFindByIdSuccessAction(item.uuid)) .catch((errorMsg: string) => Observable.of(new ItemFindByIdErrorAction(errorMsg))); } }); diff --git a/src/app/core/data-services/item/item-data.service.ts b/src/app/core/data-services/item/item-data.service.ts index a3701d9f7b..36fa5a91db 100644 --- a/src/app/core/data-services/item/item-data.service.ts +++ b/src/app/core/data-services/item/item-data.service.ts @@ -18,16 +18,19 @@ export class ItemDataService { findAll(scopeID?: string): Observable { this.store.dispatch(new ItemFindMultipleRequestAction(scopeID)); //get an observable of the IDs from the itemData store - return this.store.select>('core', 'itemData', 'findMultiple', 'itemsIDs') - .flatMap((itemIds: Array) => { + return this.store.select>('core', 'itemData', 'findMultiple', 'itemUUIDs') + .flatMap((itemUUIDs: Array) => { // use those IDs to fetch the actual item objects from the cache - return this.cache.getList(itemIds); + return this.cache.getList(itemUUIDs); }); } findById(id: string): Observable { this.store.dispatch(new ItemFindByIdRequestAction(id)); - return this.cache.get(id); + return this.store.select('core', 'itemData', 'findSingle', 'itemUUID') + .flatMap((itemUUID: string) => { + return this.cache.get(itemUUID); + }); } } diff --git a/src/app/core/data-services/item/item-find-multiple.actions.ts b/src/app/core/data-services/item/item-find-multiple.actions.ts index 6d90a1f604..72649dba85 100644 --- a/src/app/core/data-services/item/item-find-multiple.actions.ts +++ b/src/app/core/data-services/item/item-find-multiple.actions.ts @@ -34,8 +34,8 @@ export class ItemFindMultipleSuccessAction implements Action { type = ItemFindMultipleActionTypes.FIND_MULTI_SUCCESS; payload: Array; - constructor(itemIDs: Array) { - this.payload = itemIDs; + constructor(itemUUIDs: Array) { + this.payload = itemUUIDs; } } diff --git a/src/app/core/data-services/item/item-find-multiple.reducer.ts b/src/app/core/data-services/item/item-find-multiple.reducer.ts index 1621a63cd8..bb3431b1fc 100644 --- a/src/app/core/data-services/item/item-find-multiple.reducer.ts +++ b/src/app/core/data-services/item/item-find-multiple.reducer.ts @@ -7,7 +7,7 @@ import { export interface ItemFindMultipleState { scopeID: string; - itemsIDs: Array; + itemUUIDs: Array; isLoading: boolean; errorMessage: string; paginationOptions: PaginationOptions; @@ -16,7 +16,7 @@ export interface ItemFindMultipleState { const initialState: ItemFindMultipleState = { scopeID: undefined, - itemsIDs: [], + itemUUIDs: [], isLoading: false, errorMessage: undefined, paginationOptions: undefined, @@ -29,7 +29,7 @@ export const findMultipleReducer = (state = initialState, action: ItemFindMultip case ItemFindMultipleActionTypes.FIND_MULTI_REQUEST: { return Object.assign({}, state, { scopeID: action.payload.scopeID, - itemsIDs: [], + itemUUIDs: [], isLoading: true, errorMessage: undefined, paginationOptions: action.payload.paginationOptions, @@ -40,7 +40,7 @@ export const findMultipleReducer = (state = initialState, action: ItemFindMultip case ItemFindMultipleActionTypes.FIND_MULTI_SUCCESS: { return Object.assign({}, state, { isLoading: false, - itemsIDs: action.payload, + itemUUIDs: action.payload, errorMessage: undefined }); } diff --git a/src/app/core/data-services/item/item-find-single.actions.ts b/src/app/core/data-services/item/item-find-single.actions.ts index 1e00fdb6f1..f514d83474 100644 --- a/src/app/core/data-services/item/item-find-single.actions.ts +++ b/src/app/core/data-services/item/item-find-single.actions.ts @@ -12,8 +12,8 @@ export class ItemFindByIdRequestAction implements Action { type = ItemFindSingleActionTypes.FIND_BY_ID_REQUEST; payload: string; - constructor(id: string) { - this.payload = id; + constructor(requestID: string) { + this.payload = requestID; } } @@ -21,8 +21,8 @@ export class ItemFindByIdSuccessAction implements Action { type = ItemFindSingleActionTypes.FIND_BY_ID_SUCCESS; payload: string; - constructor(itemID: string) { - this.payload = itemID; + constructor(itemUUID: string) { + this.payload = itemUUID; } } diff --git a/src/app/core/data-services/item/item-find-single.reducer.ts b/src/app/core/data-services/item/item-find-single.reducer.ts index 5c11162cb0..83382728de 100644 --- a/src/app/core/data-services/item/item-find-single.reducer.ts +++ b/src/app/core/data-services/item/item-find-single.reducer.ts @@ -7,13 +7,15 @@ import { export interface ItemFindSingleState { isLoading: boolean; errorMessage: string; - itemID: string; + requestedID: string; + itemUUID: string; } const initialState: ItemFindSingleState = { isLoading: false, errorMessage: undefined, - itemID: undefined + requestedID: undefined, + itemUUID: undefined }; export const findSingleReducer = (state = initialState, action: ItemFindSingleAction): ItemFindSingleState => { @@ -23,7 +25,7 @@ export const findSingleReducer = (state = initialState, action: ItemFindSingleAc return Object.assign({}, state, { isLoading: true, errorMessage: undefined, - itemID: action.payload + requestedID: action.payload }); } @@ -31,6 +33,7 @@ export const findSingleReducer = (state = initialState, action: ItemFindSingleAc return Object.assign({}, state, { isLoading: false, errorMessage: undefined, + itemUUID: action.payload }); }