Skip to content

Commit

Permalink
chore: Add TransmissionId relation to Activity (#950)
Browse files Browse the repository at this point in the history
Missed relation in  #858 PR ( #919 )
  • Loading branch information
oskogstad authored Jul 31, 2024
1 parent 7c1282e commit 5302e9f
Show file tree
Hide file tree
Showing 21 changed files with 1,926 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Activity {
extendedType: URL
type: ActivityType!
relatedActivityId: UUID
transmissionId: UUID
performedBy: Actor!
description: [Localization!]!
}
Expand Down
36 changes: 36 additions & 0 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"ExtendedType": null,
"Type": 3,
"RelatedActivityId": null,
"TransmissionId": null,
"PerformedBy": {
"ActorType": 2,
"ActorName": null,
Expand Down Expand Up @@ -2850,6 +2851,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/UpdateDialogDialogActivityPerformedByActorDto"
},
Expand Down Expand Up @@ -3024,6 +3030,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/SearchDialogDialogActivityPerformedByActorDtoSO"
},
Expand Down Expand Up @@ -3590,6 +3601,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/GetDialogDialogActivityPerformedByActorDtoSO"
},
Expand Down Expand Up @@ -4079,6 +4095,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/CreateDialogDialogActivityPerformedByActorDto"
},
Expand Down Expand Up @@ -4134,6 +4155,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/UpdateDialogDialogActivityPerformedByActorDto"
},
Expand Down Expand Up @@ -4389,6 +4415,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/SearchDialogDialogActivityPerformedByActorDto"
},
Expand Down Expand Up @@ -4945,6 +4976,11 @@
"format": "guid",
"nullable": true
},
"transmissionId": {
"type": "string",
"format": "guid",
"nullable": true
},
"performedBy": {
"$ref": "#/components/schemas/GetDialogDialogActivityPerformedByActorDto"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class GetDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public GetDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public sealed class SearchDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public sealed class GetDialogDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public GetDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed class SearchDialogDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public SearchDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class GetDialogActivityDto
public DateTimeOffset? DeletedAt { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public GetDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public sealed class SearchDialogActivityDto
public DateTimeOffset? DeletedAt { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public CreateDialogCommandValidator(
RuleFor(x => x.Activities)
.UniqueBy(x => x.Id);
RuleForEach(x => x.Activities)
.IsIn(x => x.Transmissions,
dependentKeySelector: activity => activity.TransmissionId,
principalKeySelector: transmission => transmission.Id)
.IsIn(x => x.Activities,
dependentKeySelector: activity => activity.RelatedActivityId,
principalKeySelector: activity => activity.Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public sealed class CreateDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public Guid? TransmissionId { get; set; }

public CreateDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
VerifyActivityRelations(dialog);

AppendTransmission(dialog, request.Dto);
VerifyActivityTransmissionRelations(dialog);
VerifyTransmissionRelations(dialog);

dialog.SearchTags
Expand Down Expand Up @@ -225,6 +226,33 @@ private void AppendActivity(DialogEntity dialog, UpdateDialogDto dto)
_db.DialogActivities.AddRange(newDialogActivities);
}

private void VerifyActivityTransmissionRelations(DialogEntity dialog)
{
var relatedTransmissionIds = dialog.Activities
.Where(x => x.TransmissionId is not null)
.Select(x => x.TransmissionId)
.ToList();

if (relatedTransmissionIds.Count == 0)
{
return;
}

var transmissionIds = dialog.Transmissions.Select(x => x.Id).ToList();

var invalidTransmissionIds = relatedTransmissionIds
.Where(id => !transmissionIds.Contains(id!.Value))
.ToList();

if (invalidTransmissionIds.Count != 0)
{
_domainContext.AddError(
nameof(UpdateDialogDto.Activities),
$"Invalid '{nameof(DialogActivity.TransmissionId)}, entity '{nameof(DialogTransmission)}'" +
$" with the following key(s) does not exist: ({string.Join(", ", invalidTransmissionIds)}) in '{nameof(dialog.Transmissions)}'");
}
}

private void VerifyActivityRelations(DialogEntity dialog)
{
var relatedActivityIds = dialog.Activities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class UpdateDialogDialogActivityDto

public Guid? RelatedActivityId { get; set; }

public Guid? TransmissionId { get; set; }

public UpdateDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public sealed class GetDialogDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public GetDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public sealed class SearchDialogDialogActivityDto
public DialogActivityType.Values Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public SearchDialogDialogActivityPerformedByActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities;
using Digdir.Domain.Dialogporten.Domain.Localizations;
using Digdir.Library.Entity.Abstractions.Features.Aggregate;
Expand All @@ -23,6 +24,9 @@ public class DialogActivity : IImmutableEntity, IAggregateCreatedHandler, IEvent
public Guid? RelatedActivityId { get; set; }
public DialogActivity? RelatedActivity { get; set; }

public Guid? TransmissionId { get; set; }
public DialogTransmission? Transmission { get; set; }

// === Principal relationships ===
[AggregateChild]
public DialogActivityDescription? Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Contents;
Expand All @@ -19,6 +20,7 @@ public class DialogTransmission : IImmutableEntity
// === Principal relationships ===
public List<TransmissionContent> Content { get; set; } = [];
public List<TransmissionAttachment> Attachments { get; set; } = [];
public List<DialogActivity> Activities { get; set; } = [];
public List<DialogTransmission> RelatedTransmissions { get; set; } = [];

// === Dependent relationships ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed class Activity
public ActivityType Type { get; set; }

public Guid? RelatedActivityId { get; set; }
public Guid? TransmissionId { get; set; }

public Actor PerformedBy { get; set; } = null!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public void Configure(EntityTypeBuilder<DialogActivity> builder)
builder.HasOne(x => x.RelatedActivity)
.WithMany(x => x.RelatedActivities)
.OnDelete(DeleteBehavior.SetNull);

builder.HasOne(x => x.Transmission)
.WithMany(x => x.Activities)
.OnDelete(DeleteBehavior.SetNull);
}
}
Loading

0 comments on commit 5302e9f

Please sign in to comment.