// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Squidex.Areas.Api.Controllers.History.Models;
using Squidex.Domain.Apps.Entities.History.Repositories;
using Squidex.Infrastructure.Commands;
using Squidex.Pipeline;
using Squidex.Shared;
namespace Squidex.Areas.Api.Controllers.History
{
///
/// Readonly API to get an event stream.
///
[ApiExplorerSettings(GroupName = nameof(History))]
public sealed class HistoryController : ApiController
{
private readonly IHistoryEventRepository historyEventRepository;
public HistoryController(ICommandBus commandBus, IHistoryEventRepository historyEventRepository)
: base(commandBus)
{
this.historyEventRepository = historyEventRepository;
}
///
/// Get the events from the history
///
/// The name of the app.
/// The name of the channel.
///
/// 200 => Events returned.
/// 404 => App not found.
///
[HttpGet]
[Route("apps/{app}/history/")]
[ProducesResponseType(typeof(HistoryEventDto), 200)]
[ApiPermission(Permissions.AppCommon)]
[ApiCosts(0.1)]
public async Task GetHistory(string app, string channel)
{
var entities = await historyEventRepository.QueryByChannelAsync(AppId, channel, 100);
var response = entities.Select(HistoryEventDto.FromHistoryEvent).ToList();
return Ok(response);
}
}
}