From 8ad6c4381566ff11d2f6185b14dfebbf32ffcd63 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 5 Aug 2021 16:11:16 +0200 Subject: [PATCH] get by ids for space items --- zero.Core/Api/SpacesApi.cs | 28 ++++++++++++++++++++++++ zero.Web/Controllers/SpacesController.cs | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/zero.Core/Api/SpacesApi.cs b/zero.Core/Api/SpacesApi.cs index 9dcbeb53..4298fce9 100644 --- a/zero.Core/Api/SpacesApi.cs +++ b/zero.Core/Api/SpacesApi.cs @@ -73,6 +73,29 @@ namespace zero.Core.Api } + /// + public async Task> GetItems(params string[] ids) where T : SpaceContent + { + Space space = GetBy(); + + using (IAsyncDocumentSession session = Store.OpenAsyncSession()) + { + ids = ids.Distinct().ToArray(); + + Dictionary models = await session.LoadAsync(ids); + Dictionary result = new Dictionary(); + + foreach (string id in ids) + { + models.TryGetValue(id, out T model); + result.Add(id, model); + } + + return result; + } + } + + /// public async Task> GetListByQuery(string alias, ListQuery query) { @@ -158,6 +181,11 @@ namespace zero.Core.Api /// Task GetItem(string id = null) where T : SpaceContent; + /// + /// Get editor items for a space + /// + Task> GetItems(params string[] ids) where T : SpaceContent; + /// /// Get all list items for a space (with query) /// diff --git a/zero.Web/Controllers/SpacesController.cs b/zero.Web/Controllers/SpacesController.cs index b12ef485..cd0b5a41 100644 --- a/zero.Web/Controllers/SpacesController.cs +++ b/zero.Web/Controllers/SpacesController.cs @@ -45,7 +45,6 @@ namespace zero.Web.Controllers return Ok(await Api.GetListByQuery(alias, query)); } - public async Task GetContent([FromQuery] string alias, [FromQuery] string contentId = null) { if (!CanReadSpace(alias))