diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/CreatePartialViewFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/CreatePartialViewFolderController.cs index 07706351b1..c8f6a2d43b 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/CreatePartialViewFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/CreatePartialViewFolderController.cs @@ -2,23 +2,32 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Api.Management.ViewModels.Folder; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Mapping; +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Folder; [ApiVersion("1.0")] public class CreatePartialViewFolderController : PartialViewFolderControllerBase { - public CreatePartialViewFolderController( - IUmbracoMapper mapper, - IPartialViewFolderService partialViewFolderService) + public CreatePartialViewFolderController(IUmbracoMapper mapper, IPartialViewFolderService partialViewFolderService) : base(mapper, partialViewFolderService) { } [HttpPost] [MapToApiVersion("1.0")] - [ProducesResponseType(StatusCodes.Status200OK)] - public Task Create(CreatePathFolderRequestModel model) => CreateAsync(model); + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] + public async Task Create(CreatePathFolderRequestModel model) + { + Attempt result = await CreateAsync(model); + return result.Success + ? CreatedAtAction(controller => nameof(controller.ByPath), new { path = result.Result!.Path }) + : OperationStatusResult(result.Status); + } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/DeletePartialViewFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/DeletePartialViewFolderController.cs index 3d933ac6e1..dbe76cfbdc 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/DeletePartialViewFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Folder/DeletePartialViewFolderController.cs @@ -19,5 +19,7 @@ public class DeletePartialViewFolderController : PartialViewFolderControllerBase [HttpDelete] [MapToApiVersion("1.0")] [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] public Task Delete(string path) => DeleteAsync(path); } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PathFolderManagementControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/PathFolderManagementControllerBase.cs index 291ed932f3..a6a74bb07f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PathFolderManagementControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PathFolderManagementControllerBase.cs @@ -30,18 +30,11 @@ public abstract class PathFolderManagementControllerBase : ManagementAp return Ok(viewModel); } - protected async Task CreateAsync(CreatePathFolderRequestModel requestModel) + protected async Task> CreateAsync(CreatePathFolderRequestModel requestModel) { PathContainer folderModel = Mapper.Map(requestModel)!; - Attempt attempt = await CreateContainerAsync(folderModel); - if (attempt.Success is false) - { - return OperationStatusResult(attempt.Status); - } - - PathFolderResponseModel? viewModel = Mapper.Map(attempt.Result); - return Ok(viewModel); + return await CreateContainerAsync(folderModel); } protected async Task DeleteAsync(string path) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/CreateScriptFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/CreateScriptFolderController.cs index 9ce91c1c03..c1f67363f1 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/CreateScriptFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/CreateScriptFolderController.cs @@ -2,23 +2,32 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Api.Management.ViewModels.Folder; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Mapping; +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Api.Management.Controllers.Script.Folder; [ApiVersion("1.0")] public class CreateScriptFolderController : ScriptFolderControllerBase { - public CreateScriptFolderController( - IUmbracoMapper mapper, - IScriptFolderService scriptFolderService) + public CreateScriptFolderController(IUmbracoMapper mapper, IScriptFolderService scriptFolderService) : base(mapper, scriptFolderService) { } [HttpPost] [MapToApiVersion("1.0")] - [ProducesResponseType(StatusCodes.Status200OK)] - public Task Create(CreatePathFolderRequestModel model) => CreateAsync(model); + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] + public async Task Create(CreatePathFolderRequestModel model) + { + Attempt result = await CreateAsync(model); + return result.Success + ? CreatedAtAction(controller => nameof(controller.ByPath), new { path = result.Result!.Path }) + : OperationStatusResult(result.Status); + } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/DeleteScriptFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/DeleteScriptFolderController.cs index 17d670abae..95f4b64ac4 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/DeleteScriptFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Folder/DeleteScriptFolderController.cs @@ -17,5 +17,7 @@ public class DeleteScriptFolderController : ScriptFolderControllerBase [HttpDelete] [MapToApiVersion("1.0")] [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] public Task Delete(string path) => DeleteAsync(path); } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/CreateStylesheetFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/CreateStylesheetFolderController.cs index 3a25ba2aba..c1c90510c8 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/CreateStylesheetFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/CreateStylesheetFolderController.cs @@ -2,21 +2,33 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Api.Management.ViewModels.Folder; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Mapping; +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Folder; [ApiVersion("1.0")] public class CreateStylesheetFolderController : StylesheetFolderControllerBase { - public CreateStylesheetFolderController(IUmbracoMapper mapper, IStylesheetFolderService stylesheetFolderService) : base(mapper, stylesheetFolderService) + public CreateStylesheetFolderController(IUmbracoMapper mapper, IStylesheetFolderService stylesheetFolderService) + : base(mapper, stylesheetFolderService) { } [HttpPost] [MapToApiVersion("1.0")] - [ProducesResponseType(StatusCodes.Status200OK)] - public Task Create(CreatePathFolderRequestModel model) => CreateAsync(model); + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] + public async Task Create(CreatePathFolderRequestModel model) + { + Attempt result = await CreateAsync(model); + return result.Success + ? CreatedAtAction(controller => nameof(controller.ByPath), new { path = result.Result!.Path }) + : OperationStatusResult(result.Status); + } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/DeleteStylesheetFolderController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/DeleteStylesheetFolderController.cs index 313bedbea1..a27b16b8f6 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/DeleteStylesheetFolderController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Folder/DeleteStylesheetFolderController.cs @@ -9,12 +9,15 @@ namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Folder; [ApiVersion("1.0")] public class DeleteStylesheetFolderController : StylesheetFolderControllerBase { - public DeleteStylesheetFolderController(IUmbracoMapper mapper, IStylesheetFolderService stylesheetFolderService) : base(mapper, stylesheetFolderService) + public DeleteStylesheetFolderController(IUmbracoMapper mapper, IStylesheetFolderService stylesheetFolderService) + : base(mapper, stylesheetFolderService) { } [HttpDelete] [MapToApiVersion("1.0")] [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] public Task Delete(string path) => DeleteAsync(path); } diff --git a/src/Umbraco.Cms.Api.Management/OpenApi.json b/src/Umbraco.Cms.Api.Management/OpenApi.json index b24263d49c..1b1aa7cebe 100644 --- a/src/Umbraco.Cms.Api.Management/OpenApi.json +++ b/src/Umbraco.Cms.Api.Management/OpenApi.json @@ -10836,8 +10836,58 @@ } }, "responses": { - "200": { - "description": "Success" + "201": { + "description": "Created", + "headers": { + "Location": { + "description": "Location of the newly created resource", + "schema": { + "type": "string", + "description": "Location of the newly created resource", + "format": "uri" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } }, "401": { "description": "The resource is protected and requires an authentication token" @@ -10867,6 +10917,46 @@ "200": { "description": "Success" }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, "401": { "description": "The resource is protected and requires an authentication token" } @@ -12646,8 +12736,58 @@ } }, "responses": { - "200": { - "description": "Success" + "201": { + "description": "Created", + "headers": { + "Location": { + "description": "Location of the newly created resource", + "schema": { + "type": "string", + "description": "Location of the newly created resource", + "format": "uri" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } }, "401": { "description": "The resource is protected and requires an authentication token" @@ -12677,6 +12817,46 @@ "200": { "description": "Success" }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, "401": { "description": "The resource is protected and requires an authentication token" } @@ -14037,8 +14217,58 @@ } }, "responses": { - "200": { - "description": "Success" + "201": { + "description": "Created", + "headers": { + "Location": { + "description": "Location of the newly created resource", + "schema": { + "type": "string", + "description": "Location of the newly created resource", + "format": "uri" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } }, "401": { "description": "The resource is protected and requires an authentication token" @@ -14068,6 +14298,46 @@ "200": { "description": "Success" }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + }, + "text/plain": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, "401": { "description": "The resource is protected and requires an authentication token" }