From cbd36ddec298f18617fd076b4095ec75394fbbc8 Mon Sep 17 00:00:00 2001 From: scogliera Date: Sat, 9 Dec 2023 03:41:22 +0100 Subject: [PATCH 1/3] Add object models --- Models/ContactInfo.cs | 10 ++++++++++ Models/Error.cs | 9 +++++++++ Models/Lecturer.cs | 22 ++++++++++++++++++++++ Models/Tag.cs | 9 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 Models/ContactInfo.cs create mode 100644 Models/Error.cs create mode 100644 Models/Lecturer.cs create mode 100644 Models/Tag.cs diff --git a/Models/ContactInfo.cs b/Models/ContactInfo.cs new file mode 100644 index 0000000..c290d75 --- /dev/null +++ b/Models/ContactInfo.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace TeacherDigitalAgency.Models; + +public class ContactInfo +{ + // TODO: Must validate uniqueness of inputs + [JsonPropertyName("telephone_numbers")] public required IEnumerable TelephoneNumbers { get; set; } + [JsonPropertyName("emails")] public required IEnumerable Emails { get; set; } +} \ No newline at end of file diff --git a/Models/Error.cs b/Models/Error.cs new file mode 100644 index 0000000..a13a1c2 --- /dev/null +++ b/Models/Error.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TeacherDigitalAgency.Models; + +public class Error +{ + [JsonPropertyName("code")] public required int Code { get; set; } + [JsonPropertyName("message")] public required string Message { get; set; } +} \ No newline at end of file diff --git a/Models/Lecturer.cs b/Models/Lecturer.cs new file mode 100644 index 0000000..d58fc76 --- /dev/null +++ b/Models/Lecturer.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace TeacherDigitalAgency.Models; + +public class Lecturer +{ + // TODO: Find out how UUIDs get generated -> C# or Mongo solution + [JsonPropertyName("uuid")] public string Uuid { get; init; } + [JsonPropertyName("title_before")] public string? TitleBefore { get; set; } + [JsonPropertyName("first_name")] public required string FirstName { get; set; } + [JsonPropertyName("middle_name")] public string? MiddleName { get; set; } + [JsonPropertyName("last_name")] public required string LastName { get; set; } + [JsonPropertyName("title_after")] public string? TitleAfter { get; set; } + [JsonPropertyName("picture_url")] public string? PictureUrl { get; set; } + [JsonPropertyName("location")] public string? Location { get; set; } + [JsonPropertyName("claim")] public string? Claim { get; set; } + [JsonPropertyName("bio")] public string? Bio { get; set; } + [JsonPropertyName("tags")] public IEnumerable Tags { get; set; } = new List(); + [JsonPropertyName("price_per_hour")] public int? PricePerHour { get; set; } + // TODO: Not known if contact can be nullable - most likely yes + [JsonPropertyName("contact")] public ContactInfo? ContactInfo { get; set; } +} \ No newline at end of file diff --git a/Models/Tag.cs b/Models/Tag.cs new file mode 100644 index 0000000..36a7467 --- /dev/null +++ b/Models/Tag.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace TeacherDigitalAgency.Models; + +public class Tag +{ + [JsonPropertyName("uuid")] public required string Uuid { get; init; } + [JsonPropertyName("name")] public required string Name { get; set; } +} \ No newline at end of file From 59610039a430a597bf3a86fb4710dba8d8890889 Mon Sep 17 00:00:00 2001 From: scogliera Date: Sat, 9 Dec 2023 03:57:36 +0100 Subject: [PATCH 2/3] Make ContactInfo use HashSets as to ensure element uniqueness --- Models/ContactInfo.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Models/ContactInfo.cs b/Models/ContactInfo.cs index c290d75..9904a76 100644 --- a/Models/ContactInfo.cs +++ b/Models/ContactInfo.cs @@ -4,7 +4,6 @@ namespace TeacherDigitalAgency.Models; public class ContactInfo { - // TODO: Must validate uniqueness of inputs - [JsonPropertyName("telephone_numbers")] public required IEnumerable TelephoneNumbers { get; set; } - [JsonPropertyName("emails")] public required IEnumerable Emails { get; set; } + [JsonPropertyName("telephone_numbers")] public required HashSet TelephoneNumbers { get; set; } + [JsonPropertyName("emails")] public required HashSet Emails { get; set; } } \ No newline at end of file From 9315b78250ca0f587155316c3cbf87b1ed3f0edd Mon Sep 17 00:00:00 2001 From: scogliera Date: Sat, 9 Dec 2023 03:58:56 +0100 Subject: [PATCH 3/3] Add Guid support for Lecturers and Tags, add ctor to Lecturer.cs --- Models/Lecturer.cs | 9 +++++++-- Models/Tag.cs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Models/Lecturer.cs b/Models/Lecturer.cs index d58fc76..851cd94 100644 --- a/Models/Lecturer.cs +++ b/Models/Lecturer.cs @@ -4,8 +4,13 @@ namespace TeacherDigitalAgency.Models; public class Lecturer { - // TODO: Find out how UUIDs get generated -> C# or Mongo solution - [JsonPropertyName("uuid")] public string Uuid { get; init; } + public Lecturer(string firstName, string lastName) + { + FirstName = firstName; + LastName = lastName; + } + + [JsonPropertyName("uuid")] public Guid Uuid { get; init; } = Guid.NewGuid(); [JsonPropertyName("title_before")] public string? TitleBefore { get; set; } [JsonPropertyName("first_name")] public required string FirstName { get; set; } [JsonPropertyName("middle_name")] public string? MiddleName { get; set; } diff --git a/Models/Tag.cs b/Models/Tag.cs index 36a7467..1c901ee 100644 --- a/Models/Tag.cs +++ b/Models/Tag.cs @@ -4,6 +4,6 @@ namespace TeacherDigitalAgency.Models; public class Tag { - [JsonPropertyName("uuid")] public required string Uuid { get; init; } + [JsonPropertyName("uuid")] public Guid Uuid { get; init; } = Guid.NewGuid(); [JsonPropertyName("name")] public required string Name { get; set; } } \ No newline at end of file