Added null checks
This commit is contained in:
@@ -746,15 +746,20 @@ public partial class LightlessHub
|
|||||||
var cancellationToken = RequestAbortedToken;
|
var cancellationToken = RequestAbortedToken;
|
||||||
|
|
||||||
var data = await DbContext.GroupProfiles
|
var data = await DbContext.GroupProfiles
|
||||||
.FirstOrDefaultAsync(g => g.Group.ToGroupData().AliasOrGID == dto.Group.AliasOrGID, cancellationToken)
|
.FirstOrDefaultAsync(g => g.Group.GID == dto.Group.GID || g.Group.Alias == dto.Group.AliasOrGID, cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var profileDto = new GroupProfileDto(dto.Group, Description: null, Tags: null, PictureBase64: null, IsNsfw: false, IsDisabled: false);
|
var profileDto = new GroupProfileDto(dto.Group, Description: null, Tags: null, PictureBase64: null, IsNsfw: false, IsDisabled: false);
|
||||||
|
|
||||||
if (data is not null)
|
if (data is not null)
|
||||||
|
{
|
||||||
|
_logger.LogCallInfo(LightlessHubLogger.Args($"GroupGetProfile: dto={dto?.GID}, groupProfile.Group={(data?.Group != null)}"));
|
||||||
|
|
||||||
|
if (data.Group != null)
|
||||||
{
|
{
|
||||||
profileDto = data.ToDTO();
|
profileDto = data.ToDTO();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return profileDto;
|
return profileDto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,18 @@ public static class Extensions
|
|||||||
{
|
{
|
||||||
public static GroupProfileDto ToDTO(this GroupProfile groupProfile)
|
public static GroupProfileDto ToDTO(this GroupProfile groupProfile)
|
||||||
{
|
{
|
||||||
return new GroupProfileDto(groupProfile.Group.ToGroupData(), groupProfile.Description, groupProfile.Tags, groupProfile.Base64GroupProfileImage, groupProfile.IsNSFW, groupProfile.ProfileDisabled);
|
ArgumentNullException.ThrowIfNull(groupProfile);
|
||||||
|
|
||||||
|
return groupProfile.Group == null
|
||||||
|
? throw new InvalidOperationException("GroupProfile.Group is null when converting to DTO.")
|
||||||
|
: new GroupProfileDto(
|
||||||
|
groupProfile.Group.ToGroupData(),
|
||||||
|
groupProfile.Description,
|
||||||
|
groupProfile.Tags,
|
||||||
|
groupProfile.Base64GroupProfileImage,
|
||||||
|
groupProfile.IsNSFW,
|
||||||
|
groupProfile.ProfileDisabled
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GroupData ToGroupData(this Group group)
|
public static GroupData ToGroupData(this Group group)
|
||||||
|
|||||||
Reference in New Issue
Block a user