diff --git a/src/Tree.sln b/src/Tree.sln index 27542b14eef80691fa5ea1e0e8f6aa90d64b0129..f966299b109c78e28aac4b784cc572d9d6a3c00c 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 3c4ee7a4a295f48a8d00aea14532b78872038e94..7ed00bef2ad53da41474b794bd8e2c99702763ec 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 b2ac70de49d2c0898caaae96a1d5efdf6e4424ee..5f3e76b68d4b6d1cae5038c6aa08efa96893964f 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>