From a574f934ff1cd91b1398234be220c8a36a499266 Mon Sep 17 00:00:00 2001 From: Remko Date: Mon, 12 Aug 2024 17:04:22 +0200 Subject: [PATCH] Updated api call --- lib/Db/Attachment.php | 4 +-- src/store/modules/publication.js | 32 +++++++++++++++++--- src/views/publications/PublicationDetail.vue | 3 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/Db/Attachment.php b/lib/Db/Attachment.php index ed1c2847..d06d4c0c 100644 --- a/lib/Db/Attachment.php +++ b/lib/Db/Attachment.php @@ -96,8 +96,8 @@ public function jsonSerialize(): array 'hash' => $this->hash, 'anonymization' => $this->anonymization, 'language' => $this->language, - 'modified' => $this->modified->format('c'), - 'published' => $this->published->format('c'), + 'modified' => $this->modified?->format('c'), + 'published' => $this->published?->format('c'), 'license' => $this->license, ]; diff --git a/src/store/modules/publication.js b/src/store/modules/publication.js index b31733f4..709b2734 100644 --- a/src/store/modules/publication.js +++ b/src/store/modules/publication.js @@ -85,11 +85,35 @@ export const usePublicationStore = defineStore( (response) => { response.json().then( (data) => { - this.publicationAttachments = Object.values(data.results.map( + this.publicationAttachments = data.results.map( (attachmentItem) => new Attachment(attachmentItem), - )).filter((attachment) => { - return publication.attachments?.includes(parseInt(attachment.id)) - }) + ) + return data + }, + ) + }, + ) + .catch( + (err) => { + console.error(err) + return err + }, + ) + }, + getPublicationAttachmentsById(publication) { // @todo this might belong in a service? + fetch( + `/index.php/apps/opencatalogi/api/publications/${publication.id}/attachments`, + { + method: 'GET', + }, + ) + .then( + (response) => { + response.json().then( + (data) => { + this.publicationAttachments = data.results.map( + (attachmentItem) => new Attachment(attachmentItem), + ) return data }, ) diff --git a/src/views/publications/PublicationDetail.vue b/src/views/publications/PublicationDetail.vue index 658f9af3..5d7eeed7 100644 --- a/src/views/publications/PublicationDetail.vue +++ b/src/views/publications/PublicationDetail.vue @@ -413,6 +413,7 @@ export default { data() { return { publication: [], + attachments: [], catalogi: [], metadata: [], prive: false, @@ -477,7 +478,7 @@ export default { // this.oldZaakId = id this.fetchCatalogi(data.catalogi) this.fetchMetaData(data.metaData) - publicationStore.getPublicationAttachments(data) + publicationStore.getPublicationAttachmentsById(data) // this.loading = false }) })