Changed get/set profile with more safe handling
This commit is contained in:
@@ -9,14 +9,27 @@ namespace LightlessSyncServer.Utils;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static void UpdateProfileFromDto(this GroupProfile profile, GroupProfileDto dto)
|
||||
{
|
||||
if (profile == null || dto == null) return;
|
||||
|
||||
profile.Base64GroupProfileImage = string.IsNullOrWhiteSpace(dto.PictureBase64) ? null : dto.PictureBase64;
|
||||
if (dto.Tags != null) profile.Tags = dto.Tags;
|
||||
if (dto.Description != null) profile.Description = dto.Description;
|
||||
if (dto.IsNsfw.HasValue) profile.IsNSFW = dto.IsNsfw.Value;
|
||||
}
|
||||
|
||||
public static GroupProfileDto ToDTO(this GroupProfile groupProfile)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(groupProfile);
|
||||
if (groupProfile == null)
|
||||
{
|
||||
return new GroupProfileDto(Group: null, Description: null, Tags: null, PictureBase64: null, IsNsfw: false, IsDisabled: false);
|
||||
}
|
||||
|
||||
return groupProfile.Group == null
|
||||
? throw new InvalidOperationException("GroupProfile.Group is null when converting to DTO.")
|
||||
: new GroupProfileDto(
|
||||
groupProfile.Group.ToGroupData(),
|
||||
var groupData = groupProfile.Group?.ToGroupData();
|
||||
|
||||
return new GroupProfileDto(
|
||||
groupData,
|
||||
groupProfile.Description,
|
||||
groupProfile.Tags,
|
||||
groupProfile.Base64GroupProfileImage,
|
||||
@@ -27,16 +40,25 @@ public static class Extensions
|
||||
|
||||
public static GroupData ToGroupData(this Group group)
|
||||
{
|
||||
if (group == null)
|
||||
return null;
|
||||
|
||||
return new GroupData(group.GID, group.Alias, group.CreatedDate);
|
||||
}
|
||||
|
||||
public static UserData ToUserData(this GroupPair pair)
|
||||
{
|
||||
if (pair == null)
|
||||
return null;
|
||||
|
||||
return new UserData(pair.GroupUser.UID, pair.GroupUser.Alias);
|
||||
}
|
||||
|
||||
public static UserData ToUserData(this User user)
|
||||
{
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
return new UserData(user.UID, user.Alias);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user