diff --git a/app/adapters/application.js b/app/adapters/application.js new file mode 100644 index 0000000000000000000000000000000000000000..9e22e850a860377cacc4350cdda876e532c3e6c9 --- /dev/null +++ b/app/adapters/application.js @@ -0,0 +1,9 @@ +import JSONAPIAdapter from '@ember-data/adapter/json-api'; + +export default class ApplicationAdapter extends JSONAPIAdapter { + namespace = 'api'; + + buildURL(...args) { + return `${super.buildURL(...args)}.json`; + } +} \ No newline at end of file diff --git a/app/models/document.js b/app/models/document.js new file mode 100644 index 0000000000000000000000000000000000000000..96df438a55d43b9bd1bc8b8ac726043175df8463 --- /dev/null +++ b/app/models/document.js @@ -0,0 +1,6 @@ +import Model, { attr } from '@ember-data/model'; + +export default class DocumentModel extends Model { + @attr title; + @attr image; +} \ No newline at end of file diff --git a/app/routes/document.js b/app/routes/document.js index 3f69d45e377fb6bff16a8bbacf9bcab13fcd30ad..84d7ae6da881680dbd65204e60961c34efef4368 100644 --- a/app/routes/document.js +++ b/app/routes/document.js @@ -1,13 +1,11 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; export default class RentalRoute extends Route { - async model(params) { - let response = await fetch(`/api/document/${params.document_id}.json`); - let { data } = await response.json(); - let { attributes } = data; - let type = 'document'; + @service store; - return { type, ...attributes }; + async model(params) { + return this.store.findRecord('document', params.document_id); } } diff --git a/app/routes/index.js b/app/routes/index.js index d914bbc19272b41d75d9ce324a6245ffe5abf9b5..d24bebebcad6810271ccb38155d582cb43aca203 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -1,15 +1,12 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; + export default class IndexRoute extends Route { - async model() { - let response = await fetch('/api/nodes.json'); - let { data } = await response.json(); - return data.map((model) => { - let { attributes } = model; - let type = 'document'; + @service store; - return { type, ...attributes }; - }); + async model() { + return this.store.findAll('document'); } } diff --git a/app/serializers/application.js b/app/serializers/application.js new file mode 100644 index 0000000000000000000000000000000000000000..4756f2c3b09d9931892037a48ceb2db94d4b6e52 --- /dev/null +++ b/app/serializers/application.js @@ -0,0 +1,5 @@ +import JSONAPISerializer from '@ember-data/serializer/json-api'; + +export default class ApplicationSerializer extends JSONAPISerializer { + +} \ No newline at end of file diff --git a/public/api/document/1.json b/public/api/document/1.json index 06a7334b2049f0815508e09b6b0f470cde76219f..f38f84ace9652d292ae6a4e7d7a0b788c54697aa 100644 --- a/public/api/document/1.json +++ b/public/api/document/1.json @@ -1,8 +1,8 @@ { "data": { "type": "document", + "id": 1, "attributes": { - "id": 1, "title": "Invoice 1.pdf", "image": "https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg" } diff --git a/public/api/nodes.json b/public/api/documents.json similarity index 90% rename from public/api/nodes.json rename to public/api/documents.json index f161ba3e85a538a61ff07bbf5c3160704ef11d35..e3af1fe06af16b747fd49427ec09281c1c32bc8c 100644 --- a/public/api/nodes.json +++ b/public/api/documents.json @@ -2,16 +2,16 @@ "data": [ { "type": "document", + "id": 1, "attributes": { - "id": 1, "title": "Invoice 1.pdf", "image": "https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg" } }, { "type": "document", + "id": 2, "attributes": { - "id": 2, "title": "Invoice 2.pdf", "image": "https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg" }