diff --git a/Govor.Core/Models/Users/PrivacyRuleEntity.cs b/Govor.Core/Models/Users/PrivacyRuleEntity.cs new file mode 100644 index 0000000..09f1fe0 --- /dev/null +++ b/Govor.Core/Models/Users/PrivacyRuleEntity.cs @@ -0,0 +1,15 @@ +namespace Govor.Core.Models.Users; + +public class PrivacyRuleEntity +{ + public Guid Id { get; set; } + public Guid OwnerId { get; set; } + + public PrivacyTargetArea Area { get; set; } + public WhoCan AccessType { get; set; } // Everyone, Friends, None + + public List Whitelist { get; set; } = new(); + public List Blacklist { get; set; } = new(); + + public PrivacyUserSettings OwnerSettings { get; set; } = null!; +} \ No newline at end of file diff --git a/Govor.Core/Models/Users/PrivacyUserSettings.cs b/Govor.Core/Models/Users/PrivacyUserSettings.cs index c0a19a8..9997c9f 100644 --- a/Govor.Core/Models/Users/PrivacyUserSettings.cs +++ b/Govor.Core/Models/Users/PrivacyUserSettings.cs @@ -3,22 +3,15 @@ namespace Govor.Core.Models.Users; public class PrivacyUserSettings { public Guid UserId { get; set; } - public bool IsGlobalAccount { get; set; } - - public WhoCan CanSend { get; set; } - public List? WhitelistSent { get; set; } - public List? BlacklistSent { get; set; } - - public WhoCan CanSeeTimeWas { get; set; } - public List? WhitelistTimeWas { get; set; } - public List? BlacklistTimeWas { get; set; } - - public WhoCan CanSeeImage { get; set; } - public List? WhitelistSeeImage { get; set; } - public List? BlacklistSeeImage{ get; set; } - - public DeletingMessagesVia Via { get; set; } // if min value = none + + public bool IsGlobalAccount { get; set; } + + public DeletingMessagesVia DeletingVia { get; set; } public int DeletingIn { get; set; } + + public bool IsInvisibleMode { get; set; } + + public List Rules { get; set; } = new(); } public enum WhoCan @@ -37,3 +30,17 @@ public enum DeletingMessagesVia Years = 4 } +public enum PrivacyTargetArea +{ + CanSend = 0, + CanSeeTimeWas = 1, + CanSeeImage = 2 +} + +public enum PrivacyRuleType +{ + Allow = 0, + Deny = 1 +} + + diff --git a/Govor.Data/Configurations/PrivacyRuleEntityConfiguration.cs b/Govor.Data/Configurations/PrivacyRuleEntityConfiguration.cs new file mode 100644 index 0000000..226fb6f --- /dev/null +++ b/Govor.Data/Configurations/PrivacyRuleEntityConfiguration.cs @@ -0,0 +1,23 @@ +using Govor.Core.Models.Users; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Govor.Data.Configurations; + + +public class PrivacyRuleEntityConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(r => r.Id); + + builder.Property(r => r.OwnerId).IsRequired(); + builder.Property(r => r.Area).IsRequired().HasConversion(); + builder.Property(r => r.AccessType).IsRequired().HasConversion(); + + builder.Property(r => r.Whitelist).HasColumnType("jsonb"); + builder.Property(r => r.Blacklist).HasColumnType("jsonb"); + + builder.HasIndex(r => r.OwnerId); + } +} \ No newline at end of file diff --git a/Govor.Data/Configurations/PrivacyUserSettingsConfiguration.cs b/Govor.Data/Configurations/PrivacyUserSettingsConfiguration.cs new file mode 100644 index 0000000..7582db7 --- /dev/null +++ b/Govor.Data/Configurations/PrivacyUserSettingsConfiguration.cs @@ -0,0 +1,29 @@ +using Govor.Core.Models.Users; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Govor.Data.Configurations; + +public class PrivacyUserSettingsConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + // Primary Key + builder.HasKey(p => p.UserId); + + builder.Property(p => p.DeletingVia) + .IsRequired() + .HasConversion() + .HasDefaultValue(DeletingMessagesVia.None); // Adjust default as needed + + builder.Property(p => p.DeletingIn) + .IsRequired() + .HasDefaultValue(0); + + // Relationship Configuration + builder.HasMany(p => p.Rules) + .WithOne(r => r.OwnerSettings) + .HasForeignKey(r => r.OwnerId) + .OnDelete(DeleteBehavior.Cascade); + } +}