Skip to content

Commit

Permalink
Rest cleanup (#189)
Browse files Browse the repository at this point in the history
Refactor after new REST apis
  • Loading branch information
MartinSchmidt authored Jan 4, 2024
1 parent d98eb70 commit 0befe68
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,21 +666,25 @@
"properties": {
"start": {
"type": "integer",
"description": "The start of the aggregated period.",
"format": "int64"
},
"end": {
"type": "integer",
"description": "The end of the aggregated period.",
"format": "int64"
},
"quantity": {
"type": "integer",
"description": "The quantity of the aggregated certificates.",
"format": "int64"
},
"type": {
"$ref": "#/components/schemas/CertificateType"
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "A result of aggregated certificates that is available to use in the wallet."
},
"AggregatedCertificatesResultList": {
"type": "object",
Expand Down Expand Up @@ -945,18 +949,22 @@
},
"quantity": {
"type": "integer",
"description": "The quantity available on the certificate.",
"format": "int32"
},
"start": {
"type": "integer",
"description": "The start of the certificate.",
"format": "int64"
},
"end": {
"type": "integer",
"description": "The end of the certificate.",
"format": "int64"
},
"gridArea": {
"type": "string"
"type": "string",
"description": "The Grid Area of the certificate."
},
"certificateType": {
"$ref": "#/components/schemas/CertificateType"
Expand All @@ -965,10 +973,12 @@
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"description": "The attributes of the certificate."
}
},
"additionalProperties": false
"additionalProperties": false,
"description": "A certificate that is available to use in the wallet."
},
"GranularCertificateResultList": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void Invalid_PrivateKey()
hdPrivateKey.Should().BeNull();
}


[Fact]
public void Valid_PublicKey()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -92,3 +93,75 @@ public async Task<ActionResult<ResultList<AggregatedCertificates>>> AggregateCer
};
}
}

#region Records

/// <summary>
/// A certificate that is available to use in the wallet.
/// </summary>
public record GranularCertificate()
{
/// <summary>
/// The id of the certificate.
/// </summary>
public required FederatedStreamId FederatedStreamId { get; init; }

/// <summary>
/// The quantity available on the certificate.
/// </summary>
public required uint Quantity { get; init; }

/// <summary>
/// The start of the certificate.
/// </summary>
public required long Start { get; init; }

/// <summary>
/// The end of the certificate.
/// </summary>
public required long End { get; init; }

/// <summary>
/// The Grid Area of the certificate.
/// </summary>
public required string GridArea { get; init; }

/// <summary>
/// The type of certificate (production or consumption).
/// </summary>
public required CertificateType CertificateType { get; init; }

/// <summary>
/// The attributes of the certificate.
/// </summary>
public required Dictionary<string, string> Attributes { get; init; }
}


/// <summary>
/// A result of aggregated certificates that is available to use in the wallet.
/// </summary>
public record AggregatedCertificates()
{
/// <summary>
/// The start of the aggregated period.
/// </summary>
public required long Start { get; init; }

/// <summary>
/// The end of the aggregated period.
/// </summary>
public required long End { get; init; }

/// <summary>
/// The quantity of the aggregated certificates.
/// </summary>
public required long Quantity { get; init; }

/// <summary>
/// The type of the aggregated certificates.
/// </summary>
public required CertificateType Type { get; init; }
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ProjectOrigin.WalletSystem.Server.Services.REST.v1;

public static class MapperV1
public static class MappingExtensions
{
public static CertificateType MapToV1(this GranularCertificateType granularCertificateType) =>
granularCertificateType switch
Expand Down
40 changes: 0 additions & 40 deletions src/ProjectOrigin.WalletSystem.Server/Services/REST/v1/ModelsV1.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System;
using System.Text.Json.Serialization;

namespace ProjectOrigin.WalletSystem.Server.Services.REST.v1;

public record ResultList<T>()
{
public required IEnumerable<T> Result { get; init; }
}

public enum CertificateType
{
Consumption = 1,
Production = 2
}

public record FederatedStreamId()
{
public required string Registry { get; init; }
public required Guid StreamId { get; init; }
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TimeAggregate
{
Actual = 0,
Total = 1,
Year = 2,
Month = 3,
Week = 4,
Day = 5,
Hour = 6,
QuarterHour = 7,
}

0 comments on commit 0befe68

Please sign in to comment.