More equality shenanigans

This commit is contained in:
Laura Hausmann 2023-06-01 06:20:17 +02:00
parent ec4ed6f0be
commit 6a10e8c631
Signed by: zotan
GPG key ID: D044E84C5BE01605
4 changed files with 55 additions and 7 deletions

View file

@ -4,8 +4,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Authinator.Backend.Database.Tables;
public record ACL {
public int Id { get; set; }
public class ACL {
public int Id { get; }
public string Name { get; set; } = null!;
public bool Enabled { get; set; } = true;
public string Target { get; set; } = null!;
@ -27,4 +27,20 @@ public record ACL {
acl.HasMany(p => p.Users).WithMany();
}
}
private bool Equals(ACL other) => Id == other.Id;
public override bool Equals(object? obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == GetType() && Equals((ACL)obj);
}
public override int GetHashCode() => Id;
public static bool operator ==(ACL? left, ACL? right) => Equals(left, right);
public static bool operator !=(ACL? left, ACL? right) => !Equals(left, right);
}

View file

@ -3,8 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Authinator.Backend.Database.Tables;
public record Group {
public int Id { get; set; }
public class Group {
public int Id { get; }
public string Name { get; set; } = null!;
public class Configuration : IEntityTypeConfiguration<Group> {
@ -14,4 +14,20 @@ public record Group {
group.Property(b => b.Name).HasColumnName("Name").IsRequired();
}
}
private bool Equals(Group other) => Id == other.Id;
public override bool Equals(object? obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == GetType() && Equals((Group)obj);
}
public override int GetHashCode() => Id;
public static bool operator ==(Group? left, Group? right) => Equals(left, right);
public static bool operator !=(Group? left, Group? right) => !Equals(left, right);
}

View file

@ -4,8 +4,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Authinator.Backend.Database.Tables;
public record Network {
public int Id { get; set; }
public class Network {
public int Id { get; }
public string Name { get; set; } = null!;
public IPAddress Subnet { get; set; } = null!;
@ -17,4 +17,20 @@ public record Network {
group.Property(b => b.Name).HasColumnName("Subnet").IsRequired();
}
}
private bool Equals(Network other) => Id == other.Id;
public override bool Equals(object? obj) {
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
return obj.GetType() == GetType() && Equals((Network)obj);
}
public override int GetHashCode() => Id;
public static bool operator ==(Network? left, Network? right) => Equals(left, right);
public static bool operator !=(Network? left, Network? right) => !Equals(left, right);
}

View file

@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Authinator.Backend.Database.Tables;
public class User {
public int Id { get; set; }
public int Id { get; }
public int Iteration { get; set; }
public string Reference { get; set; } = null!;
public string? Username { get; set; }