Skip to content

Commit 37c7304

Browse files
committed
Remove not needed json converteres, and fix general some json attributes
1 parent 0f2ec88 commit 37c7304

5 files changed

Lines changed: 14 additions & 93 deletions

File tree

WebUntisAPI.Client/Converter/SchoolYearJsonConverter.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

WebUntisAPI.Client/Converter/TimegridJsonConverter.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ public override Timegrid ReadJson(JsonReader reader, Type objectType, Timegrid e
2222
{
2323
List<SchoolHour> hours = new List<SchoolHour>();
2424
foreach (JObject hour in dayTimegrid["timeUnits"].Cast<JObject>())
25-
hours.Add(new SchoolHour()
26-
{
27-
Name = hour["name"].Value<string>(),
28-
StartTime = new DateTime().FromWebUntisTimeFormat("20200101", hour["startTime"].Value<string>()),
29-
EndTime = new DateTime().FromWebUntisTimeFormat("20200101", hour["endTime"].Value<string>())
30-
});
25+
hours.Add(serializer.Deserialize<SchoolHour>(hour.CreateReader()));
3126

3227
timegrid[(Day)dayTimegrid["day"].Value<int>()] = hours.ToArray();
3328
}
@@ -48,22 +43,8 @@ public override void WriteJson(JsonWriter writer, Timegrid value, JsonSerializer
4843
writer.WritePropertyName("timeUnits");
4944
writer.WriteStartArray(); // Write all school hours
5045
foreach (SchoolHour hour in schoolHours)
51-
{
52-
writer.WriteStartObject();
46+
serializer.Serialize(writer, hour);
5347

54-
writer.WritePropertyName("name");
55-
writer.WriteValue(hour.Name);
56-
57-
hour.StartTime.ToWebUntisTimeFormat(out string _, out string startTimeString);
58-
writer.WritePropertyName("startTime");
59-
writer.WriteValue(startTimeString);
60-
61-
hour.EndTime.ToWebUntisTimeFormat(out string _, out string endTimeString);
62-
writer.WritePropertyName("endTime");
63-
writer.WriteValue(endTimeString);
64-
65-
writer.WriteEndObject();
66-
}
6748
writer.WriteEndArray();
6849
writer.WriteEndObject();
6950
}

WebUntisAPI.Client/Models/Class.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class Class
2222
/// <summary>
2323
/// Id of the class
2424
/// </summary>
25-
[JsonProperty("id")]
2625
public int Id { get; set; }
2726

2827
/// <summary>
@@ -44,21 +43,5 @@ public class Class
4443
/// An array of all teachers of the class
4544
/// </summary>
4645
public int[] Teachers { get; set; }
47-
48-
/// <summary>
49-
/// Get all taechers of this class
50-
/// </summary>
51-
/// <param name="client">The client for the request (This should be the same client with that you requested the class)</param>
52-
/// <param name="id">Identifier for the request</param>
53-
/// <param name="ct">Cancellation token</param>
54-
/// <returns>The teachers of the class</returns>
55-
/// <exception cref="UnauthorizedAccessException">Thrown when the client aren't not logged in</exception>
56-
/// <exception cref="HttpRequestException">Thrown when there was an error while the http request</exception>
57-
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
58-
public async Task<Teacher[]> GetTeachersAsync(WebUntisClient client, string id = "getClassTeachers", CancellationToken ct = default)
59-
{
60-
int[] classTeachers = Teachers;
61-
return (await client.GetAllTeachersAsync(id, ct)).Where(t => classTeachers.Contains(t.Id)).ToArray();
62-
}
6346
}
6447
}

WebUntisAPI.Client/Models/SchoolHour.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using WebUntisAPI.Client.Converter;
89

910
namespace WebUntisAPI.Client.Models
1011
{
@@ -17,6 +18,7 @@ public class SchoolHour
1718
/// <summary>
1819
/// Name of the school hour
1920
/// </summary>
21+
[JsonProperty("name")]
2022
public string Name { get; set; }
2123

2224
/// <summary>
@@ -25,6 +27,8 @@ public class SchoolHour
2527
/// <remarks>
2628
/// Only <see cref="DateTime.Hour"/> and <see cref="DateTime.Minute"/> is set and the date is always set on the 1.1.2020
2729
/// </remarks>
30+
[JsonProperty("startTime")]
31+
[JsonConverter(typeof(TimeJsonConverter))]
2832
public DateTime StartTime { get; set; }
2933

3034
/// <summary>
@@ -33,6 +37,8 @@ public class SchoolHour
3337
/// <remarks>
3438
/// Only <see cref="DateTime.Hour"/> and <see cref="DateTime.Minute"/> is set and the date is always set on the 1.1.2020
3539
/// </remarks>
40+
[JsonProperty("endTime")]
41+
[JsonConverter(typeof(TimeJsonConverter))]
3642
public DateTime EndTime { get; set; }
3743
}
3844
}

WebUntisAPI.Client/Models/SchoolYear.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ public class SchoolYear : IEquatable<SchoolYear>, IComparable<SchoolYear>
1919
/// <summary>
2020
/// Id of the school year
2121
/// </summary>
22+
[JsonProperty("id")]
2223
public int Id { get; set; }
2324

2425
/// <summary>
2526
/// Name of the school year
2627
/// </summary>
27-
/// <remarks>
28-
/// Example value: 2022/2023
29-
/// </remarks>
28+
[JsonProperty("name")]
3029
public string Name { get; set; }
3130

3231
/// <summary>
3332
/// The date where the school year begins
3433
/// </summary>
34+
[JsonProperty("startDate")]
35+
[JsonConverter(typeof(DateJsonConverter))]
3536
public DateTime StartDate { get; set; }
3637

3738
/// <summary>
3839
/// The date where the school year ends
3940
/// </summary>
41+
[JsonProperty("endDate")]
42+
[JsonConverter(typeof(DateJsonConverter))]
4043
public DateTime EndDate { get; set; }
4144

42-
/// <inheritdoc/>
43-
public override string ToString() => Name;
44-
4545
#region IEquatable<SchoolYear>
4646
/// <inheritdoc/>
4747
public bool Equals(SchoolYear other) => Id.Equals(other.Id);

0 commit comments

Comments
 (0)