s/restaurants/suggestions/
This commit is contained in:
@ -1,40 +1,40 @@
|
||||
var RestaurantConstants = require('../constants/RestaurantConstants');
|
||||
var SuggestionConstants = require('../constants/SuggestionConstants');
|
||||
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
|
||||
var models = require('../models.js');
|
||||
var Restaurant = models.Restaurant;
|
||||
var Suggestion = models.Suggestion;
|
||||
var Error = models.Error;
|
||||
|
||||
function fetchRestaurants() {
|
||||
function fetchSuggestions() {
|
||||
return {
|
||||
type: RestaurantConstants.FETCH_RESTAURANTS
|
||||
type: SuggestionConstants.FETCH_SUGGESTIONS
|
||||
}
|
||||
}
|
||||
|
||||
function restaurantsFetched(restaurants) {
|
||||
return {
|
||||
type: RestaurantConstants.RESTAURANTS_FETCHED,
|
||||
type: SuggestionConstants.SUGGESTIONS_FETCHED,
|
||||
restaurants: restaurants
|
||||
}
|
||||
}
|
||||
|
||||
function createRestaurant() {
|
||||
function createSuggestion() {
|
||||
return {
|
||||
type: RestaurantConstants.CREATE_RESTAURANT
|
||||
type: SuggestionConstants.CREATE_SUGGESTION
|
||||
}
|
||||
}
|
||||
|
||||
function restaurantCreated(restaurant) {
|
||||
return {
|
||||
type: RestaurantConstants.RESTAURANT_CREATED,
|
||||
type: SuggestionConstants.SUGGESTION_CREATED,
|
||||
restaurant: restaurant
|
||||
}
|
||||
}
|
||||
|
||||
function fetchAll() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchRestaurants());
|
||||
dispatch(fetchSuggestions());
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
@ -47,7 +47,7 @@ function fetchAll() {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
dispatch(restaurantsFetched(data.restaurants.map(function(json) {
|
||||
var a = new Restaurant();
|
||||
var a = new Suggestion();
|
||||
a.fromJSON(json);
|
||||
return a;
|
||||
})));
|
||||
@ -62,7 +62,7 @@ function fetchAll() {
|
||||
|
||||
function create(restaurant) {
|
||||
return function (dispatch) {
|
||||
dispatch(createRestaurant());
|
||||
dispatch(createSuggestion());
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
@ -75,7 +75,7 @@ function create(restaurant) {
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
var a = new Restaurant();
|
||||
var a = new Suggestion();
|
||||
a.fromJSON(data);
|
||||
dispatch(restaurantCreated(a));
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
var UserConstants = require('../constants/UserConstants');
|
||||
|
||||
var AttendeeActions = require('./AttendeeActions');
|
||||
var RestaurantActions = require('./RestaurantActions');
|
||||
var SuggestionActions = require('./SuggestionActions');
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
|
||||
var models = require('../models.js');
|
||||
@ -92,7 +92,7 @@ function initializeSession(dispatch, session) {
|
||||
dispatch(userLoggedIn(session));
|
||||
dispatch(fetch(session.UserId));
|
||||
dispatch(AttendeeActions.fetchAll());
|
||||
dispatch(RestaurantActions.fetchAll());
|
||||
dispatch(SuggestionActions.fetchAll());
|
||||
}
|
||||
|
||||
function login(user) {
|
||||
|
@ -1,8 +0,0 @@
|
||||
var keyMirror = require('keymirror');
|
||||
|
||||
module.exports = keyMirror({
|
||||
FETCH_RESTAURANTS: null,
|
||||
RESTAURANTS_FETCHED: null,
|
||||
CREATE_RESTAURANT: null,
|
||||
RESTAURANT_CREATED: null
|
||||
});
|
8
js/constants/SuggestionConstants.js
Normal file
8
js/constants/SuggestionConstants.js
Normal file
@ -0,0 +1,8 @@
|
||||
var keyMirror = require('keymirror');
|
||||
|
||||
module.exports = keyMirror({
|
||||
FETCH_SUGGESTIONS: null,
|
||||
SUGGESTIONS_FETCHED: null,
|
||||
CREATE_SUGGESTION: null,
|
||||
SUGGESTION_CREATED: null
|
||||
});
|
36
js/models.js
36
js/models.js
@ -101,31 +101,37 @@ Attendee.prototype.isAttendee = function() {
|
||||
this.Name != empty_attendee.Name;
|
||||
}
|
||||
|
||||
function Restaurant() {
|
||||
this.RestaurantId = -1;
|
||||
this.Name = "";
|
||||
function Suggestion() {
|
||||
this.SuggestionId = -1;
|
||||
this.VetoingId = -1;
|
||||
this.AttendeeId = -1;
|
||||
this.RestaurantName = "";
|
||||
}
|
||||
|
||||
Restaurant.prototype.toJSON = function() {
|
||||
Suggestion.prototype.toJSON = function() {
|
||||
var json_obj = {};
|
||||
json_obj.RestaurantId = this.RestaurantId;
|
||||
json_obj.Name = this.Name;
|
||||
json_obj.SuggestionId = this.SuggestionId;
|
||||
json_obj.AttendeeId = this.AttendeeId;
|
||||
json_obj.RestaurantName = this.RestaurantName;
|
||||
return JSON.stringify(json_obj);
|
||||
}
|
||||
|
||||
Restaurant.prototype.fromJSON = function(json_input) {
|
||||
Suggestion.prototype.fromJSON = function(json_input) {
|
||||
var json_obj = getJSONObj(json_input);
|
||||
|
||||
if (json_obj.hasOwnProperty("RestaurantId"))
|
||||
this.RestaurantId = json_obj.RestaurantId;
|
||||
if (json_obj.hasOwnProperty("Name"))
|
||||
this.Name = json_obj.Name;
|
||||
if (json_obj.hasOwnProperty("SuggestionId"))
|
||||
this.SuggestionId = json_obj.SuggestionId;
|
||||
if (json_obj.hasOwnProperty("AttendeeId"))
|
||||
this.AttendeeId = json_obj.AttendeeId;
|
||||
if (json_obj.hasOwnProperty("RestaurantName"))
|
||||
this.RestaurantName = json_obj.RestaurantName;
|
||||
}
|
||||
|
||||
Restaurant.prototype.isRestaurant = function() {
|
||||
var empty_attendee = new Restaurant();
|
||||
return this.RestaurantId != empty_attendee.RestaurantId ||
|
||||
this.Name != empty_attendee.Name;
|
||||
Suggestion.prototype.isSuggestion = function() {
|
||||
var empty_suggestion = new Suggestion();
|
||||
return this.SuggestionId != empty_suggestion.SuggestionId &&
|
||||
this.AttendeeId != empty_suggestion.AttendeeId &&
|
||||
this.RestaurantName != empty_suggestion.RestaurantName;
|
||||
}
|
||||
|
||||
function Error() {
|
||||
|
@ -3,13 +3,13 @@ var Redux = require('redux');
|
||||
var UserReducer = require('./UserReducer');
|
||||
var SessionReducer = require('./SessionReducer');
|
||||
var AttendeeReducer = require('./AttendeeReducer');
|
||||
var RestaurantReducer = require('./RestaurantReducer');
|
||||
var SuggestionReducer = require('./SuggestionReducer');
|
||||
var ErrorReducer = require('./ErrorReducer');
|
||||
|
||||
module.exports = Redux.combineReducers({
|
||||
user: UserReducer,
|
||||
session: SessionReducer,
|
||||
attendees: AttendeeReducer,
|
||||
restaurants: RestaurantReducer,
|
||||
suggestions: SuggestionReducer,
|
||||
error: ErrorReducer
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
var assign = require('object-assign');
|
||||
|
||||
var RestaurantConstants = require('../constants/RestaurantConstants');
|
||||
var UserConstants = require('../constants/UserConstants');
|
||||
|
||||
module.exports = function(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case RestaurantConstants.RESTAURANTS_FETCHED:
|
||||
var restaurants = {};
|
||||
for (var i = 0; i < action.restaurants.length; i++) {
|
||||
var restaurant = action.restaurants[i];
|
||||
restaurants[restaurant.RestaurantId] = restaurant;
|
||||
}
|
||||
return restaurants;
|
||||
case RestaurantConstants.RESTAURANT_CREATED:
|
||||
var restaurant = action.restaurant;
|
||||
var restaurants = assign({}, state, {
|
||||
[restaurant.RestaurantId]: restaurant
|
||||
});
|
||||
return restaurants;
|
||||
case UserConstants.USER_LOGGEDOUT:
|
||||
return {};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
26
js/reducers/SuggestionReducer.js
Normal file
26
js/reducers/SuggestionReducer.js
Normal file
@ -0,0 +1,26 @@
|
||||
var assign = require('object-assign');
|
||||
|
||||
var SuggestionConstants = require('../constants/SuggestionConstants');
|
||||
var UserConstants = require('../constants/UserConstants');
|
||||
|
||||
module.exports = function(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case SuggestionConstants.SUGGESTIONS_FETCHED:
|
||||
var suggestions = {};
|
||||
for (var i = 0; i < action.suggestions.length; i++) {
|
||||
var suggestion = action.suggestions[i];
|
||||
suggestions[suggestion.SuggestionId] = suggestion;
|
||||
}
|
||||
return suggestions;
|
||||
case SuggestionConstants.SUGGESTION_CREATED:
|
||||
var suggestion = action.suggestion;
|
||||
var suggestions = assign({}, state, {
|
||||
[suggestion.SuggestionId]: suggestion
|
||||
});
|
||||
return suggestions;
|
||||
case UserConstants.USER_LOGGEDOUT:
|
||||
return {};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user