Browse Source

Plan.

pull/282/head
Sebastian Stehle 8 years ago
parent
commit
641cdc84b2
  1. 19
      src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs
  2. 20
      src/Squidex/Areas/Api/Controllers/Plans/Models/AppPlansDto.cs
  3. 7
      src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs
  4. 7
      src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs

19
src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs

@ -5,15 +5,12 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations; using NSwag.Annotations;
using Squidex.Areas.Api.Controllers.Plans.Models; using Squidex.Areas.Api.Controllers.Plans.Models;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Domain.Apps.Entities.Apps.Services; using Squidex.Domain.Apps.Entities.Apps.Services;
using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Commands;
using Squidex.Infrastructure.Reflection;
using Squidex.Pipeline; using Squidex.Pipeline;
namespace Squidex.Areas.Api.Controllers.Plans namespace Squidex.Areas.Api.Controllers.Plans
@ -54,16 +51,9 @@ namespace Squidex.Areas.Api.Controllers.Plans
[ApiCosts(0)] [ApiCosts(0)]
public IActionResult GetPlans(string app) public IActionResult GetPlans(string app)
{ {
var planId = appPlansProvider.GetPlanForApp(App).Id; var hasPortal = appPlansBillingManager.HasPortal;
var plans = appPlansProvider.GetAvailablePlans().Select(x => SimpleMapper.Map(x, new PlanDto())).ToList();
var response = new AppPlansDto var response = AppPlansDto.FromApp(App, appPlansProvider, hasPortal);
{
CurrentPlanId = planId,
Plans = plans,
PlanOwner = App.Plan?.Owner.Identifier,
HasPortal = appPlansBillingManager.HasPortal
};
Response.Headers["ETag"] = App.Version.ToString(); Response.Headers["ETag"] = App.Version.ToString();
@ -89,8 +79,9 @@ namespace Squidex.Areas.Api.Controllers.Plans
[ApiCosts(0)] [ApiCosts(0)]
public async Task<IActionResult> ChangePlanAsync(string app, [FromBody] ChangePlanDto request) public async Task<IActionResult> ChangePlanAsync(string app, [FromBody] ChangePlanDto request)
{ {
var redirectUri = (string)null; var context = await CommandBus.PublishAsync(request.ToCommand());
var context = await CommandBus.PublishAsync(SimpleMapper.Map(request, new ChangePlan()));
string redirectUri = null;
if (context.Result<object>() is RedirectToCheckoutResult result) if (context.Result<object>() is RedirectToCheckoutResult result)
{ {

20
src/Squidex/Areas/Api/Controllers/Plans/Models/AppPlansDto.cs

@ -5,7 +5,11 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Domain.Apps.Entities.Apps.Services;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Squidex.Areas.Api.Controllers.Plans.Models namespace Squidex.Areas.Api.Controllers.Plans.Models
{ {
@ -14,6 +18,7 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models
/// <summary> /// <summary>
/// The available plans. /// The available plans.
/// </summary> /// </summary>
[Required]
public List<PlanDto> Plans { get; set; } public List<PlanDto> Plans { get; set; }
/// <summary> /// <summary>
@ -30,5 +35,20 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models
/// Indicates if there is a billing portal. /// Indicates if there is a billing portal.
/// </summary> /// </summary>
public bool HasPortal { get; set; } public bool HasPortal { get; set; }
public static AppPlansDto FromApp(IAppEntity app, IAppPlansProvider plans, bool hasPortal)
{
var planId = plans.GetPlanForApp(app).Id;
var response = new AppPlansDto
{
CurrentPlanId = planId,
Plans = plans.GetAvailablePlans().Select(PlanDto.FromPlan).ToList(),
PlanOwner = app.Plan?.Owner.Identifier,
HasPortal = hasPortal
};
return response;
}
} }
} }

7
src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs

@ -6,6 +6,8 @@
// ========================================================================== // ==========================================================================
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Areas.Api.Controllers.Plans.Models namespace Squidex.Areas.Api.Controllers.Plans.Models
{ {
@ -16,5 +18,10 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models
/// </summary> /// </summary>
[Required] [Required]
public string PlanId { get; set; } public string PlanId { get; set; }
public ChangePlan ToCommand()
{
return SimpleMapper.Map(this, new ChangePlan());
}
} }
} }

7
src/Squidex/Areas/Api/Controllers/Plans/Models/PlanDto.cs

@ -5,6 +5,8 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using Squidex.Domain.Apps.Entities.Apps.Services;
using Squidex.Infrastructure.Reflection;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Squidex.Areas.Api.Controllers.Plans.Models namespace Squidex.Areas.Api.Controllers.Plans.Models
@ -53,5 +55,10 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models
/// The maximum number of contributors. /// The maximum number of contributors.
/// </summary> /// </summary>
public int MaxContributors { get; set; } public int MaxContributors { get; set; }
public static PlanDto FromPlan(IAppLimitsPlan plan)
{
return SimpleMapper.Map(plan, new PlanDto());
}
} }
} }

Loading…
Cancel
Save