// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using NodaTime;
using Squidex.Domain.Apps.Entities.Backup;
using Squidex.Infrastructure.Reflection;
using Squidex.Shared;
using Squidex.Web;
namespace Squidex.Areas.Api.Controllers.Backups.Models
{
public sealed class BackupJobDto : Resource
{
///
/// The id of the backup job.
///
public Guid Id { get; set; }
///
/// The time when the job has been started.
///
public Instant Started { get; set; }
///
/// The time when the job has been stopped.
///
public Instant? Stopped { get; set; }
///
/// The number of handled events.
///
public int HandledEvents { get; set; }
///
/// The number of handled assets.
///
public int HandledAssets { get; set; }
///
/// The status of the operation.
///
public JobStatus Status { get; set; }
public static BackupJobDto FromBackup(IBackupJob backup, ApiController controller, string app)
{
var result = SimpleMapper.Map(backup, new BackupJobDto());
return result.CreateLinks(controller, app);
}
private BackupJobDto CreateLinks(ApiController controller, string app)
{
var values = new { app, id = Id };
if (controller.HasPermission(Permissions.AppBackupsDelete, app))
{
AddDeleteLink("delete", controller.Url(x => nameof(x.DeleteBackup), values));
}
return this;
}
}
}