C
C#7mo ago
TOKYODRIFT!

how to join will null?

I have this logic:
private async Task OnChannelsGet(
IDeliveryHandlerContext context,
MessagingSubjectsChannelsGetArguments arguments)
{
var channelsGetResponse = await _messagingChannelsClient
.ChannelsGet(new(arguments.Names))
.Unwrap();

var channelSettingsResponse = await _systemServiceClient
.DataGet(new(arguments.Names))
.Unwrap();

var channelSettingsSchema = await ChannelSettingsSchemaCreate();

var result = channelsGetResponse.Items
.Join( channelSettingsResponse.Items,
mutationDto => mutationDto.Name,
channelSettingsDto => channelSettingsDto.Key,
(channelDto, channelSettingsDto) =>
new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue(context.Culture),
Description = channelDto.Description.GetValue(context.Culture),
Configuration = channelDto.Configuration,
Settings = channelSettingsDto.Data.FromJson<ChannelSettingsDto>(),
SettingsSchema = channelSettingsSchema
} )
.ToList();

await context.TryRespondOk(new MessagingSubjectsChannelsGetResponse(result));
}
private async Task OnChannelsGet(
IDeliveryHandlerContext context,
MessagingSubjectsChannelsGetArguments arguments)
{
var channelsGetResponse = await _messagingChannelsClient
.ChannelsGet(new(arguments.Names))
.Unwrap();

var channelSettingsResponse = await _systemServiceClient
.DataGet(new(arguments.Names))
.Unwrap();

var channelSettingsSchema = await ChannelSettingsSchemaCreate();

var result = channelsGetResponse.Items
.Join( channelSettingsResponse.Items,
mutationDto => mutationDto.Name,
channelSettingsDto => channelSettingsDto.Key,
(channelDto, channelSettingsDto) =>
new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue(context.Culture),
Description = channelDto.Description.GetValue(context.Culture),
Configuration = channelDto.Configuration,
Settings = channelSettingsDto.Data.FromJson<ChannelSettingsDto>(),
SettingsSchema = channelSettingsSchema
} )
.ToList();

await context.TryRespondOk(new MessagingSubjectsChannelsGetResponse(result));
}
channelSettingsResponse can be null or we couldn't join by keys and now result will be null but I don't need it. If something bad with channelSettingsResponse, I'd like to return
new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue(context.Culture),
Description = channelDto.Description.GetValue(context.Culture),
Configuration = channelDto.Configuration,
Settings = null,
SettingsSchema = channelSettingsSchema
} )
new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue(context.Culture),
Description = channelDto.Description.GetValue(context.Culture),
Configuration = channelDto.Configuration,
Settings = null,
SettingsSchema = channelSettingsSchema
} )
1 Reply
TOKYODRIFT!
TOKYODRIFT!7mo ago
ahh I know! var map = channelSettingsResponse.Items .ToDictionary( x => x.Key, x => x.Data ); and then we can use this
var result = channelsGetResponse.Items
.Select( channelDto => new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue( context.Culture ),
Description = channelDto.Description.GetValue( context.Culture ),
Configuration = channelDto.Configuration,
Settings = map[ channelDto.Name].FromJson<ChannelSettingsDto>(),
SettingsSchema = channelSettingsSchema
} );
var result = channelsGetResponse.Items
.Select( channelDto => new MessagingSubjectsChannelGetDto
{
Name = channelDto.Name,
Title = channelDto.Title.GetValue( context.Culture ),
Description = channelDto.Description.GetValue( context.Culture ),
Configuration = channelDto.Configuration,
Settings = map[ channelDto.Name].FromJson<ChannelSettingsDto>(),
SettingsSchema = channelSettingsSchema
} );
without any join