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); this.cache.add(collection, GlobalConfig.cache.msToLive);
}); });
}) })
.map((collections: Array<Collection>) => collections.map(collection => collection.id)) .map((collections: Array<Collection>) => collections.map(collection => collection.uuid))
.map((ids: Array<string>) => new CollectionFindMultipleSuccessAction(ids)) .map((uuids: Array<string>) => new CollectionFindMultipleSuccessAction(uuids))
.catch((errorMsg: string) => Observable.of(new CollectionFindMultipleErrorAction(errorMsg))); .catch((errorMsg: string) => Observable.of(new CollectionFindMultipleErrorAction(errorMsg)));
}); });
@@ -50,7 +50,7 @@ export class CollectionDataEffects {
.switchMap(action => { .switchMap(action => {
if (this.cache.has(action.payload)) { if (this.cache.has(action.payload)) {
return this.cache.get<Collection>(action.payload) return this.cache.get<Collection>(action.payload)
.map(collection => new CollectionFindByIdSuccessAction(collection.id)); .map(collection => new CollectionFindByIdSuccessAction(collection.uuid));
} }
else { else {
return this.restApi.get(`/collections/${action.payload}`) return this.restApi.get(`/collections/${action.payload}`)
@@ -58,7 +58,7 @@ export class CollectionDataEffects {
.do((collection: Collection) => { .do((collection: Collection) => {
this.cache.add(collection, GlobalConfig.cache.msToLive); 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))); .catch((errorMsg: string) => Observable.of(new CollectionFindByIdErrorAction(errorMsg)));
} }
}); });

View File

@@ -18,7 +18,7 @@ export class CollectionDataService {
findAll(scopeID?: string): Observable<Collection[]> { findAll(scopeID?: string): Observable<Collection[]> {
this.store.dispatch(new CollectionFindMultipleRequestAction(scopeID)); this.store.dispatch(new CollectionFindMultipleRequestAction(scopeID));
//get an observable of the IDs from the collectionData store //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>) => { .flatMap((collectionIds: Array<string>) => {
// use those IDs to fetch the actual collection objects from the cache // use those IDs to fetch the actual collection objects from the cache
return this.cache.getList<Collection>(collectionIds); return this.cache.getList<Collection>(collectionIds);
@@ -27,7 +27,10 @@ export class CollectionDataService {
findById(id: string): Observable<Collection> { findById(id: string): Observable<Collection> {
this.store.dispatch(new CollectionFindByIdRequestAction(id)); 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; type = CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS;
payload: Array<string>; payload: Array<string>;
constructor(collectionIDs: Array<string>) { constructor(collectionUUIDs: Array<string>) {
this.payload = collectionIDs; this.payload = collectionUUIDs;
} }
} }

View File

@@ -7,7 +7,7 @@ import {
export interface CollectionFindMultipleState { export interface CollectionFindMultipleState {
scopeID: string; scopeID: string;
collectionsIDs: Array<String>; collectionUUIDs: Array<String>;
isLoading: boolean; isLoading: boolean;
errorMessage: string; errorMessage: string;
paginationOptions: PaginationOptions; paginationOptions: PaginationOptions;
@@ -16,7 +16,7 @@ export interface CollectionFindMultipleState {
const initialState: CollectionFindMultipleState = { const initialState: CollectionFindMultipleState = {
scopeID: undefined, scopeID: undefined,
collectionsIDs: [], collectionUUIDs: [],
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
paginationOptions: undefined, paginationOptions: undefined,
@@ -29,7 +29,7 @@ export const findMultipleReducer = (state = initialState, action: CollectionFind
case CollectionFindMultipleActionTypes.FIND_MULTI_REQUEST: { case CollectionFindMultipleActionTypes.FIND_MULTI_REQUEST: {
return Object.assign({}, state, { return Object.assign({}, state, {
scopeID: action.payload.scopeID, scopeID: action.payload.scopeID,
collectionsIDs: [], collectionUUIDs: [],
isLoading: true, isLoading: true,
errorMessage: undefined, errorMessage: undefined,
paginationOptions: action.payload.paginationOptions, paginationOptions: action.payload.paginationOptions,
@@ -40,7 +40,7 @@ export const findMultipleReducer = (state = initialState, action: CollectionFind
case CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS: { case CollectionFindMultipleActionTypes.FIND_MULTI_SUCCESS: {
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: false, isLoading: false,
collectionsIDs: action.payload, collectionUUIDs: action.payload,
errorMessage: undefined errorMessage: undefined
}); });
} }

View File

@@ -12,8 +12,8 @@ export class CollectionFindByIdRequestAction implements Action {
type = CollectionFindSingleActionTypes.FIND_BY_ID_REQUEST; type = CollectionFindSingleActionTypes.FIND_BY_ID_REQUEST;
payload: string; payload: string;
constructor(id: string) { constructor(requestID: string) {
this.payload = id; this.payload = requestID;
} }
} }
@@ -21,8 +21,8 @@ export class CollectionFindByIdSuccessAction implements Action {
type = CollectionFindSingleActionTypes.FIND_BY_ID_SUCCESS; type = CollectionFindSingleActionTypes.FIND_BY_ID_SUCCESS;
payload: string; payload: string;
constructor(collectionID: string) { constructor(collectionUUID: string) {
this.payload = collectionID; this.payload = collectionUUID;
} }
} }

View File

@@ -7,13 +7,15 @@ import {
export interface CollectionFindSingleState { export interface CollectionFindSingleState {
isLoading: boolean; isLoading: boolean;
errorMessage: string; errorMessage: string;
collectionID: string; requestedID: string;
collectionUUID: string;
} }
const initialState: CollectionFindSingleState = { const initialState: CollectionFindSingleState = {
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
collectionID: undefined requestedID: undefined,
collectionUUID: undefined
}; };
export const findSingleReducer = (state = initialState, action: CollectionFindSingleAction): CollectionFindSingleState => { export const findSingleReducer = (state = initialState, action: CollectionFindSingleAction): CollectionFindSingleState => {
@@ -23,7 +25,7 @@ export const findSingleReducer = (state = initialState, action: CollectionFindSi
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: true, isLoading: true,
errorMessage: undefined, errorMessage: undefined,
collectionID: action.payload requestedID: action.payload
}); });
} }
@@ -31,6 +33,7 @@ export const findSingleReducer = (state = initialState, action: CollectionFindSi
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
collectionUUID: action.payload
}); });
} }

View File

@@ -40,8 +40,8 @@ export class ItemDataEffects {
this.cache.add(item, GlobalConfig.cache.msToLive); this.cache.add(item, GlobalConfig.cache.msToLive);
}); });
}) })
.map((items: Array<Item>) => items.map(item => item.id)) .map((items: Array<Item>) => items.map(item => item.uuid))
.map((ids: Array<string>) => new ItemFindMultipleSuccessAction(ids)) .map((uuids: Array<string>) => new ItemFindMultipleSuccessAction(uuids))
.catch((errorMsg: string) => Observable.of(new ItemFindMultipleErrorAction(errorMsg))); .catch((errorMsg: string) => Observable.of(new ItemFindMultipleErrorAction(errorMsg)));
}); });
@@ -50,7 +50,7 @@ export class ItemDataEffects {
.switchMap(action => { .switchMap(action => {
if (this.cache.has(action.payload)) { if (this.cache.has(action.payload)) {
return this.cache.get<Item>(action.payload) return this.cache.get<Item>(action.payload)
.map(item => new ItemFindByIdSuccessAction(item.id)); .map(item => new ItemFindByIdSuccessAction(item.uuid));
} }
else { else {
return this.restApi.get(`/items/${action.payload}`) return this.restApi.get(`/items/${action.payload}`)
@@ -58,7 +58,7 @@ export class ItemDataEffects {
.do((item: Item) => { .do((item: Item) => {
this.cache.add(item, GlobalConfig.cache.msToLive); 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))); .catch((errorMsg: string) => Observable.of(new ItemFindByIdErrorAction(errorMsg)));
} }
}); });

View File

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

View File

@@ -7,7 +7,7 @@ import {
export interface ItemFindMultipleState { export interface ItemFindMultipleState {
scopeID: string; scopeID: string;
itemsIDs: Array<String>; itemUUIDs: Array<String>;
isLoading: boolean; isLoading: boolean;
errorMessage: string; errorMessage: string;
paginationOptions: PaginationOptions; paginationOptions: PaginationOptions;
@@ -16,7 +16,7 @@ export interface ItemFindMultipleState {
const initialState: ItemFindMultipleState = { const initialState: ItemFindMultipleState = {
scopeID: undefined, scopeID: undefined,
itemsIDs: [], itemUUIDs: [],
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
paginationOptions: undefined, paginationOptions: undefined,
@@ -29,7 +29,7 @@ export const findMultipleReducer = (state = initialState, action: ItemFindMultip
case ItemFindMultipleActionTypes.FIND_MULTI_REQUEST: { case ItemFindMultipleActionTypes.FIND_MULTI_REQUEST: {
return Object.assign({}, state, { return Object.assign({}, state, {
scopeID: action.payload.scopeID, scopeID: action.payload.scopeID,
itemsIDs: [], itemUUIDs: [],
isLoading: true, isLoading: true,
errorMessage: undefined, errorMessage: undefined,
paginationOptions: action.payload.paginationOptions, paginationOptions: action.payload.paginationOptions,
@@ -40,7 +40,7 @@ export const findMultipleReducer = (state = initialState, action: ItemFindMultip
case ItemFindMultipleActionTypes.FIND_MULTI_SUCCESS: { case ItemFindMultipleActionTypes.FIND_MULTI_SUCCESS: {
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: false, isLoading: false,
itemsIDs: action.payload, itemUUIDs: action.payload,
errorMessage: undefined errorMessage: undefined
}); });
} }

View File

@@ -12,8 +12,8 @@ export class ItemFindByIdRequestAction implements Action {
type = ItemFindSingleActionTypes.FIND_BY_ID_REQUEST; type = ItemFindSingleActionTypes.FIND_BY_ID_REQUEST;
payload: string; payload: string;
constructor(id: string) { constructor(requestID: string) {
this.payload = id; this.payload = requestID;
} }
} }
@@ -21,8 +21,8 @@ export class ItemFindByIdSuccessAction implements Action {
type = ItemFindSingleActionTypes.FIND_BY_ID_SUCCESS; type = ItemFindSingleActionTypes.FIND_BY_ID_SUCCESS;
payload: string; payload: string;
constructor(itemID: string) { constructor(itemUUID: string) {
this.payload = itemID; this.payload = itemUUID;
} }
} }

View File

@@ -7,13 +7,15 @@ import {
export interface ItemFindSingleState { export interface ItemFindSingleState {
isLoading: boolean; isLoading: boolean;
errorMessage: string; errorMessage: string;
itemID: string; requestedID: string;
itemUUID: string;
} }
const initialState: ItemFindSingleState = { const initialState: ItemFindSingleState = {
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
itemID: undefined requestedID: undefined,
itemUUID: undefined
}; };
export const findSingleReducer = (state = initialState, action: ItemFindSingleAction): ItemFindSingleState => { export const findSingleReducer = (state = initialState, action: ItemFindSingleAction): ItemFindSingleState => {
@@ -23,7 +25,7 @@ export const findSingleReducer = (state = initialState, action: ItemFindSingleAc
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: true, isLoading: true,
errorMessage: undefined, errorMessage: undefined,
itemID: action.payload requestedID: action.payload
}); });
} }
@@ -31,6 +33,7 @@ export const findSingleReducer = (state = initialState, action: ItemFindSingleAc
return Object.assign({}, state, { return Object.assign({}, state, {
isLoading: false, isLoading: false,
errorMessage: undefined, errorMessage: undefined,
itemUUID: action.payload
}); });
} }