From 61ed84ba232f8b5d4bcfeba28ed452bc88277be5 Mon Sep 17 00:00:00 2001 From: "L. Ellenbeck" <ellenbeck@itc.rwth-aachen.de> Date: Thu, 2 Dec 2021 08:49:37 +0100 Subject: [PATCH] Fix: added query parameter call (coscine/issues#1259) --- src/Tree.sln | 3 +- src/Tree/Controllers/TreeController.cs | 65 +++++++++++++++++++++++++- src/Tree/Tree.csproj | 1 + 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/Tree.sln b/src/Tree.sln index 27542b1..f966299 100644 --- a/src/Tree.sln +++ b/src/Tree.sln @@ -1,9 +1,8 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28803.156 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tree", "Tree\Tree.csproj", "{AC8882D4-3F0C-4BBF-83CE-22A5B05ED3FB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tree", "Tree\Tree.csproj", "{AC8882D4-3F0C-4BBF-83CE-22A5B05ED3FB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Tree/Controllers/TreeController.cs b/src/Tree/Controllers/TreeController.cs index 3c4ee7a..7ed00be 100644 --- a/src/Tree/Controllers/TreeController.cs +++ b/src/Tree/Controllers/TreeController.cs @@ -11,6 +11,7 @@ using Coscine.ResourceTypeBase; using Coscine.WaterbutlerHelper; using Coscine.WaterbutlerHelper.ReturnObjects; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq; @@ -83,6 +84,36 @@ namespace Coscine.Api.Tree.Controllers /// <param name="path">Path to the file</param> /// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns> [HttpGet("[controller]/{resourceId}/{*path}")] + [ApiExplorerSettings(IgnoreApi = true)] + public async Task<IActionResult> GetMetadataWithPath(string resourceId, string path = "") + { + return await GetMetadata(resourceId, path); + } + + /// <summary> + /// This method retrieves the metadata + /// </summary> + /// <param name="resourceId"> Id of a resource</param> + /// <param name="path">Path to the file</param> + /// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns> + [HttpGet("[controller]/{resourceId}/")] + public async Task<IActionResult> GetMetadataWithParameter(string resourceId, [System.Web.Http.FromUri] string path = "") + { + // Strip the first slash, to reuse the previous implementation. + if (path.StartsWith("/")) + { + path = path[1..]; + } + + return await GetMetadata(resourceId, path); + } + + /// <summary> + /// This method retrieves the metadata + /// </summary> + /// <param name="resourceId"> Id of a resource</param> + /// <param name="path">Path to the file</param> + /// <returns> JSON Object with the metadata if OK, otherwise status code 400 or 401 or 404</returns> public async Task<IActionResult> GetMetadata(string resourceId, string path = "") { var rawPath = path; @@ -195,9 +226,9 @@ namespace Coscine.Api.Tree.Controllers return Json(jObject); } - catch (Exception e) + catch (Exception) { - return BadRequest($"Error in communication with the resource"); + return BadRequest("Error in communication with the resource"); } } @@ -230,6 +261,36 @@ namespace Coscine.Api.Tree.Controllers /// <param name="path">Path to the file</param> /// <returns>If OK status code 204, otherwise status code 400 or 401</returns> [HttpPut("[controller]/{resourceId}/{*path}")] + [ApiExplorerSettings(IgnoreApi = true)] + public IActionResult StoreMetadataForFileWithPath(string resourceId, string path) + { + return StoreMetadataForFile(resourceId, path); + } + + /// <summary> + /// This method stores the metadata of the file + /// </summary> + /// <param name="resourceId">Id of the resource</param> + /// <param name="path">Path to the file</param> + /// <returns>If OK status code 204, otherwise status code 400 or 401</returns> + [HttpPut("[controller]/{resourceId}/")] + public IActionResult StoreMetadataForFileWithParameter(string resourceId, [System.Web.Http.FromUri] string path = "") + { + // Strip the first slash, to reuse the previous implementation. + if (path.StartsWith("/")) + { + path = path[1..]; + } + + return StoreMetadataForFile(resourceId, path); + } + + /// <summary> + /// This method stores the metadata of the file + /// </summary> + /// <param name="resourceId">Id of the resource</param> + /// <param name="path">Path to the file</param> + /// <returns>If OK status code 204, otherwise status code 400 or 401</returns> public IActionResult StoreMetadataForFile(string resourceId, string path) { path = $"/{path}"; diff --git a/src/Tree/Tree.csproj b/src/Tree/Tree.csproj index b2ac70d..5f3e76b 100644 --- a/src/Tree/Tree.csproj +++ b/src/Tree/Tree.csproj @@ -24,5 +24,6 @@ <PackageReference Include="Coscine.ResourceLoader" Version="2.*-*" /> <PackageReference Include="Coscine.ResourceTypeBase" Version="2.*-*" /> <PackageReference Include="Coscine.WaterbutlerHelper" Version="2.*-*" /> + <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" /> </ItemGroup> </Project> -- GitLab