Skip to content

Commit f790f0c

Browse files
committed
Add method to get classes for a school year
1 parent 8bd83d8 commit f790f0c

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

API.Test/ExtensionsTests/DateTimeExtensionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void ToWebUntisTimeFormatTest()
1717
{
1818
// Example 1 (True)
1919
new DateTime(2023, 5, 31, 20, 0, 0).ToWebUntisTimeFormat(out string E1_Date, out string E1_Time);
20-
string E1_Date_Res = "2023-05-31";
20+
string E1_Date_Res = "20230531";
2121
string E1_Time_Res = "2000";
2222
Assert.Multiple(() =>
2323
{
@@ -27,7 +27,7 @@ public static void ToWebUntisTimeFormatTest()
2727

2828
// Example 2 (True)
2929
new DateTime(2019, 12, 2, 7, 40, 0).ToWebUntisTimeFormat(out string E2_Date, out string E2_Time);
30-
string E2_Date_Res = "2019-12-02";
30+
string E2_Date_Res = "20191202";
3131
string E2_Time_Res = "740";
3232
Assert.Multiple(() =>
3333
{
@@ -41,13 +41,13 @@ public static void ToWebUntisTimeFormatTest()
4141
public static void FromWebUntisTimeFormatTest()
4242
{
4343
// Example 1
44-
string E1_Date = "2023-05-31";
44+
string E1_Date = "20230531";
4545
string E1_Time = "2000";
4646
DateTime? E1_DateTime = new DateTime().FromWebUntisTimeFormat(E1_Date, E1_Time);
4747
Assert.That(new DateTime(2023, 5, 31, 20, 0, 0), Is.EqualTo(E1_DateTime));
4848

4949
// Example 2
50-
string E2_Date = "2023-06-01";
50+
string E2_Date = "20230601";
5151
string E2_Time = "740";
5252
DateTime? E2_DateTime = new DateTime().FromWebUntisTimeFormat(E2_Date, E2_Time);
5353
Assert.That(new DateTime(2023, 6, 1, 7, 40, 0), Is.EqualTo(E2_DateTime));

API.Test/TeachingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void GetClass()
3030
{
3131
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
3232

33-
Task<Class[]> classes = Client.GetAllClassesAsync();
33+
Task<Class[]> classes = Client.GetClassesAsync(new SchoolYear() { Id = 5});
3434
classes.Wait();
3535
if (classes.Result.Length > 0)
3636
Assert.Pass();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace WebUntisAPI.Client.Models
9+
{
10+
internal struct SchoolYearModel
11+
{
12+
[JsonProperty("id")]
13+
public int Id { get; set; }
14+
}
15+
}

WebUntisAPI.Client/WebUntisClient.Teaching.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,38 @@ public async Task<Subject[]> GetAllSubjectsAsync(string id = "getSubjects", Canc
3232
}
3333

3434
/// <summary>
35-
/// Get all classes on the school
35+
/// Get all classes on the school from the current school year
3636
/// </summary>
3737
/// <param name="id">Identifier of the request</param>
3838
/// <param name="ct">Cancellation token</param>
39-
/// <returns>All classes on the school</returns>
39+
/// <returns>All classes on the school from current school year</returns>
4040
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
4141
/// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
4242
/// <exception cref="HttpRequestException">Thrown when an error happend while the hppt request</exception>
4343
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
4444
public async Task<Class[]> GetAllClassesAsync(string id = "getClasses", CancellationToken ct = default)
4545
{
46-
//TODO: School year overload
47-
4846
List<Class> classes = await MakeRequestAsync<object, List<Class>>(id, "getKlassen", new object(), ct);
4947
return classes.ToArray();
5048
}
5149

50+
/// <summary>
51+
/// Get all classes on the school from the selected school year
52+
/// </summary>
53+
/// <param name="id">Identifier of the request</param>
54+
/// <param name="ct">Cancellation token</param>
55+
/// <param name="schoolYear">The school year from the classes</param>
56+
/// <returns>All classes on the school for the school year</returns>
57+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
58+
/// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
59+
/// <exception cref="HttpRequestException">Thrown when an error happend while the hppt request</exception>
60+
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
61+
public async Task<Class[]> GetClassesAsync(SchoolYear schoolYear, string id = "getClassesBySchoolYear", CancellationToken ct = default)
62+
{
63+
List<Class> classes = await MakeRequestAsync<SchoolYearModel, List<Class>>(id, "getKlassen", new SchoolYearModel() { Id = schoolYear.Id }, ct);
64+
return classes.ToArray();
65+
}
66+
5267
/// <summary>
5368
/// Get all rooms on the school
5469
/// </summary>

0 commit comments

Comments
 (0)