Skip to content

Commit d8ec895

Browse files
authored
Merge branch 'main' into feat/util-apollo-type-narrowing
2 parents 9c161fd + ea23c13 commit d8ec895

File tree

32 files changed

+805
-933
lines changed

32 files changed

+805
-933
lines changed

apps/dh/api-dh/source/DataHub.WebApi.Tests/Snapshots/SchemaTests.ChangeTest.verified.graphql

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type Actor {
6262
glnOrEicNumber: String!
6363
displayName: String!
6464
marketRole: EicFunction!
65-
userRoles: [ActorUserRole!]!
65+
userRoles(userId: UUID): [ActorUserRole!]!
6666
status: ActorStatus!
6767
gridAreas: [GridAreaDto!]!
6868
contact: ActorContactDto
@@ -670,12 +670,6 @@ type MeteringGridAreaImbalanceSearchResult {
670670
outgoingImbalancePerDay: [MeteringGridAreaImbalancePerDayDto!]!
671671
}
672672

673-
type MeteringPointDetails {
674-
meteringPointId: String!
675-
currentCommercialRelation: CommercialRelationDto
676-
currentMeteringPointPeriod: MeteringPointPeriodDto
677-
}
678-
679673
type MeteringPointDto {
680674
meteringPointPeriods("Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String): MeteringPointPeriodsConnection
681675
commercialRelations("Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String): CommercialRelationsConnection
@@ -688,11 +682,13 @@ type MeteringPointDto {
688682
}
689683

690684
type MeteringPointPeriodDto {
685+
gridArea: GridAreaDto
686+
fromGridArea: GridAreaDto
687+
toGridArea: GridAreaDto
691688
id: Long!
692689
validFrom: DateTime!
693690
validTo: DateTime!
694691
createdAt: DateTime!
695-
gridAreaCode: String!
696692
ownedBy: String!
697693
connectionState: ConnectionState!
698694
type: ElectricityMarketMeteringPointType!
@@ -704,8 +700,6 @@ type MeteringPointPeriodDto {
704700
assetType: AssetType!
705701
disconnectionType: DisconnectionType!
706702
fuelType: String!
707-
fromGridAreaCode: String!
708-
toGridAreaCode: String!
709703
meterNumber: String!
710704
meterReadingOccurrence: String!
711705
capacity: String!
@@ -917,7 +911,7 @@ type Query {
917911
userRoles(actorId: UUID): [UserRoleDto!]!
918912
meteringPointWithHistory(filter: String): MeteringPointDto! @authorize(policy: "fas")
919913
meteringPointContactCpr(contactId: Long!): String! @authorize(policy: "fas")
920-
meteringPoint(meteringPointId: String!): MeteringPointDetails! @authorize(policy: "fas")
914+
meteringPoint(meteringPointId: String!): MeteringPointDto! @authorize(policy: "fas")
921915
gridAreas: [GridAreaDto!]!
922916
relevantGridAreas(actorId: UUID period: DateRange!): [GridAreaDto!]!
923917
gridAreaOverviewItemById(gridAreaId: UUID!): GridAreaOverviewItemDto!
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 Energinet DataHub A/S
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License2");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Energinet.DataHub.WebApi.Clients.ElectricityMarket.Import;
16+
17+
public sealed class ElectricityMarketImportClient : IElectricityMarketImportClient
18+
{
19+
private readonly HttpClient _httpClient;
20+
21+
public ElectricityMarketImportClient(HttpClient httpClient)
22+
{
23+
ArgumentNullException.ThrowIfNull(httpClient);
24+
25+
_httpClient = httpClient;
26+
}
27+
28+
public async Task ImportTransactionsAsync(Stream content, CancellationToken cancellationToken)
29+
{
30+
using var request = new HttpRequestMessage(HttpMethod.Post, "import/transactions");
31+
request.Content = new StreamContent(content);
32+
33+
using var response = await _httpClient.SendAsync(request, cancellationToken);
34+
response.EnsureSuccessStatusCode();
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2020 Energinet DataHub A/S
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License2");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Energinet.DataHub.WebApi.Clients.ElectricityMarket.Import;
16+
17+
/// <summary>
18+
/// Provides an interface for importing capacity settlement data.
19+
/// </summary>
20+
public interface IElectricityMarketImportClient
21+
{
22+
/// <summary>
23+
/// Asynchronously imports transactions to Electricity Market.
24+
/// </summary>
25+
/// <param name="content">The stream containing capacity settlement data to be imported.</param>
26+
/// <param name="cancellationToken">A token used to cancel the import operation.</param>
27+
/// <returns>A task that represents the asynchronous import operation.</returns>
28+
Task ImportTransactionsAsync(Stream content, CancellationToken cancellationToken);
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2020 Energinet DataHub A/S
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License2");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Energinet.DataHub.WebApi.Clients.ElectricityMarket.Import;
16+
using Energinet.DataHub.WebApi.Clients.ImbalancePrices.v1;
17+
using Microsoft.AspNetCore.Authorization;
18+
using Microsoft.AspNetCore.Mvc;
19+
20+
namespace Energinet.DataHub.WebApi.Controllers;
21+
22+
[ApiController]
23+
[Route("v1/[controller]")]
24+
public sealed class ElectricityMarketController : ControllerBase
25+
{
26+
private readonly IElectricityMarketImportClient _client;
27+
28+
public ElectricityMarketController(IElectricityMarketImportClient client)
29+
{
30+
_client = client;
31+
}
32+
33+
[HttpPost]
34+
[Route("ImportTransactions")]
35+
[RequestSizeLimit(10485760)]
36+
[Authorize(Policy = "fas")]
37+
public async Task<ActionResult> ImportTransactionsAsync(IFormFile csvFile)
38+
{
39+
try
40+
{
41+
await using var openReadStream = csvFile.OpenReadStream();
42+
await _client.ImportTransactionsAsync(openReadStream, default);
43+
return Ok();
44+
}
45+
catch (ApiException ex)
46+
{
47+
return StatusCode(ex.StatusCode, ex.Response);
48+
}
49+
}
50+
}

apps/dh/api-dh/source/DataHub.WebApi/DataHub.WebApi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ limitations under the License.
5555

5656
<ItemGroup>
5757
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
58-
<PackageReference Include="Energinet.DataHub.ProcessManager.Client" Version="1.3.1" />
59-
<PackageReference Include="Energinet.DataHub.ProcessManager.Orchestrations.Abstractions" Version="1.3.1" />
58+
<PackageReference Include="Energinet.DataHub.ProcessManager.Client" Version="1.4.0" />
59+
<PackageReference Include="Energinet.DataHub.ProcessManager.Orchestrations.Abstractions" Version="1.3.3" />
6060
<PackageReference Include="HotChocolate.AspNetCore" Version="14.2.0" />
6161
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="14.2.0" />
6262
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="14.2.0" />

apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Resolvers/MarketParticipantResolvers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ await client.UserActorsGetAsync(user.Id)).ActorIds
154154
ActorPublicContactByActorId dataLoader) => dataLoader.LoadAsync(actor.ActorId);
155155

156156
public async Task<IEnumerable<ActorUserRole>> GetActorsRolesAsync(
157+
Guid? userId,
157158
[Parent] ActorDto actor,
158-
[ScopedState] IUser? user,
159159
[Service] IMarketParticipantClient_V1 client)
160160
{
161161
var roles = await client.ActorsRolesAsync(actor.ActorId);
162162

163-
if (user is null)
163+
if (userId is null)
164164
{
165165
return roles.Select(r => new ActorUserRole(
166166
r.Id,
@@ -172,7 +172,7 @@ public async Task<IEnumerable<ActorUserRole>> GetActorsRolesAsync(
172172
}
173173

174174
var assignedRoles = await client
175-
.ActorsUsersRolesGetAsync(actor.ActorId, user.Id)
175+
.ActorsUsersRolesGetAsync(actor.ActorId, userId.Value)
176176
.ConfigureAwait(false);
177177

178178
var assignmentLookup = assignedRoles

apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/Actor/ActorType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var actor when string.IsNullOrWhiteSpace(actor.MarketRole.EicFunction.ToString()
5050

5151
descriptor
5252
.Field("userRoles")
53+
.Argument("userId", a => a.Type<UuidType>())
5354
.ResolveWith<MarketParticipantResolvers>(c => c.GetActorsRolesAsync(default!, default!, default!));
5455

5556
descriptor

apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/ElectricityMarketOperations.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
using Energinet.DataHub.WebApi.Clients.ElectricityMarket.v1;
1616
using Energinet.DataHub.WebApi.Extensions;
17-
using Energinet.DataHub.WebApi.GraphQL.Attribute;
18-
using Energinet.DataHub.WebApi.Modules.ElectricityMarket.Types;
1917
using HotChocolate.Authorization;
2018
using MarketParticipantClient = Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
2119

@@ -77,17 +75,12 @@ public static async Task<string> GetMeteringPointContactCprAsync(
7775

7876
[Query]
7977
[Authorize(Policy = "fas")]
80-
public static async Task<MeteringPointDetails> GetMeteringPointAsync(
78+
public static async Task<MeteringPointDto> GetMeteringPointAsync(
8179
string meteringPointId,
8280
CancellationToken ct,
8381
[Service] IElectricityMarketClient_V1 electricityMarketClient)
8482
{
85-
var result = await electricityMarketClient.ElectricityMarketAsync(meteringPointId, ct).ConfigureAwait(false);
86-
87-
return new MeteringPointDetails(
88-
meteringPointId,
89-
result.CurrentCommercialRelation,
90-
result.CurrentMeteringPointPeriod);
83+
return await electricityMarketClient.ElectricityMarketAsync(meteringPointId, ct).ConfigureAwait(false);
9184
}
9285

9386
private static EicFunction FromMarketPartEicFunctionToElectricityMarketEicFunction(

apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/Types/MeteringPointDetails.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/Types/MeteringPointDtoType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
using Energinet.DataHub.WebApi.Clients.ElectricityMarket.v1;
16+
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
1617

1718
namespace Energinet.DataHub.WebApi.Modules.ElectricityMarket.Types;
1819

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2020 Energinet DataHub A/S
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License2");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Energinet.DataHub.WebApi.Clients.ElectricityMarket.v1;
16+
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
17+
18+
namespace Energinet.DataHub.WebApi.Modules.ElectricityMarket.Types;
19+
20+
[ObjectType<MeteringPointPeriodDto>]
21+
public static partial class MeteringPointPeriodDtoType
22+
{
23+
public static async Task<GridAreaDto?> GetGridAreaAsync(
24+
[Parent] MeteringPointPeriodDto meteringPointPeriod,
25+
MarketParticipant.GridAreas.IGridAreaByCodeDataLoader dataLoader) =>
26+
await dataLoader.LoadAsync(meteringPointPeriod.GridAreaCode);
27+
28+
public static async Task<GridAreaDto?> GetFromGridAreaAsync(
29+
[Parent] MeteringPointPeriodDto meteringPointPeriod,
30+
MarketParticipant.GridAreas.IGridAreaByCodeDataLoader dataLoader) =>
31+
await dataLoader.LoadAsync(meteringPointPeriod.FromGridAreaCode);
32+
33+
public static async Task<GridAreaDto?> GetToGridAreaAsync(
34+
[Parent] MeteringPointPeriodDto meteringPointPeriod,
35+
MarketParticipant.GridAreas.IGridAreaByCodeDataLoader dataLoader) =>
36+
await dataLoader.LoadAsync(meteringPointPeriod.ToGridAreaCode);
37+
38+
static partial void Configure(
39+
IObjectTypeDescriptor<MeteringPointPeriodDto> descriptor)
40+
{
41+
descriptor
42+
.Field(f => f.GridAreaCode)
43+
.Ignore();
44+
45+
descriptor
46+
.Field(f => f.FromGridAreaCode)
47+
.Ignore();
48+
49+
descriptor
50+
.Field(f => f.ToGridAreaCode)
51+
.Ignore();
52+
}
53+
}

apps/dh/api-dh/source/DataHub.WebApi/Modules/MarketParticipant/User/UserNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
16+
using Energinet.DataHub.WebApi.GraphQL.Attribute;
1617

1718
namespace Energinet.DataHub.WebApi.Modules.MarketParticipant.User;
1819

0 commit comments

Comments
 (0)