Created
May 7, 2020 14:45
-
-
Save alexdiliberto/378a41b728ba6c95777d6041151697f3 to your computer and use it in GitHub Desktop.
REST Adapter With Sideloading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import DS from 'ember-data'; | |
| export default DS.RESTAdapter.extend({ | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function() { | |
| window.server = this; | |
| this.get('/cartItems', function (schema, request) { | |
| return { | |
| "cart-items": [ | |
| { | |
| "cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3", | |
| "id": "ROVE949352B", | |
| "personalization": [], | |
| "prices": { | |
| "price": 74.95, | |
| "totalPrice": 74.95 | |
| }, | |
| "product": 4464, | |
| "quantity": 1, | |
| "skuid": "ROVE949352B", | |
| "variantCodes": [], | |
| "variantData": [] | |
| }, | |
| { | |
| "cart": "0048f8cc-ef50-11e7-8337-76502ffc62f3", | |
| "id": "BLK4226", | |
| "personalization": [], | |
| "prices": { | |
| "origprice": 0, | |
| "price": 60, | |
| "totalPrice": 60 | |
| }, | |
| "product": 4502, | |
| "quantity": 1, | |
| "skuid": "BLK4226", | |
| "variantCodes": [], | |
| "variantData": [] | |
| } | |
| ], | |
| "products": [ | |
| { | |
| "id": 4464, | |
| "images": { | |
| "image": "tristan-irish-watch.jpg", | |
| }, | |
| "name": "Watch - Gold Plated Watch", | |
| "prices": { | |
| "price": 74.95 | |
| }, | |
| "skuid": "ROVE949352B" | |
| }, | |
| { | |
| "id": 4502, | |
| "images": { | |
| "image": "BLK4226.jpg" | |
| }, | |
| "name": "Serving Bowl", | |
| "prices": { | |
| "origprice": 0, | |
| "price": 60 | |
| }, | |
| "skuid": "BLK4226" | |
| } | |
| ] | |
| } | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| cart: belongsTo('cart'), | |
| product: belongsTo('product', { async: true }), | |
| skuid: attr('string'), | |
| quantity: attr('number'), | |
| personalization: attr(''), | |
| variantCodes: attr(''), | |
| variantData: attr(''), | |
| prices: attr('') | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| cart: attr('string'), | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| name: attr(''), | |
| skuid: attr(''), | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Route.extend({ | |
| model() { | |
| return this.get('store').findAll('cart-item', { include: 'products' }); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import DS from 'ember-data'; | |
| export default DS.RESTSerializer.extend({ | |
| // normalizeArrayResponse() { | |
| // let res = this._super(...arguments); | |
| // console.log('normalized array response:', res); | |
| // return res; | |
| // } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.13.0", | |
| "ENV": { | |
| "ember-cli-mirage": { | |
| "enabled": true | |
| } | |
| }, | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.16.2", | |
| "ember-template-compiler": "2.16.2", | |
| "ember-testing": "2.16.2" | |
| }, | |
| "addons": { | |
| "ember-data": "2.16.3", | |
| "ember-cli-mirage": "0.4.1" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment