Add attendees and suggestions (except for UI)
This commit is contained in:
@ -12,10 +12,10 @@ function fetchSuggestions() {
|
||||
}
|
||||
}
|
||||
|
||||
function restaurantsFetched(restaurants) {
|
||||
function suggestionsFetched(suggestions) {
|
||||
return {
|
||||
type: SuggestionConstants.SUGGESTIONS_FETCHED,
|
||||
restaurants: restaurants
|
||||
suggestions: suggestions
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,10 +25,23 @@ function createSuggestion() {
|
||||
}
|
||||
}
|
||||
|
||||
function restaurantCreated(restaurant) {
|
||||
function suggestionCreated(suggestion) {
|
||||
return {
|
||||
type: SuggestionConstants.SUGGESTION_CREATED,
|
||||
restaurant: restaurant
|
||||
suggestion: suggestion
|
||||
}
|
||||
}
|
||||
|
||||
function fetchPopularSuggestions() {
|
||||
return {
|
||||
type: SuggestionConstants.FETCH_POPULAR_SUGGESTIONS
|
||||
}
|
||||
}
|
||||
|
||||
function popularSuggestionsFetched(suggestions) {
|
||||
return {
|
||||
type: SuggestionConstants.POPULAR_SUGGESTIONS_FETCHED,
|
||||
suggestions: suggestions
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,14 +52,14 @@ function fetchAll() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "restaurant/",
|
||||
url: "suggestion/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
dispatch(restaurantsFetched(data.restaurants.map(function(json) {
|
||||
dispatch(suggestionsFetched(data.suggestions.map(function(json) {
|
||||
var a = new Suggestion();
|
||||
a.fromJSON(json);
|
||||
return a;
|
||||
@ -60,15 +73,15 @@ function fetchAll() {
|
||||
};
|
||||
}
|
||||
|
||||
function create(restaurant) {
|
||||
function create(suggestion) {
|
||||
return function (dispatch) {
|
||||
dispatch(createSuggestion());
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
url: "restaurant/",
|
||||
data: {restaurant: restaurant.toJSON()},
|
||||
url: "suggestion/",
|
||||
data: {suggestion: suggestion.toJSON()},
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
@ -77,7 +90,35 @@ function create(restaurant) {
|
||||
} else {
|
||||
var a = new Suggestion();
|
||||
a.fromJSON(data);
|
||||
dispatch(restaurantCreated(a));
|
||||
dispatch(suggestionCreated(a));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function fetchPopular() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchPopularSuggestions());
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "popularsuggestions/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
dispatch(popularSuggestionsFetched(data.suggestions.map(function(json) {
|
||||
var a = new Suggestion();
|
||||
a.fromJSON(json);
|
||||
return a;
|
||||
})));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
@ -89,5 +130,6 @@ function create(restaurant) {
|
||||
|
||||
module.exports = {
|
||||
fetchAll: fetchAll,
|
||||
create: create
|
||||
create: create,
|
||||
fetchPopular: fetchPopular
|
||||
};
|
||||
|
Reference in New Issue
Block a user