| @@ -0,0 +1,10 @@ | |||||
| export default { | |||||
| CREATE_COURSE: "CREATE_COURSE", | |||||
| UPDATE_COURSE: "UPDATE_COURSE", | |||||
| DELETE_COURSE: "DELETE_COURSE", | |||||
| LOAD_COURSES: "LOAD_COURSES", | |||||
| CREATE_USER: "CREATE_USER", | |||||
| UPDATE_USER: "UPDATE_USER", | |||||
| DELETE_USER: "DELETE_USER", | |||||
| LOAD_USERS: "LOAD_USERS", | |||||
| }; | |||||
| @@ -0,0 +1,33 @@ | |||||
| import dispatcher from "../appDispatcher"; | |||||
| import * as courseApi from "../api/courseApi"; | |||||
| import actionTypes from "./actionTypes"; | |||||
| export function saveCourse(course) { | |||||
| return courseApi.saveCourse(course).then((savedCourse) => { | |||||
| // Hey dispatcher, go tell all the stores that a course was just created. | |||||
| dispatcher.dispatch({ | |||||
| actionType: course.id | |||||
| ? actionTypes.UPDATE_COURSE | |||||
| : actionTypes.CREATE_COURSE, | |||||
| course: savedCourse, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| export function loadCourses() { | |||||
| return courseApi.getCourses().then((courses) => { | |||||
| dispatcher.dispatch({ | |||||
| actionType: actionTypes.LOAD_COURSES, | |||||
| courses: courses, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| export function deleteCourse(id) { | |||||
| return courseApi.deleteCourse(id).then(() => { | |||||
| dispatcher.dispatch({ | |||||
| actionType: actionTypes.DELETE_COURSE, | |||||
| id: id, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| @@ -0,0 +1,31 @@ | |||||
| import dispatcher from "../appDispatcher"; | |||||
| import * as userApi from "../api/userApi"; | |||||
| import actionTypes from "./actionTypes"; | |||||
| export function saveUser(user) { | |||||
| return userApi.saveUser(user).then((savedUser) => { | |||||
| // Hey dispatcher, go tell all the stores that a user was just created. | |||||
| dispatcher.dispatch({ | |||||
| actionType: user.id ? actionTypes.UPDATE_USER : actionTypes.CREATE_USER, | |||||
| user: savedUser, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| export function loadUsers() { | |||||
| return userApi.getUsers().then((users) => { | |||||
| dispatcher.dispatch({ | |||||
| actionType: actionTypes.LOAD_USERS, | |||||
| users: users, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| export function deleteUser(id) { | |||||
| return userApi.deleteUser(id).then(() => { | |||||
| dispatcher.dispatch({ | |||||
| actionType: actionTypes.DELETE_USER, | |||||
| id: id, | |||||
| }); | |||||
| }); | |||||
| } | |||||