56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
export default function() {
|
|
this.namespace = '/api';
|
|
|
|
let items = [{
|
|
type: 'items',
|
|
id: 'grand-old-mansion',
|
|
attributes: {
|
|
title: 'Grand Old Mansion',
|
|
owner: 'Veruca Salt',
|
|
city: 'San Francisco',
|
|
type: 'Estate',
|
|
bedrooms: 15,
|
|
image: 'https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg',
|
|
description: "This grand old mansion sits on over 100 acres of rolling hills and dense redwood forests."
|
|
}
|
|
}, {
|
|
type: 'items',
|
|
id: 'urban-living',
|
|
attributes: {
|
|
title: 'Urban Living',
|
|
owner: 'Mike Teavee',
|
|
city: 'Seattle',
|
|
type: 'Condo',
|
|
bedrooms: 1,
|
|
image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Alfonso_13_Highrise_Tegucigalpa.jpg',
|
|
description: "A commuters dream. This rental is within walking distance of 2 bus stops and the Metro."
|
|
}
|
|
}, {
|
|
type: 'items',
|
|
id: 'downtown-charm',
|
|
attributes: {
|
|
title: 'Downtown Charm',
|
|
owner: 'Violet Beauregarde',
|
|
city: 'Portland',
|
|
type: 'Apartment',
|
|
bedrooms: 3,
|
|
image: 'https://upload.wikimedia.org/wikipedia/commons/f/f7/Wheeldon_Apartment_Building_-_Portland_Oregon.jpg',
|
|
description: "Convenience is at your doorstep with this charming downtown rental. Great restaurants and active night life are within a few feet."
|
|
}
|
|
}];
|
|
|
|
this.get('/items', function(db, request) {
|
|
if(request.queryParams.name !== undefined) {
|
|
let filteredItems = items.filter(function(i) {
|
|
return i.attributes.title.toLowerCase().indexOf(request.queryParams.name.toLowerCase()) !== -1;
|
|
});
|
|
return { data: filteredItems };
|
|
} else {
|
|
return { data: items };
|
|
}
|
|
});
|
|
|
|
this.get('/items/:id', function (db, request) {
|
|
return { data: items.find((item) => request.params.id === item.id) };
|
|
});
|
|
}
|