Skip to content

Commit

Permalink
feat(webapi): Combine actorDtos (#1374)
Browse files Browse the repository at this point in the history
## Description

Replaced all actorDtos with one common enduser actordto, and one common
serivceowner actordto

## Related Issue(s)


## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] Manual testing done (required)
- [x] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a unified `ActorDto` for actor representation across
various components, replacing multiple specific actor DTOs.
- Added validation for `ActorDto` to ensure proper data integrity based
on actor type.

- **Bug Fixes**
- Updated mappings and properties to reflect the new actor structure,
enhancing data consistency across the application.

- **Documentation**
- Updated Swagger configuration to reflect changes in actor
representation.

- **Tests**
- Added comprehensive unit tests for the new `ActorValidator` to ensure
validation rules are correctly enforced.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Amund Myrbostad <amund.myrbostad@digdir.no>
Co-authored-by: Magnus Sandgren <5285192+MagnusSandgren@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent e79dbfa commit ca18a99
Show file tree
Hide file tree
Showing 49 changed files with 377 additions and 1,184 deletions.
640 changes: 79 additions & 561 deletions docs/schema/V1/swagger.verified.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Digdir.Domain.Dialogporten.Domain.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;

public sealed class ActorDto
{
/// <summary>
/// The type of actor that sent the transmission.
/// </summary>
public ActorType.Values ActorType { get; set; }

/// <summary>
/// Specifies the name of the entity that sent the transmission. Mutually exclusive with ActorId. If ActorId
/// is supplied, the name will be automatically populated from the name registries.
/// </summary>
/// <example>Ola Nordmann</example>
public string? ActorName { get; set; }

/// <summary>
/// The identifier of the person or organization that sent the transmission. Mutually exclusive with ActorName.
/// Might be omitted if ActorType is "ServiceOwner".
/// </summary>
/// <example>urn:altinn:person:identifier-no:12018212345</example>
public string? ActorId { get; set; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain;
using Digdir.Domain.Dialogporten.Domain.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;

internal sealed class MappingProfile : Profile
{
public MappingProfile()
{

var actorDtoType = typeof(ActorDto);
var actorType = typeof(Actor);

var derivedActorTypes = DomainAssemblyMarker
.Assembly
.GetTypes()
.Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(actorType))
.ToList();

CreateMap<Actor, ActorDto>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId))
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));

foreach (var outputActor in derivedActorTypes)
{
CreateMap(outputActor, actorDtoType)
.IncludeBase(actorType, actorDtoType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Actors;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Get;
Expand All @@ -14,14 +14,6 @@ public sealed class ActivityDto

public Guid? TransmissionId { get; set; }

public PerformedByActorDto PerformedBy { get; set; } = null!;
public ActorDto PerformedBy { get; set; } = null!;
public List<LocalizationDto> Description { get; set; } = [];
}

public sealed class PerformedByActorDto
{
public Guid Id { get; set; }
public ActorType.Values ActorType { get; set; }
public string? ActorName { get; set; }
public string? ActorId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Get;
Expand All @@ -11,8 +10,5 @@ public MappingProfile()
CreateMap<DialogActivity, ActivityDto>()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId));

CreateMap<DialogActivityPerformedByActor, PerformedByActorDto>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId))
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogLabelAssignmentLog.Queries.Search;

public sealed class LabelAssignmentLogDto
Expand All @@ -8,14 +10,6 @@ public sealed class LabelAssignmentLogDto

public string Action { get; set; } = null!;

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

}

public sealed class LabelAssignmentLogActorDto
{

public string ActorName { get; set; } = null!;
public ActorDto PerformedBy { get; set; } = null!;

public string ActorId { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public sealed class MappingProfile : Profile
public MappingProfile()
{
CreateMap<LabelAssignmentLog, LabelAssignmentLogDto>();
CreateMap<LabelAssignmentLogActor, LabelAssignmentLogActorDto>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Get;
Expand All @@ -11,8 +10,5 @@ public MappingProfile()
CreateMap<DialogSeenLog, SeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogSeenLogSeenByActor, SeenLogSeenByActorDto>()
.ForMember(dest => dest.ActorId,
opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Get;

public sealed class SeenLogDto
{
public Guid Id { get; set; }
public DateTimeOffset SeenAt { get; set; }
public SeenLogSeenByActorDto SeenBy { get; set; } = null!;
public ActorDto SeenBy { get; set; } = null!;

public bool IsViaServiceOwner { get; set; }
public bool IsCurrentEndUser { get; set; }
}

public sealed class SeenLogSeenByActorDto
{
public Guid Id { get; set; }
public string ActorName { get; set; } = null!;
public string ActorId { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoMapper;
using Digdir.Domain.Dialogporten.Application.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Search;
Expand All @@ -11,7 +10,5 @@ public MappingProfile()
CreateMap<DialogSeenLog, SeenLogDto>()
.ForMember(dest => dest.SeenAt, opt => opt.MapFrom(src => src.CreatedAt));

CreateMap<DialogSeenLogSeenByActor, SeenLogSeenByActorDto>()
.ForMember(dest => dest.ActorId, opt => opt.MapFrom(src => IdentifierMasker.GetMaybeMaskedIdentifier(src.ActorId)));
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogSeenLogs.Queries.Search;

public sealed class SeenLogDto
{
public Guid Id { get; set; }
public DateTimeOffset SeenAt { get; set; }

public SeenLogSeenByActorDto SeenBy { get; set; } = null!;
public ActorDto SeenBy { get; set; } = null!;

public bool IsViaServiceOwner { get; set; }
public bool IsCurrentEndUser { get; set; }
}

public sealed class SeenLogSeenByActorDto
{
public Guid Id { get; set; }
public string ActorName { get; set; } = null!;
public string ActorId { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public MappingProfile()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId))
.ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt));

CreateMap<DialogTransmissionSenderActor, SenderActorDto>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId));

CreateMap<List<DialogTransmissionContent>?, ContentDto?>()
.ConvertUsing<TransmissionContentOutputConverter<ContentDto>>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Actors;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;
using Digdir.Domain.Dialogporten.Domain.Attachments;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;

Expand Down Expand Up @@ -52,7 +52,7 @@ public sealed class TransmissionDto
/// <summary>
/// The sender actor information for the transmission.
/// </summary>
public SenderActorDto Sender { get; set; } = null!;
public ActorDto Sender { get; set; } = null!;

/// <summary>
/// The content of the transmission.
Expand All @@ -65,29 +65,6 @@ public sealed class TransmissionDto
public List<AttachmentDto> Attachments { get; set; } = [];
}

public sealed class SenderActorDto
{
/// <summary>
/// The unique identifier for the sender actor in UUIDv7 format.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// The type of the actor.
/// </summary>
public ActorType.Values ActorType { get; set; }

/// <summary>
/// The name of the actor.
/// </summary>
public string ActorName { get; set; } = null!;

/// <summary>
/// The identifier of the actor.
/// </summary>
public string ActorId { get; set; } = null!;
}

public sealed class ContentDto
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public MappingProfile()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId))
.ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt));

CreateMap<DialogTransmissionSenderActor, SenderActorDto>()
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId));

CreateMap<List<DialogTransmissionContent>?, ContentDto?>()
.ConvertUsing<TransmissionContentOutputConverter<ContentDto>>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content;
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations;
using Digdir.Domain.Dialogporten.Domain.Actors;
using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Common.Actors;
using Digdir.Domain.Dialogporten.Domain.Attachments;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;

Expand Down Expand Up @@ -52,7 +52,7 @@ public sealed class TransmissionDto
/// <summary>
/// The sender actor information for the transmission.
/// </summary>
public SenderActorDto Sender { get; set; } = null!;
public ActorDto Sender { get; set; } = null!;

/// <summary>
/// The content of the transmission.
Expand All @@ -65,29 +65,6 @@ public sealed class TransmissionDto
public List<AttachmentDto> Attachments { get; set; } = [];
}

public sealed class SenderActorDto
{
/// <summary>
/// The unique identifier for the sender actor in UUIDv7 format.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// The type of the actor.
/// </summary>
public ActorType.Values ActorType { get; set; }

/// <summary>
/// The name of the actor.
/// </summary>
public string ActorName { get; set; } = null!;

/// <summary>
/// The identifier of the actor.
/// </summary>
public string ActorId { get; set; } = null!;
}

public sealed class ContentDto
{
/// <summary>
Expand Down
Loading

0 comments on commit ca18a99

Please sign in to comment.