generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #862 from ita-social-projects/matvienko-856-Create…
…-HomeworkStudent-model add homeworkStudent model
- Loading branch information
Showing
11 changed files
with
366 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,152 @@ | ||
import { | ||
all, | ||
fork, | ||
put, | ||
call, | ||
takeLatest, | ||
takeEvery, | ||
} from 'redux-saga/effects'; | ||
import { ApiService } from '../../shared/api-service'; | ||
import * as actionTypes from './types'; | ||
|
||
export const addHomeworkStudent = (homeworkStudent) => ({ | ||
type: actionTypes.ADD_HOMEWORK_STUDENT, | ||
payload: { | ||
homeworkStudent, | ||
}, | ||
}); | ||
|
||
export const getHomeworkStudent = () => ({ | ||
type: actionTypes.GET_HOMEWORK_STUDENT, | ||
payload: { | ||
}, | ||
}); | ||
|
||
export const getHomeworkByIdStudent = (id) => ({ | ||
type: actionTypes.GET_HOMEWORK_STUDENT_BY_ID, | ||
payload: { | ||
id, | ||
}, | ||
}); | ||
|
||
export const updateHomeworkStudent = (id, homeworkStudent) => ({ | ||
type: actionTypes.UPDATE_HOMEWORK_STUDENT, | ||
payload: { | ||
id, | ||
homeworkStudent | ||
}, | ||
}); | ||
|
||
function* addHomeworkStudentWorker(data) { | ||
try { | ||
yield put({ type: actionTypes.ADDING_HOMEWORK_STUDENT_STARTED }); | ||
const homeworkStudent = yield call( | ||
ApiService.create, | ||
'/homeworkstudent', | ||
data.payload.homeworkStudent | ||
); | ||
|
||
yield put({ | ||
type: actionTypes.ADDING_HOMEWORK_STUDENT_SUCCESS, | ||
payload: { homeworkStudent }, | ||
}); | ||
|
||
yield put({ type: actionTypes.CLEAR_LOADED }); | ||
} catch (error) { | ||
yield put({ | ||
type: actionTypes.ADDING_HOMEWORK_STUDENT_FAILED, | ||
payload: { error }, | ||
}); | ||
|
||
yield put({ type: actionTypes.CLEAR_ERROR }); | ||
} | ||
} | ||
|
||
function* getHomeworkStudentWorker() { | ||
try { | ||
yield put({ type: actionTypes.LOADING_HOMEWORK_STUDENT_STARTED }); | ||
|
||
const homeworkStudent = yield call( | ||
ApiService.load, | ||
`/homeworkstudent` | ||
); | ||
|
||
yield put({ | ||
type: actionTypes.LOADING_HOMEWORK_STUDENT_SUCCESS, | ||
payload: { homeworkStudent }, | ||
}); | ||
} catch (error) { | ||
yield put({ | ||
type: actionTypes.LOADING_HOMEWORK_STUDENT_FAILED, | ||
payload: { error }, | ||
}); | ||
} | ||
} | ||
|
||
function* getHomeworkStudentByIdWorker(data) { | ||
try { | ||
yield put({ type: actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_STARTED }); | ||
|
||
const homeworkStudent = yield call( | ||
ApiService.load, | ||
`/homeworkstudent/${data.payload.id}` | ||
); | ||
|
||
yield put({ | ||
type: actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_SUCCESS, | ||
payload: { homeworkStudent }, | ||
}); | ||
} catch (error) { | ||
yield put({ | ||
type: actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_FAILED, | ||
payload: { error }, | ||
}); | ||
} | ||
} | ||
|
||
function* updateHomeworkStudentWorker(data) { | ||
try { | ||
yield put({ type: actionTypes.UPDATING_HOMEWORK_STUDENT_STARTED }); | ||
|
||
const homeworkStudent = yield call( | ||
ApiService.update, | ||
`/homeworkstudent/${data.payload.id}`, | ||
data.payload.homeworkStudent | ||
); | ||
|
||
yield put({ | ||
type: actionTypes.UPDATING_HOMEWORK_STUDENT_SUCCESS, | ||
payload: { homeworkStudent }, | ||
}); | ||
} catch (error) { | ||
yield put({ | ||
type: actionTypes.UPDATING_HOMEWORK_STUDENT_FAILED, | ||
payload: { error }, | ||
}); | ||
} | ||
} | ||
|
||
function* getHomeworkStudentWatcher() { | ||
yield takeLatest(actionTypes.GET_HOMEWORK_STUDENT, getHomeworkStudentWorker); | ||
} | ||
|
||
function* getHomeworkStudentByIdWatcher() { | ||
yield takeLatest(actionTypes.GET_HOMEWORK_STUDENT_BY_ID, getHomeworkStudentByIdWorker); | ||
} | ||
|
||
function* addHomeworkStudentWatcher() { | ||
yield takeEvery(actionTypes.ADD_HOMEWORK_STUDENT, addHomeworkStudentWorker); | ||
} | ||
|
||
function* updateHomeworkStudentWatcher() { | ||
yield takeEvery(actionTypes.UPDATE_HOMEWORK_STUDENT, updateHomeworkStudentWorker); | ||
} | ||
|
||
export function* homeworkStudentWatcher() { | ||
yield all([ | ||
fork(getHomeworkStudentWatcher), | ||
fork(getHomeworkStudentByIdWatcher), | ||
fork(addHomeworkStudentWatcher), | ||
fork(updateHomeworkStudentWatcher), | ||
]); | ||
} |
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,8 @@ | ||
export { homeworkStudentReducer } from './reducer.js'; | ||
export { getHomeworkStudent, getHomeworkByIdStudent, addHomeworkStudent, updateHomeworkStudent } from './actions.js'; | ||
export { | ||
homeworkStudentSelector, | ||
homeworkByIdStudentSelector, | ||
addedHomeworkStudentSelector, | ||
updatedHomeworkStudentSelector, | ||
} from './selectors.js'; |
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,15 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
import { | ||
addHomeworkStudentReducer, | ||
updateHomeworkStudentReducer, | ||
getHomeworkStudentReducer, | ||
getHomeworkByIdStudentReducer, | ||
} from './reducers'; | ||
|
||
export const homeworkStudentReducer = combineReducers({ | ||
homeworkStudent: getHomeworkStudentReducer, | ||
homeworkByIdStudent: getHomeworkByIdStudentReducer, | ||
updatedHomeworkStudent: updateHomeworkStudentReducer, | ||
addedHomeworkStudent: addHomeworkStudentReducer, | ||
}); |
46 changes: 46 additions & 0 deletions
46
src/models/homework-student/reducers/add-homework-student-reducer.js
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,46 @@ | ||
import * as actionTypes from '../types'; | ||
|
||
const INITIAL_STATE = { | ||
data: {}, | ||
isLoading: false, | ||
loaded: false, | ||
error: '', | ||
}; | ||
|
||
export const addHomeworkStudentReducer = (state = INITIAL_STATE, action) => { | ||
switch (action.type) { | ||
case actionTypes.ADDING_HOMEWORK_STUDENT_STARTED: | ||
return { | ||
...state, | ||
isLoading: true, | ||
error: '', | ||
}; | ||
case actionTypes.ADDING_HOMEWORK_STUDENT_SUCCESS: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: true, | ||
data: action.payload.homeworkStudent, | ||
error: '', | ||
}; | ||
case actionTypes.ADDING_HOMEWORK_STUDENT_FAILED: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: false, | ||
error: action.payload.error, | ||
}; | ||
case actionTypes.CLEAR_LOADED: | ||
return { | ||
...state, | ||
loaded: false, | ||
}; | ||
case actionTypes.CLEAR_ERROR: | ||
return { | ||
...state, | ||
error: '', | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/models/homework-student/reducers/get-by-id-homework-student-reducer.js
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,36 @@ | ||
import * as actionTypes from '../types'; | ||
|
||
const INITIAL_STATE = { | ||
data: {}, | ||
isLoading: false, | ||
loaded: false, | ||
error: '', | ||
}; | ||
|
||
export const getHomeworkByIdStudentReducer = (state = INITIAL_STATE, action) => { | ||
switch (action.type) { | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_STARTED: | ||
return { | ||
...state, | ||
isLoading: true, | ||
error: '', | ||
}; | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_SUCCESS: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: true, | ||
data: action.payload.homeworkStudent, | ||
error: '', | ||
}; | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_BY_ID_FAILED: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: false, | ||
error: action.payload.error, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/models/homework-student/reducers/get-homework-student-reducer.js
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,36 @@ | ||
import * as actionTypes from '../types'; | ||
|
||
const INITIAL_STATE = { | ||
data: {}, | ||
isLoading: false, | ||
loaded: false, | ||
error: '', | ||
}; | ||
|
||
export const getHomeworkStudentReducer = (state = INITIAL_STATE, action) => { | ||
switch (action.type) { | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_STARTED: | ||
return { | ||
...state, | ||
isLoading: true, | ||
error: '', | ||
}; | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_SUCCESS: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: true, | ||
data: action.payload.homeworkStudent, | ||
error: '', | ||
}; | ||
case actionTypes.LOADING_HOMEWORK_STUDENT_FAILED: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: false, | ||
error: action.payload.error, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
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,4 @@ | ||
export { addHomeworkStudentReducer } from './add-homework-student-reducer'; | ||
export { getHomeworkStudentReducer } from './get-homework-student-reducer'; | ||
export { getHomeworkByIdStudentReducer } from './get-by-id-homework-student-reducer'; | ||
export { updateHomeworkStudentReducer } from './update-homework-student-reducer'; |
36 changes: 36 additions & 0 deletions
36
src/models/homework-student/reducers/update-homework-student-reducer.js
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,36 @@ | ||
import * as actionTypes from '../types'; | ||
|
||
const INITIAL_STATE = { | ||
data: {}, | ||
isLoading: false, | ||
loaded: false, | ||
error: '', | ||
}; | ||
|
||
export const updateHomeworkStudentReducer = (state = INITIAL_STATE, action) => { | ||
switch (action.type) { | ||
case actionTypes.UPDATING_HOMEWORK_STUDENT_STARTED: | ||
return { | ||
...state, | ||
isLoading: true, | ||
error: '', | ||
}; | ||
case actionTypes.UPDATING_HOMEWORK_STUDENT_SUCCESS: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: true, | ||
data: action.payload.homeworkStudent, | ||
error: '', | ||
}; | ||
case actionTypes.UPDATING_HOMEWORK_STUDENT_FAILED: | ||
return { | ||
...state, | ||
isLoading: false, | ||
loaded: false, | ||
error: action.payload.error, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
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,8 @@ | ||
export const homeworkStudentSelector = (state) => | ||
state.models.homework.homeworkStudent; | ||
export const homeworkByIdStudentSelector = (state) => | ||
state.models.homework.homeworkStudent; | ||
export const updatedHomeworkStudentSelector = (state) => | ||
state.models.homework.updatedHomeworkStudent; | ||
export const addedHomeworkStudentSelector = (state) => | ||
state.models.homework.addedHomeworkStudent; |
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,23 @@ | ||
export const ADD_HOMEWORK_STUDENT = 'HOMEWORK/ADD_HOMEWORK_STUDENT'; | ||
export const UPDATE_HOMEWORK_STUDENT = 'HOMEWORK/UPDATE_HOMEWORK_STUDENT'; | ||
export const GET_HOMEWORK_STUDENT = 'HOMEWORK/GET_HOMEWORK_STUDENT'; | ||
export const GET_HOMEWORK_STUDENT_BY_ID = 'HOMEWORK/GET_HOMEWORK_STUDENT_BY_ID'; | ||
|
||
export const ADDING_HOMEWORK_STUDENT_STARTED = 'HOMEWORK/ADDING_HOMEWORK_STUDENT_STARTED'; | ||
export const ADDING_HOMEWORK_STUDENT_SUCCESS = 'HOMEWORK/ADDING_HOMEWORK_STUDENT_SUCCESS'; | ||
export const ADDING_HOMEWORK_STUDENT_FAILED = 'HOMEWORK/ADDING_HOMEWORK_STUDENT_FAILED'; | ||
|
||
export const LOADING_HOMEWORK_STUDENT_STARTED = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_STARTED'; | ||
export const LOADING_HOMEWORK_STUDENT_SUCCESS = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_SUCCESS'; | ||
export const LOADING_HOMEWORK_STUDENT_FAILED = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_FAILED'; | ||
|
||
export const LOADING_HOMEWORK_STUDENT_BY_ID_STARTED = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_BY_ID_STARTED'; | ||
export const LOADING_HOMEWORK_STUDENT_BY_ID_SUCCESS = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_BY_ID_SUCCESS'; | ||
export const LOADING_HOMEWORK_STUDENT_BY_ID_FAILED = 'HOMEWORK/LOADING_HOMEWORK_STUDENT_BY_ID_FAILED'; | ||
|
||
export const UPDATING_HOMEWORK_STUDENT_STARTED = 'HOMEWORK/UPDATING_HOMEWORK_STUDENT_STARTED'; | ||
export const UPDATING_HOMEWORK_STUDENT_SUCCESS = 'HOMEWORK/UPDATING_HOMEWORK_STUDENT_SUCCESS'; | ||
export const UPDATING_HOMEWORK_STUDENT_FAILED = 'HOMEWORK/UPDATING_HOMEWORK_STUDENT_FAILED'; | ||
|
||
export const CLEAR_LOADED = 'HOMEWORK_STUDENT/CLEAR_LOADED'; | ||
export const CLEAR_ERROR = 'HOMEWORK_STUDENT/CLEAR_ERROR'; |
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