Add attendees and suggestions (except for UI)
This commit is contained in:
@ -32,6 +32,19 @@ function attendeeCreated(attendee) {
|
||||
}
|
||||
}
|
||||
|
||||
function fetchPopularAttendees() {
|
||||
return {
|
||||
type: AttendeeConstants.FETCH_POPULAR_ATTENDEES
|
||||
}
|
||||
}
|
||||
|
||||
function popularAttendeesFetched(attendees) {
|
||||
return {
|
||||
type: AttendeeConstants.POPULAR_ATTENDEES_FETCHED,
|
||||
attendees: attendees
|
||||
}
|
||||
}
|
||||
|
||||
function fetchAll() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchAttendees());
|
||||
@ -87,7 +100,36 @@ function create(attendee) {
|
||||
};
|
||||
}
|
||||
|
||||
function fetchPopular() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchPopularAttendees());
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "popularattendees/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
ErrorActions.serverError(e);
|
||||
} else {
|
||||
dispatch(popularAttendeesFetched(data.attendees.map(function(json) {
|
||||
var a = new Attendee();
|
||||
a.fromJSON(json);
|
||||
return a;
|
||||
})));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
ErrorActions.ajaxError(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchAll: fetchAll,
|
||||
create: create
|
||||
create: create,
|
||||
fetchPopular: fetchPopular
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -93,6 +93,8 @@ function initializeSession(dispatch, session) {
|
||||
dispatch(fetch(session.UserId));
|
||||
dispatch(AttendeeActions.fetchAll());
|
||||
dispatch(SuggestionActions.fetchAll());
|
||||
dispatch(AttendeeActions.fetchPopular());
|
||||
dispatch(SuggestionActions.fetchPopular());
|
||||
}
|
||||
|
||||
function login(user) {
|
||||
|
Reference in New Issue
Block a user