From 64bfc6c3caec949a6597e7d06b43d46291384ced Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Thu, 12 Sep 2024 17:10:44 +0100 Subject: [PATCH 1/2] Hierarchical collection to return with AsJson --- .../API/Features/Storage/StorageController.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index f48deb1a..4b8f53b6 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -9,8 +9,8 @@ using MediatR; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -using FluentValidation; -using Models.API.Collection; +using IIIF.Presentation; +using IIIF.Serialisation; using Models.API.Collection.Upsert; namespace API.Features.Storage; @@ -28,7 +28,8 @@ public async Task GetHierarchicalRootCollection(int customerId) if (storageRoot.Collection == null) return NotFound(); - return Ok(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items)); + return Content(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items).AsJson(), + ContentTypes.V3); } [HttpGet("{*slug}")] @@ -39,7 +40,8 @@ public async Task GetHierarchicalCollection(int customerId, strin if (storageRoot.Collection is not { IsPublic: true }) return NotFound(); - return Ok(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items)); + return Content(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items).AsJson(), + ContentTypes.V3); } [HttpGet("collections/{id}")] @@ -50,9 +52,13 @@ public async Task Get(int customerId, string id) if (storageRoot.Collection == null) return NotFound(); - return Ok(Request.ShowExtraProperties() - ? storageRoot.Collection.ToFlatCollection(GetUrlRoots(), Settings.PageSize, storageRoot.Items) - : storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items)); + if (Request.ShowExtraProperties()) + { + return Ok(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items)); + } + + return Content(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items).AsJson(), + ContentTypes.V3); } [HttpPost("collections")] From 4440462d02b640cdac22948647b66598b1ed4914 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Thu, 12 Sep 2024 17:25:17 +0100 Subject: [PATCH 2/2] returning flat collection correctly --- src/IIIFPresentation/API/Features/Storage/StorageController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index 4b8f53b6..83abae50 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -54,7 +54,7 @@ public async Task Get(int customerId, string id) if (Request.ShowExtraProperties()) { - return Ok(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items)); + return Ok(storageRoot.Collection.ToFlatCollection(GetUrlRoots(), Settings.PageSize, storageRoot.Items)); } return Content(storageRoot.Collection.ToHierarchicalCollection(GetUrlRoots(), storageRoot.Items).AsJson(),