New Backoffice: Log viewer controller (#13648)
* Fixing a few nullable reference types for log viewer (#13634) (cherry picked from commitb4ca2a6636) * Adding LogControllerBase * Migrating GetLogLevels() * Migrating GetNumberOfErrors() * Migrating GetLogLevelCounts() * Migrating GetCanViewLogs() * Migrating GetMessageTemplates() * Migrating GetLogs() * Migrating GetSavedSearches() * Migrating PostSavedSearch() * Migrating DeleteSavedSearch() * Adding LoggerViewModel * Adding LogViewModelMapDefinition * Update OpenApi.json * Cleanup * V12: Change nullability for the log searches (#13647) * Changing nullability * Obsolete DeleteSavedSearch since the query param is not used * Fix a bit more referenced * Add default implementation for the new overload of DeleteSavedSearch (cherry picked from commit5e06f5a8a0) * Updates based on nullability fix * Adding GetSavedSearchByName * Implementing ByName endpoint * Refactoring Delete endpoint based on GetSavedSearchByName * Refactoring Create endpoint to return the item's location * Suppress new GetSavedSearchByName in ILogViewer interfaces * Update OpenApi.json * Adding github initials to FIXME * Renaming * Moving files to Core proj * Adding GetLogs with skip and take * Introducing ILogViewerService * Supressing xml for ILogViewer.GetLogsAsPagedModel() * Changing to our own Enum representation of LogLevel * Creating ILogEntry needed for GetPagedLogs() * Refactoring controllers to use the new logViewerService * Removing base class methods since those have been moved to the new service * Removing ErrorCountLogViewerController since the result can be calculated from another endpoint * Refactoring the MapDefinition because of the new return types from the service * Update OpenApi.json * Obsoleting old methods in favor of the ILogViewerService * Cleanup * Fixing enum representation as strings for Swagger * Adding documentation * Changing enum representation to string in OpenApi.OpenApi.json * Fix FIXME (use CreatedAtAction) * Removing JsonStringEnumConverter as there should be another way to fix enum representation for Swagger * Removing MappingBuilderExtensions and making specific LogViewerBuilderExtensions * Changes to the .sln file * Take only the result in the response * Register the LogViewer extensions * Update OpenApi.json * Fix the supressions.xml * Add inheritdoc * Remove GetSavedSearchByName as it isn't necessary to introduce it anymore * Obsolete interfaces * Rename ViewPermission controller to ValidateLogFileSize * Make rest of the methods async * Route name change * Remove methods obsoletion * Introduce the "attempt" pattern * Refactoring of ILogViewerService * Refactoring controllers * Another OpenApi.json update * Adding fixme * Re-add new client project Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch>
This commit is contained in:
committed by
GitHub
parent
0fd90c1294
commit
aa90efa5b7
@@ -0,0 +1,63 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Logging.Viewer;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.New.Cms.Core.Models;
|
||||
using LogLevel = Umbraco.Cms.Core.Logging.LogLevel;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
public class AllLogViewerController : LogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public AllLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paginated list of all logs for a specific date range.
|
||||
/// </summary>
|
||||
/// <param name="skip">The amount of items to skip.</param>
|
||||
/// <param name="take">The amount of items to take.</param>
|
||||
/// <param name="orderDirection">
|
||||
/// By default this will be ordered descending (newest items first).
|
||||
/// </param>
|
||||
/// <param name="filterExpression">The query expression to filter on (can be null).</param>
|
||||
/// <param name="logLevels">The log levels for which to retrieve the log messages (can be null).</param>
|
||||
/// <param name="startDate">The start date for the date range (can be null).</param>
|
||||
/// <param name="endDate">The end date for the date range (can be null).</param>
|
||||
/// <returns>The paged result of the logs from the given time period.</returns>
|
||||
[HttpGet("log")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<LogMessageViewModel>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> AllLogs(
|
||||
int skip = 0,
|
||||
int take = 100,
|
||||
Direction orderDirection = Direction.Descending,
|
||||
string? filterExpression = null,
|
||||
[FromQuery(Name = "logLevel")] LogLevel[]? logLevels = null,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
{
|
||||
var levels = logLevels?.Select(l => l.ToString()).ToArray();
|
||||
|
||||
Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus> logsAttempt =
|
||||
await _logViewerService.GetPagedLogsAsync(startDate, endDate, skip, take, orderDirection, filterExpression, levels);
|
||||
|
||||
if (logsAttempt.Success)
|
||||
{
|
||||
return Ok(_umbracoMapper.Map<PagedViewModel<LogMessageViewModel>>(logsAttempt.Result));
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(logsAttempt.Status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
public class AllSinkLevelLogViewerController : LogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public AllSinkLevelLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paginated list of all loggers' levels.
|
||||
/// </summary>
|
||||
/// <param name="skip">The amount of items to skip.</param>
|
||||
/// <param name="take">The amount of items to take.</param>
|
||||
/// <returns>The paged result of the configured loggers and their level.</returns>
|
||||
[HttpGet("level")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<LoggerViewModel>), StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<PagedViewModel<LoggerViewModel>>> AllLogLevels(int skip = 0, int take = 100)
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, LogLevel>> logLevels = _logViewerService
|
||||
.GetLogLevelsFromSinks()
|
||||
.Skip(skip)
|
||||
.Take(take);
|
||||
|
||||
return await Task.FromResult(Ok(_umbracoMapper.Map<PagedViewModel<LoggerViewModel>>(logLevels)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Logging.Viewer;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
public class LogLevelCountLogViewerController : LogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public LogLevelCountLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the count for each log level from the logs for a specific date range.
|
||||
/// </summary>
|
||||
/// <param name="startDate">The start date for the date range (can be null).</param>
|
||||
/// <param name="endDate">The end date for the date range (can be null).</param>
|
||||
/// <returns>The log level counts from the (filtered) logs.</returns>
|
||||
[HttpGet("level-count")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> LogLevelCounts(DateTime? startDate = null, DateTime? endDate = null)
|
||||
{
|
||||
Attempt<LogLevelCounts?, LogViewerOperationStatus> logLevelCountsAttempt =
|
||||
await _logViewerService.GetLogLevelCountsAsync(startDate, endDate);
|
||||
|
||||
if (logLevelCountsAttempt.Success)
|
||||
{
|
||||
return Ok(_umbracoMapper.Map<LogLevelCountsViewModel>(logLevelCountsAttempt.Result));
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(logLevelCountsAttempt.Status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.Builders;
|
||||
using Umbraco.Cms.Api.Management.Routing;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
[ApiController]
|
||||
[VersionedApiBackOfficeRoute("log-viewer")]
|
||||
[ApiExplorerSettings(GroupName = "Log Viewer")]
|
||||
[ApiVersion("1.0")]
|
||||
public abstract class LogViewerControllerBase : ManagementApiControllerBase
|
||||
{
|
||||
protected IActionResult LogViewerOperationStatusResult(LogViewerOperationStatus status) =>
|
||||
status switch
|
||||
{
|
||||
LogViewerOperationStatus.NotFoundLogSearch => NotFound("The log search could not be found"),
|
||||
LogViewerOperationStatus.DuplicateLogSearch => BadRequest(new ProblemDetailsBuilder()
|
||||
.WithTitle("Duplicate log search name")
|
||||
.WithDetail("Another log search already exists with the attempted name.")
|
||||
.Build()),
|
||||
LogViewerOperationStatus.CancelledByLogsSizeValidation => BadRequest(new ProblemDetailsBuilder()
|
||||
.WithTitle("Cancelled due to log file size")
|
||||
.WithDetail("The log file size for the requested date range prevented the operation.")
|
||||
.Build()),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, "Unknown log viewer operation status")
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core.Logging.Viewer;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
public class MessageTemplateLogViewerController : LogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public MessageTemplateLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paginated list of all log message templates for a specific date range.
|
||||
/// </summary>
|
||||
/// <param name="skip">The amount of items to skip.</param>
|
||||
/// <param name="take">The amount of items to take.</param>
|
||||
/// <param name="startDate">The start date for the date range (can be null).</param>
|
||||
/// <param name="endDate">The end date for the date range (can be null).</param>
|
||||
/// <returns>The paged result of the log message templates from the given time period.</returns>
|
||||
[HttpGet("message-template")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(PagedViewModel<LogTemplateViewModel>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> AllMessageTemplates(
|
||||
int skip = 0,
|
||||
int take = 100,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
{
|
||||
Attempt<IEnumerable<LogTemplate>, LogViewerOperationStatus> messageTemplatesAttempt = await _logViewerService.GetMessageTemplatesAsync(startDate, endDate);
|
||||
|
||||
if (messageTemplatesAttempt.Success)
|
||||
{
|
||||
IEnumerable<LogTemplate> messageTemplates = messageTemplatesAttempt
|
||||
.Result
|
||||
.Skip(skip)
|
||||
.Take(take);
|
||||
|
||||
return Ok(_umbracoMapper.Map<PagedViewModel<LogTemplateViewModel>>(messageTemplates));
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(messageTemplatesAttempt.Status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer.SavedSearch;
|
||||
|
||||
public class AllSavedSearchLogViewerController : SavedSearchLogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public AllSavedSearchLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a paginated list of all saved log searches.
|
||||
/// </summary>
|
||||
/// <param name="skip">The amount of items to skip.</param>
|
||||
/// <param name="take">The amount of items to take.</param>
|
||||
/// <returns>The paged result of the saved log searches.</returns>
|
||||
[HttpGet]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<SavedLogSearchViewModel>), StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<PagedViewModel<SavedLogSearchViewModel>>> AllSavedSearches(int skip = 0, int take = 100)
|
||||
{
|
||||
IReadOnlyList<ILogViewerQuery> savedLogQueries = await _logViewerService.GetSavedLogQueriesAsync();
|
||||
|
||||
return Ok(_umbracoMapper.Map<PagedViewModel<SavedLogSearchViewModel>>(savedLogQueries.Skip(skip).Take(take)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer.SavedSearch;
|
||||
|
||||
public class ByNameSavedSearchLogViewerController : SavedSearchLogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public ByNameSavedSearchLogViewerController(ILogViewerService logViewerService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_logViewerService = logViewerService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a saved log search by name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the saved log search.</param>
|
||||
/// <returns>The saved log search or not found result.</returns>
|
||||
[HttpGet("{name}")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(SavedLogSearchViewModel), StatusCodes.Status200OK)]
|
||||
public async Task<ActionResult<SavedLogSearchViewModel>> ByName(string name)
|
||||
{
|
||||
ILogViewerQuery? savedLogQuery = await _logViewerService.GetSavedLogQueryByNameAsync(name);
|
||||
|
||||
if (savedLogQuery is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(_umbracoMapper.Map<SavedLogSearchViewModel>(savedLogQuery));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.LogViewer;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer.SavedSearch;
|
||||
|
||||
public class CreateSavedSearchLogViewerController : SavedSearchLogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
|
||||
public CreateSavedSearchLogViewerController(ILogViewerService logViewerService) => _logViewerService = logViewerService;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a saved log search.
|
||||
/// </summary>
|
||||
/// <param name="savedSearch">The log search to be saved.</param>
|
||||
/// <returns>The location of the saved log search after the creation.</returns>
|
||||
[HttpPost]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
public async Task<IActionResult> Create(SavedLogSearchViewModel savedSearch)
|
||||
{
|
||||
Attempt<ILogViewerQuery?, LogViewerOperationStatus> result =
|
||||
await _logViewerService.AddSavedLogQueryAsync(savedSearch.Name, savedSearch.Query);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
return CreatedAtAction<ByNameSavedSearchLogViewerController>(
|
||||
controller => nameof(controller.ByName), savedSearch.Name);
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(result.Status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer.SavedSearch;
|
||||
|
||||
public class DeleteSavedSearchLogViewerController : SavedSearchLogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
|
||||
public DeleteSavedSearchLogViewerController(ILogViewerService logViewerService) => _logViewerService = logViewerService;
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a saved log search with a given name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the saved log search.</param>
|
||||
/// <returns>The result of the deletion.</returns>
|
||||
[HttpDelete("{name}")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(NotFoundResult), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> Delete(string name)
|
||||
{
|
||||
Attempt<ILogViewerQuery?, LogViewerOperationStatus> result = await _logViewerService.DeleteSavedLogQueryAsync(name);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(result.Status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.Routing;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer.SavedSearch;
|
||||
|
||||
[ApiController]
|
||||
[VersionedApiBackOfficeRoute("log-viewer/saved-search")]
|
||||
[ApiExplorerSettings(GroupName = "Log Viewer")]
|
||||
[ApiVersion("1.0")]
|
||||
public class SavedSearchLogViewerControllerBase : LogViewerControllerBase
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.LogViewer;
|
||||
|
||||
public class ValidateLogFileSizeLogViewerController : LogViewerControllerBase
|
||||
{
|
||||
private readonly ILogViewerService _logViewerService;
|
||||
|
||||
public ValidateLogFileSizeLogViewerController(ILogViewerService logViewerService) => _logViewerService = logViewerService;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not you are able to view logs for a specified date range.
|
||||
/// </summary>
|
||||
/// <param name="startDate">The start date for the date range (can be null).</param>
|
||||
/// <param name="endDate">The end date for the date range (can be null).</param>
|
||||
/// <returns>The boolean result.</returns>
|
||||
[HttpGet("validate-logs-size")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> CanViewLogs(DateTime? startDate = null, DateTime? endDate = null)
|
||||
{
|
||||
Attempt<bool, LogViewerOperationStatus> result = await _logViewerService.CanViewLogsAsync(startDate, endDate);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return LogViewerOperationStatusResult(result.Status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user