-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(WebAPI): Add Transmission endpoints (#943)
- Loading branch information
Showing
25 changed files
with
1,624 additions
and
278 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...plication/Features/V1/EndUser/DialogTransmissions/Queries/Get/GetDialogTransmissionDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Get; | ||
|
||
public sealed class GetDialogTransmissionDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DateTimeOffset CreatedAt { get; set; } | ||
public string? AuthorizationAttribute { get; set; } | ||
public bool IsAuthorized { get; set; } | ||
public string? ExtendedType { get; set; } | ||
public Guid? RelatedTransmissionId { get; set; } | ||
public DateTimeOffset? DeletedAt { get; set; } | ||
|
||
public DialogTransmissionType.Values Type { get; set; } | ||
|
||
public GetDialogTransmissionSenderActorDto Sender { get; set; } = null!; | ||
|
||
public GetDialogTransmissionContentDto Content { get; set; } = null!; | ||
public List<GetDialogTransmissionAttachmentDto> Attachments { get; set; } = []; | ||
} | ||
|
||
public sealed class GetDialogTransmissionSenderActorDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DialogActorType.Values ActorType { get; set; } | ||
public string ActorName { get; set; } = null!; | ||
public string ActorId { get; set; } = null!; | ||
} | ||
|
||
public sealed class GetDialogTransmissionContentDto | ||
{ | ||
public ContentValueDto Title { get; set; } = null!; | ||
public ContentValueDto Summary { get; set; } = null!; | ||
} | ||
|
||
public sealed class GetDialogTransmissionAttachmentDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public List<LocalizationDto> DisplayName { get; set; } = []; | ||
public List<GetDialogTransmissionAttachmentUrlDto> Urls { get; set; } = []; | ||
} | ||
|
||
public sealed class GetDialogTransmissionAttachmentUrlDto | ||
{ | ||
public Guid Id { get; set; } | ||
public Uri Url { get; set; } = null!; | ||
public string? MediaType { get; set; } = null!; | ||
|
||
public AttachmentUrlConsumerType.Values ConsumerType { get; set; } | ||
} |
71 changes: 71 additions & 0 deletions
71
...ication/Features/V1/EndUser/DialogTransmissions/Queries/Get/GetDialogTransmissionQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using AutoMapper; | ||
using Digdir.Domain.Dialogporten.Application.Common; | ||
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes; | ||
using Digdir.Domain.Dialogporten.Application.Externals; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using OneOf; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Get; | ||
|
||
public sealed class GetDialogTransmissionQuery : IRequest<GetDialogTransmissionResult> | ||
{ | ||
public Guid DialogId { get; set; } | ||
public Guid TransmissionId { get; set; } | ||
} | ||
|
||
[GenerateOneOf] | ||
public partial class GetDialogTransmissionResult : OneOfBase<GetDialogTransmissionDto, EntityNotFound, EntityDeleted>; | ||
|
||
internal sealed class GetDialogTransmissionQueryHandler : IRequestHandler<GetDialogTransmissionQuery, GetDialogTransmissionResult> | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IDialogDbContext _dbContext; | ||
private readonly IUserResourceRegistry _userResourceRegistry; | ||
|
||
public GetDialogTransmissionQueryHandler(IMapper mapper, IDialogDbContext dbContext, IUserResourceRegistry userResourceRegistry) | ||
{ | ||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); | ||
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); | ||
_userResourceRegistry = userResourceRegistry ?? throw new ArgumentNullException(nameof(userResourceRegistry)); | ||
} | ||
|
||
public async Task<GetDialogTransmissionResult> Handle(GetDialogTransmissionQuery request, | ||
CancellationToken cancellationToken) | ||
{ | ||
var dialog = await _dbContext.Dialogs | ||
.Include(x => x.Transmissions.Where(x => x.Id == request.TransmissionId)) | ||
.ThenInclude(x => x.Content) | ||
.ThenInclude(x => x.Value.Localizations) | ||
.Include(x => x.Transmissions.Where(x => x.Id == request.TransmissionId)) | ||
.ThenInclude(x => x.Attachments) | ||
.ThenInclude(x => x.DisplayName!.Localizations) | ||
.Include(x => x.Transmissions.Where(x => x.Id == request.TransmissionId)) | ||
.ThenInclude(x => x.Attachments.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id)) | ||
.ThenInclude(x => x.Urls.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id)) | ||
.Include(x => x.Transmissions) | ||
.ThenInclude(x => x.Sender) | ||
.IgnoreQueryFilters() | ||
.FirstOrDefaultAsync(x => x.Id == request.DialogId, | ||
cancellationToken: cancellationToken); | ||
|
||
if (dialog is null) | ||
{ | ||
return new EntityNotFound<DialogEntity>(request.DialogId); | ||
} | ||
|
||
if (dialog.Deleted) | ||
{ | ||
return new EntityDeleted<DialogEntity>(request.DialogId); | ||
} | ||
|
||
var transmission = dialog.Transmissions.FirstOrDefault(); | ||
|
||
// TODO: Check auth | ||
return transmission is null | ||
? (GetDialogTransmissionResult)new EntityNotFound<DialogTransmission>(request.TransmissionId) | ||
: _mapper.Map<GetDialogTransmissionDto>(transmission); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...gporten.Application/Features/V1/EndUser/DialogTransmissions/Queries/Get/MappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AutoMapper; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Contents; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Get; | ||
|
||
public class MappingProfile : Profile | ||
{ | ||
public MappingProfile() | ||
{ | ||
CreateMap<DialogTransmission, GetDialogTransmissionDto>() | ||
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)) | ||
.ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt)); | ||
|
||
CreateMap<DialogTransmissionSenderActor, GetDialogTransmissionSenderActorDto>() | ||
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId)); | ||
|
||
CreateMap<List<TransmissionContent>?, GetDialogTransmissionContentDto?>() | ||
.ConvertUsing<TransmissionContentOutputConverter<GetDialogTransmissionContentDto>>(); | ||
|
||
CreateMap<TransmissionAttachment, GetDialogTransmissionAttachmentDto>(); | ||
CreateMap<AttachmentUrl, GetDialogTransmissionAttachmentUrlDto>() | ||
.ForMember(dest => dest.ConsumerType, opt => opt.MapFrom(src => src.ConsumerTypeId)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...rten.Application/Features/V1/EndUser/DialogTransmissions/Queries/Search/MappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AutoMapper; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Contents; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Search; | ||
|
||
public class MappingProfile : Profile | ||
{ | ||
public MappingProfile() | ||
{ | ||
CreateMap<DialogTransmission, SearchDialogTransmissionDto>() | ||
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)) | ||
.ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt)); | ||
|
||
CreateMap<DialogTransmissionSenderActor, SearchDialogTransmissionSenderActorDto>() | ||
.ForMember(dest => dest.ActorType, opt => opt.MapFrom(src => src.ActorTypeId)); | ||
|
||
CreateMap<List<TransmissionContent>?, SearchDialogTransmissionContentDto?>() | ||
.ConvertUsing<TransmissionContentOutputConverter<SearchDialogTransmissionContentDto>>(); | ||
|
||
CreateMap<TransmissionAttachment, SearchDialogTransmissionAttachmentDto>(); | ||
CreateMap<AttachmentUrl, SearchDialogTransmissionAttachmentUrlDto>() | ||
.ForMember(dest => dest.ConsumerType, opt => opt.MapFrom(src => src.ConsumerTypeId)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ion/Features/V1/EndUser/DialogTransmissions/Queries/Search/SearchDialogTransmissionDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Search; | ||
|
||
public sealed class SearchDialogTransmissionDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DateTimeOffset CreatedAt { get; set; } | ||
public string? AuthorizationAttribute { get; set; } | ||
public bool IsAuthorized { get; set; } | ||
public string? ExtendedType { get; set; } | ||
public Guid? RelatedTransmissionId { get; set; } | ||
public DateTimeOffset? DeletedAt { get; set; } | ||
|
||
public DialogTransmissionType.Values Type { get; set; } | ||
|
||
public SearchDialogTransmissionSenderActorDto Sender { get; set; } = null!; | ||
|
||
public SearchDialogTransmissionContentDto Content { get; set; } = null!; | ||
public List<SearchDialogTransmissionAttachmentDto> Attachments { get; set; } = []; | ||
} | ||
|
||
public sealed class SearchDialogTransmissionSenderActorDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DialogActorType.Values ActorType { get; set; } | ||
public string ActorName { get; set; } = null!; | ||
public string ActorId { get; set; } = null!; | ||
} | ||
|
||
public sealed class SearchDialogTransmissionContentDto | ||
{ | ||
public ContentValueDto Title { get; set; } = null!; | ||
public ContentValueDto Summary { get; set; } = null!; | ||
} | ||
|
||
public sealed class SearchDialogTransmissionAttachmentDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public List<LocalizationDto> DisplayName { get; set; } = []; | ||
public List<SearchDialogTransmissionAttachmentUrlDto> Urls { get; set; } = []; | ||
} | ||
|
||
public sealed class SearchDialogTransmissionAttachmentUrlDto | ||
{ | ||
public Guid Id { get; set; } | ||
public Uri Url { get; set; } = null!; | ||
public string? MediaType { get; set; } = null!; | ||
|
||
public AttachmentUrlConsumerType.Values ConsumerType { get; set; } | ||
} |
68 changes: 68 additions & 0 deletions
68
...n/Features/V1/EndUser/DialogTransmissions/Queries/Search/SearchDialogTransmissionQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using AutoMapper; | ||
using Digdir.Domain.Dialogporten.Application.Common; | ||
using Digdir.Domain.Dialogporten.Application.Common.ReturnTypes; | ||
using Digdir.Domain.Dialogporten.Application.Externals; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using OneOf; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogTransmissions.Queries.Search; | ||
|
||
public sealed class SearchDialogTransmissionQuery : IRequest<SearchDialogTransmissionResult> | ||
{ | ||
public Guid DialogId { get; set; } | ||
} | ||
|
||
[GenerateOneOf] | ||
public partial class SearchDialogTransmissionResult : OneOfBase<List<SearchDialogTransmissionDto>, EntityNotFound, EntityDeleted>; | ||
|
||
internal sealed class SearchDialogTransmissionQueryHandler : IRequestHandler<SearchDialogTransmissionQuery, SearchDialogTransmissionResult> | ||
{ | ||
private readonly IDialogDbContext _db; | ||
private readonly IMapper _mapper; | ||
private readonly IUserResourceRegistry _userResourceRegistry; | ||
|
||
public SearchDialogTransmissionQueryHandler(IDialogDbContext db, IMapper mapper, IUserResourceRegistry userResourceRegistry) | ||
{ | ||
_db = db ?? throw new ArgumentNullException(nameof(db)); | ||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); | ||
_userResourceRegistry = userResourceRegistry ?? throw new ArgumentNullException(nameof(userResourceRegistry)); | ||
} | ||
|
||
public async Task<SearchDialogTransmissionResult> Handle(SearchDialogTransmissionQuery request, CancellationToken cancellationToken) | ||
{ | ||
var resourceIds = await _userResourceRegistry.GetCurrentUserResourceIds(cancellationToken); | ||
|
||
var dialog = await _db.Dialogs | ||
.Include(x => x.Transmissions) | ||
.ThenInclude(x => x.Content.OrderBy(x => x.Id).ThenBy(x => x.CreatedAt)) | ||
.ThenInclude(x => x.Value.Localizations.OrderBy(x => x.CreatedAt).ThenBy(x => x.LanguageCode)) | ||
.Include(x => x.Transmissions) | ||
.ThenInclude(x => x.Attachments.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id)) | ||
.ThenInclude(x => x.DisplayName!.Localizations.OrderBy(x => x.CreatedAt).ThenBy(x => x.LanguageCode)) | ||
.Include(x => x.Transmissions) | ||
.ThenInclude(x => x.Attachments.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id)) | ||
.ThenInclude(x => x.Urls.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id)) | ||
.Include(x => x.Transmissions) | ||
.ThenInclude(x => x.Sender) | ||
.IgnoreQueryFilters() | ||
.Where(x => resourceIds.Contains(x.ServiceResource)) | ||
.FirstOrDefaultAsync(x => x.Id == request.DialogId, | ||
cancellationToken: cancellationToken); | ||
|
||
if (dialog is null) | ||
{ | ||
return new EntityNotFound<DialogEntity>(request.DialogId); | ||
} | ||
|
||
if (dialog.Deleted) | ||
{ | ||
return new EntityDeleted<DialogEntity>(request.DialogId); | ||
} | ||
|
||
// TODO: Check auth | ||
|
||
return _mapper.Map<List<SearchDialogTransmissionDto>>(dialog.Transmissions); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...tion/Features/V1/ServiceOwner/DialogTransmissions/Queries/Get/GetDialogTransmissionDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Content; | ||
using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actors; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Attachments; | ||
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions; | ||
|
||
namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogTransmissions.Queries.Get; | ||
|
||
public sealed class GetDialogTransmissionDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DateTimeOffset CreatedAt { get; set; } | ||
public string? AuthorizationAttribute { get; set; } | ||
public string? ExtendedType { get; set; } | ||
public Guid? RelatedTransmissionId { get; set; } | ||
public DateTimeOffset? DeletedAt { get; set; } | ||
|
||
public DialogTransmissionType.Values Type { get; set; } | ||
|
||
public GetDialogTransmissionSenderActorDto Sender { get; set; } = null!; | ||
|
||
public GetDialogTransmissionContentDto Content { get; set; } = null!; | ||
public List<GetDialogTransmissionAttachmentDto> Attachments { get; set; } = []; | ||
} | ||
|
||
public sealed class GetDialogTransmissionSenderActorDto | ||
{ | ||
public Guid Id { get; set; } | ||
public DialogActorType.Values ActorType { get; set; } | ||
public string ActorName { get; set; } = null!; | ||
public string ActorId { get; set; } = null!; | ||
} | ||
|
||
public sealed class GetDialogTransmissionContentDto | ||
{ | ||
public ContentValueDto Title { get; set; } = null!; | ||
public ContentValueDto Summary { get; set; } = null!; | ||
} | ||
|
||
public sealed class GetDialogTransmissionAttachmentDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public List<LocalizationDto> DisplayName { get; set; } = []; | ||
public List<GetDialogTransmissionAttachmentUrlDto> Urls { get; set; } = []; | ||
} | ||
|
||
public sealed class GetDialogTransmissionAttachmentUrlDto | ||
{ | ||
public Guid Id { get; set; } | ||
public Uri Url { get; set; } = null!; | ||
public string? MediaType { get; set; } = null!; | ||
|
||
public AttachmentUrlConsumerType.Values ConsumerType { get; set; } | ||
} |
Oops, something went wrong.