-
-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` docker-compose exec client generate-api-platform-client ```
- Loading branch information
Showing
37 changed files
with
2,690 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { SubmissionError } from 'redux-form'; | ||
import { fetch } from '../../utils/dataAccess'; | ||
|
||
export function error(error) { | ||
return { type: 'BOOK_CREATE_ERROR', error }; | ||
} | ||
|
||
export function loading(loading) { | ||
return { type: 'BOOK_CREATE_LOADING', loading }; | ||
} | ||
|
||
export function success(created) { | ||
return { type: 'BOOK_CREATE_SUCCESS', created }; | ||
} | ||
|
||
export function create(values) { | ||
return dispatch => { | ||
dispatch(loading(true)); | ||
|
||
return fetch('/books', { method: 'POST', body: JSON.stringify(values) }) | ||
.then(response => { | ||
dispatch(loading(false)); | ||
|
||
return response.json(); | ||
}) | ||
.then(retrieved => dispatch(success(retrieved))) | ||
.catch(e => { | ||
dispatch(loading(false)); | ||
|
||
if (e instanceof SubmissionError) { | ||
dispatch(error(e.errors._error)); | ||
throw e; | ||
} | ||
|
||
dispatch(error(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function reset() { | ||
return dispatch => { | ||
dispatch(loading(false)); | ||
dispatch(error(null)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { fetch } from '../../utils/dataAccess'; | ||
|
||
export function error(error) { | ||
return { type: 'BOOK_DELETE_ERROR', error }; | ||
} | ||
|
||
export function loading(loading) { | ||
return { type: 'BOOK_DELETE_LOADING', loading }; | ||
} | ||
|
||
export function success(deleted) { | ||
return { type: 'BOOK_DELETE_SUCCESS', deleted }; | ||
} | ||
|
||
export function del(item) { | ||
return dispatch => { | ||
dispatch(loading(true)); | ||
|
||
return fetch(item['@id'], { method: 'DELETE' }) | ||
.then(() => { | ||
dispatch(loading(false)); | ||
dispatch(success(item)); | ||
}) | ||
.catch(e => { | ||
dispatch(loading(false)); | ||
dispatch(error(e.message)); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { | ||
fetch, | ||
normalize, | ||
extractHubURL, | ||
mercureSubscribe as subscribe | ||
} from '../../utils/dataAccess'; | ||
import { success as deleteSuccess } from './delete'; | ||
|
||
export function error(error) { | ||
return { type: 'BOOK_LIST_ERROR', error }; | ||
} | ||
|
||
export function loading(loading) { | ||
return { type: 'BOOK_LIST_LOADING', loading }; | ||
} | ||
|
||
export function success(retrieved) { | ||
return { type: 'BOOK_LIST_SUCCESS', retrieved }; | ||
} | ||
|
||
export function list(page = '/books') { | ||
return dispatch => { | ||
dispatch(loading(true)); | ||
dispatch(error('')); | ||
|
||
fetch(page) | ||
.then(response => | ||
response | ||
.json() | ||
.then(retrieved => ({ retrieved, hubURL: extractHubURL(response) })) | ||
) | ||
.then(({ retrieved, hubURL }) => { | ||
retrieved = normalize(retrieved); | ||
|
||
dispatch(loading(false)); | ||
dispatch(success(retrieved)); | ||
|
||
if (hubURL) | ||
dispatch( | ||
mercureSubscribe( | ||
hubURL, | ||
retrieved['hydra:member'].map(i => i['@id']) | ||
) | ||
); | ||
}) | ||
.catch(e => { | ||
dispatch(loading(false)); | ||
dispatch(error(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function reset(eventSource) { | ||
return dispatch => { | ||
if (eventSource) eventSource.close(); | ||
|
||
dispatch({ type: 'BOOK_LIST_RESET' }); | ||
dispatch(deleteSuccess(null)); | ||
}; | ||
} | ||
|
||
export function mercureSubscribe(hubURL, topics) { | ||
return dispatch => { | ||
const eventSource = subscribe(hubURL, topics); | ||
dispatch(mercureOpen(eventSource)); | ||
eventSource.addEventListener('message', event => | ||
dispatch(mercureMessage(normalize(JSON.parse(event.data)))) | ||
); | ||
}; | ||
} | ||
|
||
export function mercureOpen(eventSource) { | ||
return { type: 'BOOK_LIST_MERCURE_OPEN', eventSource }; | ||
} | ||
|
||
export function mercureMessage(retrieved) { | ||
return dispatch => { | ||
if (1 === Object.keys(retrieved).length) { | ||
dispatch({ type: 'BOOK_LIST_MERCURE_DELETED', retrieved }); | ||
return; | ||
} | ||
|
||
dispatch({ type: 'BOOK_LIST_MERCURE_MESSAGE', retrieved }); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
fetch, | ||
extractHubURL, | ||
normalize, | ||
mercureSubscribe as subscribe | ||
} from '../../utils/dataAccess'; | ||
|
||
export function error(error) { | ||
return { type: 'BOOK_SHOW_ERROR', error }; | ||
} | ||
|
||
export function loading(loading) { | ||
return { type: 'BOOK_SHOW_LOADING', loading }; | ||
} | ||
|
||
export function success(retrieved) { | ||
return { type: 'BOOK_SHOW_SUCCESS', retrieved }; | ||
} | ||
|
||
export function retrieve(id) { | ||
return dispatch => { | ||
dispatch(loading(true)); | ||
|
||
return fetch(id) | ||
.then(response => | ||
response | ||
.json() | ||
.then(retrieved => ({ retrieved, hubURL: extractHubURL(response) })) | ||
) | ||
.then(({ retrieved, hubURL }) => { | ||
retrieved = normalize(retrieved); | ||
|
||
dispatch(loading(false)); | ||
dispatch(success(retrieved)); | ||
|
||
if (hubURL) dispatch(mercureSubscribe(hubURL, retrieved['@id'])); | ||
}) | ||
.catch(e => { | ||
dispatch(loading(false)); | ||
dispatch(error(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function reset(eventSource) { | ||
return dispatch => { | ||
if (eventSource) eventSource.close(); | ||
|
||
dispatch({ type: 'BOOK_SHOW_RESET' }); | ||
dispatch(error(null)); | ||
dispatch(loading(false)); | ||
}; | ||
} | ||
|
||
export function mercureSubscribe(hubURL, topic) { | ||
return dispatch => { | ||
const eventSource = subscribe(hubURL, [topic]); | ||
dispatch(mercureOpen(eventSource)); | ||
eventSource.addEventListener('message', event => | ||
dispatch(mercureMessage(normalize(JSON.parse(event.data)))) | ||
); | ||
}; | ||
} | ||
|
||
export function mercureOpen(eventSource) { | ||
return { type: 'BOOK_SHOW_MERCURE_OPEN', eventSource }; | ||
} | ||
|
||
export function mercureMessage(retrieved) { | ||
return dispatch => { | ||
if (1 === Object.keys(retrieved).length) { | ||
dispatch({ type: 'BOOK_SHOW_MERCURE_DELETED', retrieved }); | ||
return; | ||
} | ||
|
||
dispatch({ type: 'BOOK_SHOW_MERCURE_MESSAGE', retrieved }); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { SubmissionError } from 'redux-form'; | ||
import { | ||
fetch, | ||
extractHubURL, | ||
normalize, | ||
mercureSubscribe as subscribe | ||
} from '../../utils/dataAccess'; | ||
import { success as createSuccess } from './create'; | ||
import { loading, error } from './delete'; | ||
|
||
export function retrieveError(retrieveError) { | ||
return { type: 'BOOK_UPDATE_RETRIEVE_ERROR', retrieveError }; | ||
} | ||
|
||
export function retrieveLoading(retrieveLoading) { | ||
return { type: 'BOOK_UPDATE_RETRIEVE_LOADING', retrieveLoading }; | ||
} | ||
|
||
export function retrieveSuccess(retrieved) { | ||
return { type: 'BOOK_UPDATE_RETRIEVE_SUCCESS', retrieved }; | ||
} | ||
|
||
export function retrieve(id) { | ||
return dispatch => { | ||
dispatch(retrieveLoading(true)); | ||
|
||
return fetch(id) | ||
.then(response => | ||
response | ||
.json() | ||
.then(retrieved => ({ retrieved, hubURL: extractHubURL(response) })) | ||
) | ||
.then(({ retrieved, hubURL }) => { | ||
retrieved = normalize(retrieved); | ||
|
||
dispatch(retrieveLoading(false)); | ||
dispatch(retrieveSuccess(retrieved)); | ||
|
||
if (hubURL) dispatch(mercureSubscribe(hubURL, retrieved['@id'])); | ||
}) | ||
.catch(e => { | ||
dispatch(retrieveLoading(false)); | ||
dispatch(retrieveError(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function updateError(updateError) { | ||
return { type: 'BOOK_UPDATE_UPDATE_ERROR', updateError }; | ||
} | ||
|
||
export function updateLoading(updateLoading) { | ||
return { type: 'BOOK_UPDATE_UPDATE_LOADING', updateLoading }; | ||
} | ||
|
||
export function updateSuccess(updated) { | ||
return { type: 'BOOK_UPDATE_UPDATE_SUCCESS', updated }; | ||
} | ||
|
||
export function update(item, values) { | ||
return dispatch => { | ||
dispatch(updateError(null)); | ||
dispatch(createSuccess(null)); | ||
dispatch(updateLoading(true)); | ||
|
||
return fetch(item['@id'], { | ||
method: 'PUT', | ||
headers: new Headers({ 'Content-Type': 'application/ld+json' }), | ||
body: JSON.stringify(values) | ||
}) | ||
.then(response => | ||
response | ||
.json() | ||
.then(retrieved => ({ retrieved, hubURL: extractHubURL(response) })) | ||
) | ||
.then(({ retrieved, hubURL }) => { | ||
retrieved = normalize(retrieved); | ||
|
||
dispatch(updateLoading(false)); | ||
dispatch(updateSuccess(retrieved)); | ||
|
||
if (hubURL) dispatch(mercureSubscribe(hubURL, retrieved['@id'])); | ||
}) | ||
.catch(e => { | ||
dispatch(updateLoading(false)); | ||
|
||
if (e instanceof SubmissionError) { | ||
dispatch(updateError(e.errors._error)); | ||
throw e; | ||
} | ||
|
||
dispatch(updateError(e.message)); | ||
}); | ||
}; | ||
} | ||
|
||
export function reset(eventSource) { | ||
return dispatch => { | ||
if (eventSource) eventSource.close(); | ||
|
||
dispatch({ type: 'BOOK_UPDATE_RESET' }); | ||
dispatch(error(null)); | ||
dispatch(loading(false)); | ||
dispatch(createSuccess(null)); | ||
}; | ||
} | ||
|
||
export function mercureSubscribe(hubURL, topic) { | ||
return dispatch => { | ||
const eventSource = subscribe(hubURL, [topic]); | ||
dispatch(mercureOpen(eventSource)); | ||
eventSource.addEventListener('message', event => | ||
dispatch(mercureMessage(normalize(JSON.parse(event.data)))) | ||
); | ||
}; | ||
} | ||
|
||
export function mercureOpen(eventSource) { | ||
return { type: 'BOOK_UPDATE_MERCURE_OPEN', eventSource }; | ||
} | ||
|
||
export function mercureMessage(retrieved) { | ||
return dispatch => { | ||
if (1 === Object.keys(retrieved).length) { | ||
dispatch({ type: 'BOOK_UPDATE_MERCURE_DELETED', retrieved }); | ||
return; | ||
} | ||
|
||
dispatch({ type: 'BOOK_UPDATE_MERCURE_MESSAGE', retrieved }); | ||
}; | ||
} |
Oops, something went wrong.