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

This commit is contained in:
Art Lowel
2017-02-16 15:25:18 +01:00
parent d63fc0a9bb
commit 43a2b9699e
12 changed files with 52 additions and 40 deletions

View File

@@ -40,8 +40,8 @@ export class CollectionDataEffects {
this.cache.add(collection, GlobalConfig.cache.msToLive);
});
})
.map((collections: Array<Collection>) => collections.map(collection => collection.id))
.map((ids: Array<string>) => new CollectionFindMultipleSuccessAction(ids))
.map((collections: Array<Collection>) => collections.map(collection => collection.uuid))
.map((uuids: Array<string>) => 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<Collection>(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)));
}
});

View File

@@ -18,7 +18,7 @@ export class CollectionDataService {
findAll(scopeID?: string): Observable<Collection[]> {
this.store.dispatch(new CollectionFindMultipleRequestAction(scopeID));
//get an observable of the IDs from the collectionData store
return this.store.select<Array<string>>('core', 'collectionData', 'findMultiple', 'collectionsIDs')
return this.store.select<Array<string>>('core', 'collectionData', 'findMultiple', 'collectionUUIDs')
.flatMap((collectionIds: Array<string>) => {
// use those IDs to fetch the actual collection objects from the cache
return this.cache.getList<Collection>(collectionIds);
@@ -27,7 +27,10 @@ export class CollectionDataService {
findById(id: string): Observable<Collection> {
this.store.dispatch(new CollectionFindByIdRequestAction(id));
return this.cache.get<Collection>(id);
return this.store.select<string>('core', 'collectionData', 'findSingle', 'collectionUUID')
.flatMap((collectionUUID: string) => {
return this.cache.get<Collection>(collectionUUID);
});
}
}

View File

@@ -34,8 +34,8 @@ export class CollectionFindMultipleSuccessAction implements Action {
type = CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS;
payload: Array<string>;
constructor(collectionIDs: Array<string>) {
this.payload = collectionIDs;
constructor(collectionUUIDs: Array<string>) {
this.payload = collectionUUIDs;
}
}

View File

@@ -7,7 +7,7 @@ import {
export interface CollectionFindMultipleState {
scopeID: string;
collectionsIDs: Array<String>;
collectionUUIDs: Array<String>;
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
});
}

View File

@@ -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;
}
}

View File

@@ -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
});
}

View File

@@ -40,8 +40,8 @@ export class ItemDataEffects {
this.cache.add(item, GlobalConfig.cache.msToLive);
});
})
.map((items: Array<Item>) => items.map(item => item.id))
.map((ids: Array<string>) => new ItemFindMultipleSuccessAction(ids))
.map((items: Array<Item>) => items.map(item => item.uuid))
.map((uuids: Array<string>) => 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<Item>(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)));
}
});

View File

@@ -18,16 +18,19 @@ export class ItemDataService {
findAll(scopeID?: string): Observable<Item[]> {
this.store.dispatch(new ItemFindMultipleRequestAction(scopeID));
//get an observable of the IDs from the itemData store
return this.store.select<Array<string>>('core', 'itemData', 'findMultiple', 'itemsIDs')
.flatMap((itemIds: Array<string>) => {
return this.store.select<Array<string>>('core', 'itemData', 'findMultiple', 'itemUUIDs')
.flatMap((itemUUIDs: Array<string>) => {
// use those IDs to fetch the actual item objects from the cache
return this.cache.getList<Item>(itemIds);
return this.cache.getList<Item>(itemUUIDs);
});
}
findById(id: string): Observable<Item> {
this.store.dispatch(new ItemFindByIdRequestAction(id));
return this.cache.get<Item>(id);
return this.store.select<string>('core', 'itemData', 'findSingle', 'itemUUID')
.flatMap((itemUUID: string) => {
return this.cache.get<Item>(itemUUID);
});
}
}

View File

@@ -34,8 +34,8 @@ export class ItemFindMultipleSuccessAction implements Action {
type = ItemFindMultipleActionTypes.FIND_MULTI_SUCCESS;
payload: Array<string>;
constructor(itemIDs: Array<string>) {
this.payload = itemIDs;
constructor(itemUUIDs: Array<string>) {
this.payload = itemUUIDs;
}
}

View File

@@ -7,7 +7,7 @@ import {
export interface ItemFindMultipleState {
scopeID: string;
itemsIDs: Array<String>;
itemUUIDs: Array<String>;
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
});
}

View File

@@ -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;
}
}

View File

@@ -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
});
}