From 26c18d2f484df796655356b7a8a1f3efd0830b9a Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 7 Aug 2021 16:39:32 -0400 Subject: [PATCH] refactor: move modeltypes to own folder, move IDs to file of respective type --- PluralKit.Core/Models/GroupId.cs | 26 ----------------- PluralKit.Core/Models/MemberId.cs | 26 ----------------- .../Models/{ => ModelTypes}/INumericId.cs | 0 .../{Utils => Models/ModelTypes}/Partial.cs | 0 PluralKit.Core/Models/PKGroup.cs | 28 ++++++++++++++++++- PluralKit.Core/Models/PKMember.cs | 26 +++++++++++++++++ PluralKit.Core/Models/PKSwitch.cs | 27 ++++++++++++++++++ PluralKit.Core/Models/PKSystem.cs | 27 ++++++++++++++++++ PluralKit.Core/Models/SwitchId.cs | 26 ----------------- PluralKit.Core/Models/SystemId.cs | 26 ----------------- 10 files changed, 107 insertions(+), 105 deletions(-) delete mode 100644 PluralKit.Core/Models/GroupId.cs delete mode 100644 PluralKit.Core/Models/MemberId.cs rename PluralKit.Core/Models/{ => ModelTypes}/INumericId.cs (100%) rename PluralKit.Core/{Utils => Models/ModelTypes}/Partial.cs (100%) delete mode 100644 PluralKit.Core/Models/SwitchId.cs delete mode 100644 PluralKit.Core/Models/SystemId.cs diff --git a/PluralKit.Core/Models/GroupId.cs b/PluralKit.Core/Models/GroupId.cs deleted file mode 100644 index b294f56c..00000000 --- a/PluralKit.Core/Models/GroupId.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace PluralKit.Core -{ - public readonly struct GroupId: INumericId - { - public int Value { get; } - - public GroupId(int value) - { - Value = value; - } - - public bool Equals(GroupId other) => Value == other.Value; - - public override bool Equals(object obj) => obj is GroupId other && Equals(other); - - public override int GetHashCode() => Value; - - public static bool operator ==(GroupId left, GroupId right) => left.Equals(right); - - public static bool operator !=(GroupId left, GroupId right) => !left.Equals(right); - - public int CompareTo(GroupId other) => Value.CompareTo(other.Value); - - public override string ToString() => $"Group #{Value}"; - } -} \ No newline at end of file diff --git a/PluralKit.Core/Models/MemberId.cs b/PluralKit.Core/Models/MemberId.cs deleted file mode 100644 index 7bf27ab7..00000000 --- a/PluralKit.Core/Models/MemberId.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace PluralKit.Core -{ - public readonly struct MemberId: INumericId - { - public int Value { get; } - - public MemberId(int value) - { - Value = value; - } - - public bool Equals(MemberId other) => Value == other.Value; - - public override bool Equals(object obj) => obj is MemberId other && Equals(other); - - public override int GetHashCode() => Value; - - public static bool operator ==(MemberId left, MemberId right) => left.Equals(right); - - public static bool operator !=(MemberId left, MemberId right) => !left.Equals(right); - - public int CompareTo(MemberId other) => Value.CompareTo(other.Value); - - public override string ToString() => $"Member #{Value}"; - } -} \ No newline at end of file diff --git a/PluralKit.Core/Models/INumericId.cs b/PluralKit.Core/Models/ModelTypes/INumericId.cs similarity index 100% rename from PluralKit.Core/Models/INumericId.cs rename to PluralKit.Core/Models/ModelTypes/INumericId.cs diff --git a/PluralKit.Core/Utils/Partial.cs b/PluralKit.Core/Models/ModelTypes/Partial.cs similarity index 100% rename from PluralKit.Core/Utils/Partial.cs rename to PluralKit.Core/Models/ModelTypes/Partial.cs diff --git a/PluralKit.Core/Models/PKGroup.cs b/PluralKit.Core/Models/PKGroup.cs index 018f945e..742d9acf 100644 --- a/PluralKit.Core/Models/PKGroup.cs +++ b/PluralKit.Core/Models/PKGroup.cs @@ -1,8 +1,34 @@ using NodaTime; -#nullable enable + + namespace PluralKit.Core { + public readonly struct GroupId: INumericId + { + public int Value { get; } + + public GroupId(int value) + { + Value = value; + } + + public bool Equals(GroupId other) => Value == other.Value; + + public override bool Equals(object obj) => obj is GroupId other && Equals(other); + + public override int GetHashCode() => Value; + + public static bool operator ==(GroupId left, GroupId right) => left.Equals(right); + + public static bool operator !=(GroupId left, GroupId right) => !left.Equals(right); + + public int CompareTo(GroupId other) => Value.CompareTo(other.Value); + + public override string ToString() => $"Group #{Value}"; + } + +#nullable enable public class PKGroup { public GroupId Id { get; private set; } diff --git a/PluralKit.Core/Models/PKMember.cs b/PluralKit.Core/Models/PKMember.cs index 8f4894cd..4a1dc6d4 100644 --- a/PluralKit.Core/Models/PKMember.cs +++ b/PluralKit.Core/Models/PKMember.cs @@ -5,7 +5,33 @@ using Newtonsoft.Json; using NodaTime; using NodaTime.Text; + + namespace PluralKit.Core { + public readonly struct MemberId: INumericId + { + public int Value { get; } + + public MemberId(int value) + { + Value = value; + } + + public bool Equals(MemberId other) => Value == other.Value; + + public override bool Equals(object obj) => obj is MemberId other && Equals(other); + + public override int GetHashCode() => Value; + + public static bool operator ==(MemberId left, MemberId right) => left.Equals(right); + + public static bool operator !=(MemberId left, MemberId right) => !left.Equals(right); + + public int CompareTo(MemberId other) => Value.CompareTo(other.Value); + + public override string ToString() => $"Member #{Value}"; + } + public class PKMember { // Dapper *can* figure out mapping to getter-only properties, but this doesn't work diff --git a/PluralKit.Core/Models/PKSwitch.cs b/PluralKit.Core/Models/PKSwitch.cs index 0ac4be40..c73c030b 100644 --- a/PluralKit.Core/Models/PKSwitch.cs +++ b/PluralKit.Core/Models/PKSwitch.cs @@ -1,6 +1,33 @@ using NodaTime; + + namespace PluralKit.Core { + + public readonly struct SwitchId: INumericId + { + public int Value { get; } + + public SwitchId(int value) + { + Value = value; + } + + public bool Equals(SwitchId other) => Value == other.Value; + + public override bool Equals(object obj) => obj is SwitchId other && Equals(other); + + public override int GetHashCode() => Value; + + public static bool operator ==(SwitchId left, SwitchId right) => left.Equals(right); + + public static bool operator !=(SwitchId left, SwitchId right) => !left.Equals(right); + + public int CompareTo(SwitchId other) => Value.CompareTo(other.Value); + + public override string ToString() => $"Switch #{Value}"; + } + public class PKSwitch { public SwitchId Id { get; } diff --git a/PluralKit.Core/Models/PKSystem.cs b/PluralKit.Core/Models/PKSystem.cs index de059db6..42f9e6b8 100644 --- a/PluralKit.Core/Models/PKSystem.cs +++ b/PluralKit.Core/Models/PKSystem.cs @@ -4,7 +4,34 @@ using Newtonsoft.Json; using NodaTime; + + namespace PluralKit.Core { + + public readonly struct SystemId: INumericId + { + public int Value { get; } + + public SystemId(int value) + { + Value = value; + } + + public bool Equals(SystemId other) => Value == other.Value; + + public override bool Equals(object obj) => obj is SystemId other && Equals(other); + + public override int GetHashCode() => Value; + + public static bool operator ==(SystemId left, SystemId right) => left.Equals(right); + + public static bool operator !=(SystemId left, SystemId right) => !left.Equals(right); + + public int CompareTo(SystemId other) => Value.CompareTo(other.Value); + + public override string ToString() => $"System #{Value}"; + } + public class PKSystem { // Additions here should be mirrored in SystemStore::Save diff --git a/PluralKit.Core/Models/SwitchId.cs b/PluralKit.Core/Models/SwitchId.cs deleted file mode 100644 index 6c6f98c3..00000000 --- a/PluralKit.Core/Models/SwitchId.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace PluralKit.Core -{ - public readonly struct SwitchId: INumericId - { - public int Value { get; } - - public SwitchId(int value) - { - Value = value; - } - - public bool Equals(SwitchId other) => Value == other.Value; - - public override bool Equals(object obj) => obj is SwitchId other && Equals(other); - - public override int GetHashCode() => Value; - - public static bool operator ==(SwitchId left, SwitchId right) => left.Equals(right); - - public static bool operator !=(SwitchId left, SwitchId right) => !left.Equals(right); - - public int CompareTo(SwitchId other) => Value.CompareTo(other.Value); - - public override string ToString() => $"Switch #{Value}"; - } -} \ No newline at end of file diff --git a/PluralKit.Core/Models/SystemId.cs b/PluralKit.Core/Models/SystemId.cs deleted file mode 100644 index a09afdca..00000000 --- a/PluralKit.Core/Models/SystemId.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace PluralKit.Core -{ - public readonly struct SystemId: INumericId - { - public int Value { get; } - - public SystemId(int value) - { - Value = value; - } - - public bool Equals(SystemId other) => Value == other.Value; - - public override bool Equals(object obj) => obj is SystemId other && Equals(other); - - public override int GetHashCode() => Value; - - public static bool operator ==(SystemId left, SystemId right) => left.Equals(right); - - public static bool operator !=(SystemId left, SystemId right) => !left.Equals(right); - - public int CompareTo(SystemId other) => Value.CompareTo(other.Value); - - public override string ToString() => $"System #{Value}"; - } -} \ No newline at end of file