Browse Source

Renamings.

pull/491/head
Sebastian 6 years ago
parent
commit
61b307cba0
  1. 3
      backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/ConfigAppPlansProvider.cs
  2. 13
      backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsageDtoDto.cs
  3. 6
      backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsagePerDateDto.cs
  4. 6
      backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/StorageUsagePerDateDto.cs
  5. 9
      backend/src/Squidex/Areas/Api/Controllers/Statistics/UsagesController.cs
  6. 2
      backend/src/Squidex/Config/Web/WebServices.cs
  7. 9
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/ConfigAppLimitsProviderTests.cs
  8. 14
      frontend/app/framework/angular/http/http-extensions.ts
  9. 20
      frontend/app/shared/services/usages.service.spec.ts
  10. 22
      frontend/app/shared/services/usages.service.ts

3
backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/ConfigAppPlansProvider.cs

@ -20,7 +20,8 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
Name = "Infinite", Name = "Infinite",
MaxApiCalls = -1, MaxApiCalls = -1,
MaxAssetSize = -1, MaxAssetSize = -1,
MaxContributors = -1 MaxContributors = -1,
BlockingApiCalls = -1
}; };
private readonly Dictionary<string, ConfigAppLimitsPlan> plansById = new Dictionary<string, ConfigAppLimitsPlan>(StringComparer.OrdinalIgnoreCase); private readonly Dictionary<string, ConfigAppLimitsPlan> plansById = new Dictionary<string, ConfigAppLimitsPlan>(StringComparer.OrdinalIgnoreCase);

13
backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/ApiUsagesDto.cs → backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsageDtoDto.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@ -13,7 +12,7 @@ using Squidex.Infrastructure.UsageTracking;
namespace Squidex.Areas.Api.Controllers.Statistics.Models namespace Squidex.Areas.Api.Controllers.Statistics.Models
{ {
public sealed class ApiUsagesDto public sealed class CallsUsageDtoDto
{ {
/// <summary> /// <summary>
/// The total number of API calls. /// The total number of API calls.
@ -39,17 +38,17 @@ namespace Squidex.Areas.Api.Controllers.Statistics.Models
/// The statistics by date and group. /// The statistics by date and group.
/// </summary> /// </summary>
[Required] [Required]
public Dictionary<string, ApiUsageDto[]> Details { get; set; } public Dictionary<string, CallsUsagePerDateDto[]> Details { get; set; }
public static ApiUsagesDto FromStats(long allowedCalls, ApiStatsSummary summary, Dictionary<string, List<ApiStats>> details) public static CallsUsageDtoDto FromStats(long allowedCalls, ApiStatsSummary summary, Dictionary<string, List<ApiStats>> details)
{ {
return new ApiUsagesDto return new CallsUsageDtoDto
{ {
AllowedCalls = allowedCalls, AllowedCalls = allowedCalls,
AverageElapsedMs = summary.AverageElapsedMs, AverageElapsedMs = summary.AverageElapsedMs,
TotalBytes = summary.TotalBytes, TotalBytes = summary.TotalBytes,
TotalCalls = summary.TotalBytes, TotalCalls = summary.TotalCalls,
Details = details.ToDictionary(x => x.Key, x => x.Value.Select(ApiUsageDto.FromStats).ToArray()) Details = details.ToDictionary(x => x.Key, x => x.Value.Select(CallsUsagePerDateDto.FromStats).ToArray())
}; };
} }
} }

6
backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/ApiUsageDto.cs → backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/CallsUsagePerDateDto.cs

@ -10,7 +10,7 @@ using Squidex.Infrastructure.UsageTracking;
namespace Squidex.Areas.Api.Controllers.Statistics.Models namespace Squidex.Areas.Api.Controllers.Statistics.Models
{ {
public sealed class ApiUsageDto public sealed class CallsUsagePerDateDto
{ {
/// <summary> /// <summary>
/// The date when the usage was tracked. /// The date when the usage was tracked.
@ -32,9 +32,9 @@ namespace Squidex.Areas.Api.Controllers.Statistics.Models
/// </summary> /// </summary>
public double AverageElapsedMs { get; set; } public double AverageElapsedMs { get; set; }
public static ApiUsageDto FromStats(ApiStats stats) public static CallsUsagePerDateDto FromStats(ApiStats stats)
{ {
var result = new ApiUsageDto var result = new CallsUsagePerDateDto
{ {
Date = stats.Date, Date = stats.Date,
TotalBytes = stats.TotalBytes, TotalBytes = stats.TotalBytes,

6
backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/StorageUsageDto.cs → backend/src/Squidex/Areas/Api/Controllers/Statistics/Models/StorageUsagePerDateDto.cs

@ -10,7 +10,7 @@ using Squidex.Domain.Apps.Entities.Assets;
namespace Squidex.Areas.Api.Controllers.Statistics.Models namespace Squidex.Areas.Api.Controllers.Statistics.Models
{ {
public sealed class StorageUsageDto public sealed class StorageUsagePerDateDto
{ {
/// <summary> /// <summary>
/// The date when the usage was tracked. /// The date when the usage was tracked.
@ -27,9 +27,9 @@ namespace Squidex.Areas.Api.Controllers.Statistics.Models
/// </summary> /// </summary>
public long TotalSize { get; set; } public long TotalSize { get; set; }
public static StorageUsageDto FromStats(AssetStats stats) public static StorageUsagePerDateDto FromStats(AssetStats stats)
{ {
var result = new StorageUsageDto var result = new StorageUsagePerDateDto
{ {
Date = stats.Date, Date = stats.Date,
TotalCount = stats.TotalCount, TotalCount = stats.TotalCount,

9
backend/src/Squidex/Areas/Api/Controllers/Statistics/UsagesController.cs

@ -6,7 +6,6 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
@ -93,7 +92,7 @@ namespace Squidex.Areas.Api.Controllers.Statistics
/// </returns> /// </returns>
[HttpGet] [HttpGet]
[Route("apps/{app}/usages/calls/{fromDate}/{toDate}/")] [Route("apps/{app}/usages/calls/{fromDate}/{toDate}/")]
[ProducesResponseType(typeof(ApiUsagesDto), 200)] [ProducesResponseType(typeof(CallsUsageDtoDto), 200)]
[ApiPermission(Permissions.AppCommon)] [ApiPermission(Permissions.AppCommon)]
[ApiCosts(0)] [ApiCosts(0)]
public async Task<IActionResult> GetUsages(string app, DateTime fromDate, DateTime toDate) public async Task<IActionResult> GetUsages(string app, DateTime fromDate, DateTime toDate)
@ -107,7 +106,7 @@ namespace Squidex.Areas.Api.Controllers.Statistics
var (plan, _) = appPlansProvider.GetPlanForApp(App); var (plan, _) = appPlansProvider.GetPlanForApp(App);
var response = ApiUsagesDto.FromStats(plan.MaxApiCalls, summary, details); var response = CallsUsageDtoDto.FromStats(plan.MaxApiCalls, summary, details);
return Ok(response); return Ok(response);
} }
@ -149,7 +148,7 @@ namespace Squidex.Areas.Api.Controllers.Statistics
/// </returns> /// </returns>
[HttpGet] [HttpGet]
[Route("apps/{app}/usages/storage/{fromDate}/{toDate}/")] [Route("apps/{app}/usages/storage/{fromDate}/{toDate}/")]
[ProducesResponseType(typeof(StorageUsageDto[]), 200)] [ProducesResponseType(typeof(StorageUsagePerDateDto[]), 200)]
[ApiPermission(Permissions.AppCommon)] [ApiPermission(Permissions.AppCommon)]
[ApiCosts(0)] [ApiCosts(0)]
public async Task<IActionResult> GetStorageSizes(string app, DateTime fromDate, DateTime toDate) public async Task<IActionResult> GetStorageSizes(string app, DateTime fromDate, DateTime toDate)
@ -161,7 +160,7 @@ namespace Squidex.Areas.Api.Controllers.Statistics
var usages = await assetStatsRepository.QueryAsync(AppId, fromDate.Date, toDate.Date); var usages = await assetStatsRepository.QueryAsync(AppId, fromDate.Date, toDate.Date);
var models = usages.Select(StorageUsageDto.FromStats).ToArray(); var models = usages.Select(StorageUsagePerDateDto.FromStats).ToArray();
return Ok(models); return Ok(models);
} }

2
backend/src/Squidex/Config/Web/WebServices.cs

@ -11,8 +11,6 @@ using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Squidex.Areas.Frontend.Middlewares;
using Squidex.Areas.OrleansDashboard.Middlewares;
using Squidex.Config.Domain; using Squidex.Config.Domain;
using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities;
using Squidex.Infrastructure.Caching; using Squidex.Infrastructure.Caching;

9
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/ConfigAppLimitsProviderTests.cs

@ -22,7 +22,8 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
Name = "Infinite", Name = "Infinite",
MaxApiCalls = -1, MaxApiCalls = -1,
MaxAssetSize = -1, MaxAssetSize = -1,
MaxContributors = -1 MaxContributors = -1,
BlockingApiCalls = -1
}; };
private static readonly ConfigAppLimitsPlan FreePlan = new ConfigAppLimitsPlan private static readonly ConfigAppLimitsPlan FreePlan = new ConfigAppLimitsPlan
@ -31,7 +32,8 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
Name = "Free", Name = "Free",
MaxApiCalls = 50000, MaxApiCalls = 50000,
MaxAssetSize = 1024 * 1024 * 10, MaxAssetSize = 1024 * 1024 * 10,
MaxContributors = 2 MaxContributors = 2,
BlockingApiCalls = 50000
}; };
private static readonly ConfigAppLimitsPlan BasicPlan = new ConfigAppLimitsPlan private static readonly ConfigAppLimitsPlan BasicPlan = new ConfigAppLimitsPlan
@ -42,7 +44,8 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
MaxAssetSize = 1024 * 1024 * 2, MaxAssetSize = 1024 * 1024 * 2,
MaxContributors = 5, MaxContributors = 5,
YearlyCosts = "100€", YearlyCosts = "100€",
YearlyId = "basic_yearly" YearlyId = "basic_yearly",
BlockingApiCalls = 150000
}; };
private static readonly ConfigAppLimitsPlan[] Plans = { BasicPlan, FreePlan }; private static readonly ConfigAppLimitsPlan[] Plans = { BasicPlan, FreePlan };

14
frontend/app/framework/angular/http/http-extensions.ts

@ -100,10 +100,16 @@ export const pretifyError = (message: string) => <T>(source: Observable<T>) =>
errorDto = { message: 'Failed to make the request.', details: [] }; errorDto = { message: 'Failed to make the request.', details: [] };
} }
if (response.status === 412) { switch (response.status) {
result = new ErrorDto(response.status, 'Failed to make the update. Another user has made a change. Please reload.', [], response); case 412:
} else if (response.status !== 500) { result = new ErrorDto(response.status, 'Failed to make the update. Another user has made a change. Please reload.', [], response);
result = new ErrorDto(response.status, errorDto.message, errorDto.details, response); break;
case 429:
result = new ErrorDto(response.status, 'You have exceeded the maximum limit of API calls.', [], response);
break;
case 500:
result = new ErrorDto(response.status, errorDto.message, errorDto.details, response);
break;
} }
} catch (e) { } catch (e) {
result = new ErrorDto(500, 'Failed to make the request.', [], response); result = new ErrorDto(500, 'Failed to make the request.', [], response);

20
frontend/app/shared/services/usages.service.spec.ts

@ -10,11 +10,11 @@ import { inject, TestBed } from '@angular/core/testing';
import { import {
ApiUrlConfig, ApiUrlConfig,
ApiUsageDto, CallsUsageDto,
ApiUsagesDto, CallsUsagePerDateDto,
CurrentStorageDto, CurrentStorageDto,
DateTime, DateTime,
StorageUsageDto, StorageUsagePerDateDto,
UsagesService UsagesService
} from '@app/shared/internal'; } from '@app/shared/internal';
@ -38,7 +38,7 @@ describe('UsagesService', () => {
it('should make get request to get calls usages', it('should make get request to get calls usages',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => { inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let usages: ApiUsagesDto; let usages: CallsUsageDto;
usagesService.getCallsUsages('my-app', DateTime.parseISO_UTC('2017-10-12'), DateTime.parseISO_UTC('2017-10-13')).subscribe(result => { usagesService.getCallsUsages('my-app', DateTime.parseISO_UTC('2017-10-12'), DateTime.parseISO_UTC('2017-10-13')).subscribe(result => {
usages = result; usages = result;
@ -73,10 +73,10 @@ describe('UsagesService', () => {
}); });
expect(usages!).toEqual( expect(usages!).toEqual(
new ApiUsagesDto(100, 1024, 40, 12.4, { new CallsUsageDto(100, 1024, 40, 12.4, {
category1: [ category1: [
new ApiUsageDto(DateTime.parseISO_UTC('2017-10-12'), 10, 130, 12.3), new CallsUsagePerDateDto(DateTime.parseISO_UTC('2017-10-12'), 10, 130, 12.3),
new ApiUsageDto(DateTime.parseISO_UTC('2017-10-13'), 13, 170, 33.3) new CallsUsagePerDateDto(DateTime.parseISO_UTC('2017-10-13'), 13, 170, 33.3)
] ]
}) })
); );
@ -85,7 +85,7 @@ describe('UsagesService', () => {
it('should make get request to get storage usages', it('should make get request to get storage usages',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => { inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let usages: ReadonlyArray<StorageUsageDto>; let usages: ReadonlyArray<StorageUsagePerDateDto>;
usagesService.getStorageUsages('my-app', DateTime.parseISO_UTC('2017-10-12'), DateTime.parseISO_UTC('2017-10-13')).subscribe(result => { usagesService.getStorageUsages('my-app', DateTime.parseISO_UTC('2017-10-12'), DateTime.parseISO_UTC('2017-10-13')).subscribe(result => {
usages = result; usages = result;
@ -111,8 +111,8 @@ describe('UsagesService', () => {
expect(usages!).toEqual( expect(usages!).toEqual(
[ [
new StorageUsageDto(DateTime.parseISO_UTC('2017-10-12'), 10, 130), new StorageUsagePerDateDto(DateTime.parseISO_UTC('2017-10-12'), 10, 130),
new StorageUsageDto(DateTime.parseISO_UTC('2017-10-13'), 13, 170) new StorageUsagePerDateDto(DateTime.parseISO_UTC('2017-10-13'), 13, 170)
]); ]);
})); }));

22
frontend/app/shared/services/usages.service.ts

@ -16,18 +16,18 @@ import {
pretifyError pretifyError
} from '@app/framework'; } from '@app/framework';
export class ApiUsagesDto { export class CallsUsageDto {
constructor( constructor(
public readonly allowedCalls: number, public readonly allowedCalls: number,
public readonly totalBytes: number, public readonly totalBytes: number,
public readonly totalCalls: number, public readonly totalCalls: number,
public readonly averageElapsedMs: number, public readonly averageElapsedMs: number,
public readonly details: { [category: string]: ReadonlyArray<ApiUsageDto> } public readonly details: { [category: string]: ReadonlyArray<CallsUsagePerDateDto> }
) { ) {
} }
} }
export class ApiUsageDto { export class CallsUsagePerDateDto {
constructor( constructor(
public readonly date: DateTime, public readonly date: DateTime,
public readonly totalBytes: number, public readonly totalBytes: number,
@ -37,7 +37,7 @@ export class ApiUsageDto {
} }
} }
export class StorageUsageDto { export class StorageUsagePerDateDto {
constructor( constructor(
public readonly date: DateTime, public readonly date: DateTime,
public readonly totalCount: number, public readonly totalCount: number,
@ -82,16 +82,16 @@ export class UsagesService {
pretifyError('Failed to load todays storage size. Please reload.')); pretifyError('Failed to load todays storage size. Please reload.'));
} }
public getCallsUsages(app: string, fromDate: DateTime, toDate: DateTime): Observable<ApiUsagesDto> { public getCallsUsages(app: string, fromDate: DateTime, toDate: DateTime): Observable<CallsUsageDto> {
const url = this.apiUrl.buildUrl(`api/apps/${app}/usages/calls/${fromDate.toUTCStringFormat('YYYY-MM-DD')}/${toDate.toUTCStringFormat('YYYY-MM-DD')}`); const url = this.apiUrl.buildUrl(`api/apps/${app}/usages/calls/${fromDate.toUTCStringFormat('YYYY-MM-DD')}/${toDate.toUTCStringFormat('YYYY-MM-DD')}`);
return this.http.get<any>(url).pipe( return this.http.get<any>(url).pipe(
map(body => { map(body => {
const details: { [category: string]: ApiUsageDto[] } = {}; const details: { [category: string]: CallsUsagePerDateDto[] } = {};
for (let category of Object.keys(body.details)) { for (let category of Object.keys(body.details)) {
details[category] = body.details[category].map((item: any) => details[category] = body.details[category].map((item: any) =>
new ApiUsageDto( new CallsUsagePerDateDto(
DateTime.parseISO_UTC(item.date), DateTime.parseISO_UTC(item.date),
item.totalBytes, item.totalBytes,
item.totalCalls, item.totalCalls,
@ -99,10 +99,10 @@ export class UsagesService {
} }
const usages = const usages =
new ApiUsagesDto( new CallsUsageDto(
body.allowedCalls, body.allowedCalls,
body.totalBytes, body.totalBytes,
body.totalBytes, body.totalCalls,
body.averageElapsedMs, body.averageElapsedMs,
details); details);
@ -111,13 +111,13 @@ export class UsagesService {
pretifyError('Failed to load calls usage. Please reload.')); pretifyError('Failed to load calls usage. Please reload.'));
} }
public getStorageUsages(app: string, fromDate: DateTime, toDate: DateTime): Observable<ReadonlyArray<StorageUsageDto>> { public getStorageUsages(app: string, fromDate: DateTime, toDate: DateTime): Observable<ReadonlyArray<StorageUsagePerDateDto>> {
const url = this.apiUrl.buildUrl(`api/apps/${app}/usages/storage/${fromDate.toUTCStringFormat('YYYY-MM-DD')}/${toDate.toUTCStringFormat('YYYY-MM-DD')}`); const url = this.apiUrl.buildUrl(`api/apps/${app}/usages/storage/${fromDate.toUTCStringFormat('YYYY-MM-DD')}/${toDate.toUTCStringFormat('YYYY-MM-DD')}`);
return this.http.get<any[]>(url).pipe( return this.http.get<any[]>(url).pipe(
map(body => { map(body => {
const usages = body.map(item => const usages = body.map(item =>
new StorageUsageDto( new StorageUsagePerDateDto(
DateTime.parseISO_UTC(item.date), DateTime.parseISO_UTC(item.date),
item.totalCount, item.totalCount,
item.totalSize)); item.totalSize));

Loading…
Cancel
Save