Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Add Devices to account DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jul 10, 2023
1 parent bf93aca commit 4bd5752
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Common/DTOs/AccountDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ namespace ZapMe.DTOs;

public required string StatusText { get; init; }

/// <summary>
/// Ids of devices this account owns
/// </summary>
public required IEnumerable<Guid> OwnedDeviceIds { get; init; }

/// <summary>
/// Ids of users this account has friended
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Common/Database/Models/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public void Configure(EntityTypeBuilder<DeviceEntity> builder)

builder.HasIndex(ud => ud.OwnerId);
builder.HasIndex(ud => ud.AccessToken).IsUnique();

builder.HasOne(ud => ud.Owner).WithMany(u => u.OwnedDevices).OnDelete(DeleteBehavior.Cascade);
}
}
1 change: 1 addition & 0 deletions Common/Database/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public sealed class UserEntity
public List<UserRelationEntity> RelationsOutgoing { get; private set; } = new List<UserRelationEntity>();
public List<UserRelationEntity> RelationsIncoming { get; private set; } = new List<UserRelationEntity>();
public List<SSOConnectionEntity> SSOConnections { get; private set; } = new List<SSOConnectionEntity>();
public List<DeviceEntity> OwnedDevices { get; private set; } = new List<DeviceEntity>();
}

public sealed class UserEntityConfiguration : IEntityTypeConfiguration<UserEntity>
Expand Down
1 change: 1 addition & 0 deletions Common/Mappers/UserMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static AccountDto MapToAccountDto(UserEntity user)
BannerUrl = user.ProfileBanner?.PublicUrl,
Status = user.Status,
StatusText = user.StatusText,
OwnedDeviceIds = user.OwnedDevices.Select(d => d.Id),
FriendUserIds = user.RelationsOutgoing.Where(r => r.FriendStatus == UserPartialRelationType.Accepted).Select(r => r.ToUserId),
SSOConnections = user.SSOConnections.Select(oc => oc.ProviderName),
CreatedAt = user.CreatedAt,
Expand Down

0 comments on commit 4bd5752

Please sign in to comment.