Files
Umbraco-CMS/src/Umbraco.Cms.Api.Management/Controllers/PathFolderManagementControllerBase.cs

64 lines
2.1 KiB
C#
Raw Normal View History

New backoffice: Add new codefile controllers and services (#14157) * Add scaffolding * Entities not Entitys * Remove unececary obsoleted constructor * Implement create script * Return a simplified ScriptFile instead of IScript That file abstraction seems way too bloated, containing a lot of stuff that's not relevant for files, such as IDs and keys. * Use IScript instead of custom return model * Add validation when creating script * Add Get script endpoint * Add response types * Add Delete * Throw if user key not found * Remove unused maapper * Add update endpoint * Add Get by path * Add create folder endpoint * Don't pass performingUserId to folder creation * Remove update folder * Add delete folder endpoint * Use specific ScriptFolderOperationStatus instead of ScriptOperationStatus * Add OperationStatusResult * Check folder for invalid name * Check name for invalid characters * Add partial view snippet endpoint * Start working on CreatePartialView * Add create partial view endpoint * Retrieve key from audit method * Add operation status results * Add Get endpoint * Return 201 when creating * Add update partial view endpoint * Add delete endpoint * Add response types * Add folder base implementation * Add folder endpoints * User property for allowed file extensions * Rename async method to async * Break snippet into endpoint in two * Make content non-nullable * Remove IService * Add get by path * Add viewmodels * Add create and update models * Add create stylesheet * Add update endpoint * Rename StylesheetControllerBase to StylesheetControllerBase * Add stylesheet delete * Rename controller bases * Add stylesheet folders * Add status results * Add response types to folders * Add richtext rules endpoints * Add Get all endpoint * Add get rules by path endpoint * Aling validates so they're not async These are private methods, so there's no reason to make them preemptively async * Add template obsoletions to interface * Add stream methods This is evidently used by deploy 🤷 * Obsolete stylesheet operations * Add get and getall across all services * Obsolete script operations * Obsolete old partial view methods * Add some method docs * Add compatibility suppression * Update OpenApi.json * Rename action * formatting * Fix import * add expression body * Invert if * Move base on own line * Rename file * Rename to all * Change to stylesheet instead of script * Add Umbraco.Code.MapAll to map definitions * Add comment about auditing * use publish cancelable async * use expression body * formatting * fix to use pattern matching --------- Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-04-26 13:47:47 +02:00
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.Builders;
New backoffice: Add new codefile controllers and services (#14157) * Add scaffolding * Entities not Entitys * Remove unececary obsoleted constructor * Implement create script * Return a simplified ScriptFile instead of IScript That file abstraction seems way too bloated, containing a lot of stuff that's not relevant for files, such as IDs and keys. * Use IScript instead of custom return model * Add validation when creating script * Add Get script endpoint * Add response types * Add Delete * Throw if user key not found * Remove unused maapper * Add update endpoint * Add Get by path * Add create folder endpoint * Don't pass performingUserId to folder creation * Remove update folder * Add delete folder endpoint * Use specific ScriptFolderOperationStatus instead of ScriptOperationStatus * Add OperationStatusResult * Check folder for invalid name * Check name for invalid characters * Add partial view snippet endpoint * Start working on CreatePartialView * Add create partial view endpoint * Retrieve key from audit method * Add operation status results * Add Get endpoint * Return 201 when creating * Add update partial view endpoint * Add delete endpoint * Add response types * Add folder base implementation * Add folder endpoints * User property for allowed file extensions * Rename async method to async * Break snippet into endpoint in two * Make content non-nullable * Remove IService * Add get by path * Add viewmodels * Add create and update models * Add create stylesheet * Add update endpoint * Rename StylesheetControllerBase to StylesheetControllerBase * Add stylesheet delete * Rename controller bases * Add stylesheet folders * Add status results * Add response types to folders * Add richtext rules endpoints * Add Get all endpoint * Add get rules by path endpoint * Aling validates so they're not async These are private methods, so there's no reason to make them preemptively async * Add template obsoletions to interface * Add stream methods This is evidently used by deploy 🤷 * Obsolete stylesheet operations * Add get and getall across all services * Obsolete script operations * Obsolete old partial view methods * Add some method docs * Add compatibility suppression * Update OpenApi.json * Rename action * formatting * Fix import * add expression body * Invert if * Move base on own line * Rename file * Rename to all * Change to stylesheet instead of script * Add Umbraco.Code.MapAll to map definitions * Add comment about auditing * use publish cancelable async * use expression body * formatting * fix to use pattern matching --------- Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-04-26 13:47:47 +02:00
using Umbraco.Cms.Api.Management.ViewModels.Folder;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Api.Management.Controllers;
public abstract class PathFolderManagementControllerBase<TStatus> : ManagementApiControllerBase
where TStatus : Enum
{
protected readonly IUmbracoMapper Mapper;
protected PathFolderManagementControllerBase(
IUmbracoMapper mapper) =>
Mapper = mapper;
protected async Task<IActionResult> GetFolderAsync(string path)
{
PathContainer? container = await GetContainerAsync(path);
if (container == null)
{
return NotFound(new ProblemDetailsBuilder()
.WithTitle("The container could not be found")
.Build());
New backoffice: Add new codefile controllers and services (#14157) * Add scaffolding * Entities not Entitys * Remove unececary obsoleted constructor * Implement create script * Return a simplified ScriptFile instead of IScript That file abstraction seems way too bloated, containing a lot of stuff that's not relevant for files, such as IDs and keys. * Use IScript instead of custom return model * Add validation when creating script * Add Get script endpoint * Add response types * Add Delete * Throw if user key not found * Remove unused maapper * Add update endpoint * Add Get by path * Add create folder endpoint * Don't pass performingUserId to folder creation * Remove update folder * Add delete folder endpoint * Use specific ScriptFolderOperationStatus instead of ScriptOperationStatus * Add OperationStatusResult * Check folder for invalid name * Check name for invalid characters * Add partial view snippet endpoint * Start working on CreatePartialView * Add create partial view endpoint * Retrieve key from audit method * Add operation status results * Add Get endpoint * Return 201 when creating * Add update partial view endpoint * Add delete endpoint * Add response types * Add folder base implementation * Add folder endpoints * User property for allowed file extensions * Rename async method to async * Break snippet into endpoint in two * Make content non-nullable * Remove IService * Add get by path * Add viewmodels * Add create and update models * Add create stylesheet * Add update endpoint * Rename StylesheetControllerBase to StylesheetControllerBase * Add stylesheet delete * Rename controller bases * Add stylesheet folders * Add status results * Add response types to folders * Add richtext rules endpoints * Add Get all endpoint * Add get rules by path endpoint * Aling validates so they're not async These are private methods, so there's no reason to make them preemptively async * Add template obsoletions to interface * Add stream methods This is evidently used by deploy 🤷 * Obsolete stylesheet operations * Add get and getall across all services * Obsolete script operations * Obsolete old partial view methods * Add some method docs * Add compatibility suppression * Update OpenApi.json * Rename action * formatting * Fix import * add expression body * Invert if * Move base on own line * Rename file * Rename to all * Change to stylesheet instead of script * Add Umbraco.Code.MapAll to map definitions * Add comment about auditing * use publish cancelable async * use expression body * formatting * fix to use pattern matching --------- Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-04-26 13:47:47 +02:00
}
PathFolderResponseModel? viewModel = Mapper.Map<PathFolderResponseModel>(container);
return Ok(viewModel);
}
protected async Task<IActionResult> CreateAsync(CreatePathFolderRequestModel requestModel)
{
PathContainer folderModel = Mapper.Map<PathContainer>(requestModel)!;
Attempt<PathContainer?, TStatus> attempt = await CreateContainerAsync(folderModel);
if (attempt.Success is false)
{
return OperationStatusResult(attempt.Status);
}
PathFolderResponseModel? viewModel = Mapper.Map<PathFolderResponseModel>(attempt.Result);
return Ok(viewModel);
}
protected async Task<IActionResult> DeleteAsync(string path)
{
Attempt<TStatus> attempt = await DeleteContainerAsync(path);
return attempt.Success
? Ok()
: OperationStatusResult(attempt.Result!);
}
protected abstract Task<PathContainer?> GetContainerAsync(string path);
protected abstract Task<Attempt<PathContainer?, TStatus>> CreateContainerAsync(PathContainer container);
protected abstract Task<Attempt<TStatus>> DeleteContainerAsync(string path);
protected abstract IActionResult OperationStatusResult(TStatus status);
}