diff --git a/Common/DTOs/AccountDto.cs b/Common/DTOs/AccountDto.cs
index 374bac9..11dd330 100644
--- a/Common/DTOs/AccountDto.cs
+++ b/Common/DTOs/AccountDto.cs
@@ -28,6 +28,11 @@ namespace ZapMe.DTOs;
public required string StatusText { get; init; }
+ ///
+ /// Ids of devices this account owns
+ ///
+ public required IEnumerable OwnedDeviceIds { get; init; }
+
///
/// Ids of users this account has friended
///
diff --git a/Common/Database/Models/Device.cs b/Common/Database/Models/Device.cs
index 0793f22..0815bab 100644
--- a/Common/Database/Models/Device.cs
+++ b/Common/Database/Models/Device.cs
@@ -40,5 +40,7 @@ public void Configure(EntityTypeBuilder builder)
builder.HasIndex(ud => ud.OwnerId);
builder.HasIndex(ud => ud.AccessToken).IsUnique();
+
+ builder.HasOne(ud => ud.Owner).WithMany(u => u.OwnedDevices).OnDelete(DeleteBehavior.Cascade);
}
}
\ No newline at end of file
diff --git a/Common/Database/Models/User.cs b/Common/Database/Models/User.cs
index 8b3cba8..16514fd 100644
--- a/Common/Database/Models/User.cs
+++ b/Common/Database/Models/User.cs
@@ -57,6 +57,7 @@ public sealed class UserEntity
public List RelationsOutgoing { get; private set; } = new List();
public List RelationsIncoming { get; private set; } = new List();
public List SSOConnections { get; private set; } = new List();
+ public List OwnedDevices { get; private set; } = new List();
}
public sealed class UserEntityConfiguration : IEntityTypeConfiguration
diff --git a/Common/Mappers/UserMapper.cs b/Common/Mappers/UserMapper.cs
index a6b04b1..ff4feaa 100644
--- a/Common/Mappers/UserMapper.cs
+++ b/Common/Mappers/UserMapper.cs
@@ -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,