Skip to content

Commit fbaa79f

Browse files
committed
Add classreg events
1 parent 7471918 commit fbaa79f

4 files changed

Lines changed: 114 additions & 3 deletions

File tree

WebUntisAPI.Client/Exceptions/WebUntisException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace WebUntisAPI.Client.Exceptions
77
/// <summary>
88
/// An error that the WebUntis server returned
99
/// </summary>
10-
[DebuggerDisplay("Message = {Message}, Code = {Code}")]
10+
[DebuggerDisplay("Message = {Message, nq}, Code = {Code, nq}")]
1111
public class WebUntisException : Exception
1212
{
1313
/// <summary>
@@ -41,9 +41,9 @@ public enum Codes
4141
NoSuchElementFound = -7002,
4242

4343
/// <summary>
44-
/// Access dinied for substitutions
44+
/// Access dinied for the method
4545
/// </summary>
46-
NoRightForGetSubstitutions = -8509
46+
NoRightForMethod = -8509
4747
}
4848

4949
/// <summary>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using WebUntisAPI.Client.Converter;
9+
10+
namespace WebUntisAPI.Client.Models
11+
{
12+
/// <summary>
13+
/// A classreg event
14+
/// </summary>
15+
[DebuggerDisplay("On: {Date, nq}, Student: {Forename, nq} {Surname, nq}")]
16+
public class ClassregEvent
17+
{
18+
/// <summary>
19+
/// The id of the involved student
20+
/// </summary>
21+
[JsonProperty("studentId")]
22+
public int StudentId { get; set; }
23+
24+
/// <summary>
25+
/// The forename of the involved student
26+
/// </summary>
27+
[JsonProperty("forename")]
28+
public string Forename { get; set; }
29+
30+
/// <summary>
31+
/// The surname of the involved student
32+
/// </summary>
33+
[JsonProperty("surname")]
34+
public string Surname { get; set; }
35+
36+
/// <summary>
37+
/// The date where the event happens
38+
/// </summary>
39+
[JsonProperty("date")]
40+
[JsonConverter(typeof(DateJsonConverter))]
41+
public DateTime Date { get; set; }
42+
43+
/// <summary>
44+
/// The subject what is involved
45+
/// </summary>
46+
[JsonProperty("subject")]
47+
public string Subject { get; set; }
48+
49+
/// <summary>
50+
/// The reason why this happend
51+
/// </summary>
52+
[JsonProperty("reason")]
53+
public string Reason { get; set; }
54+
55+
/// <summary>
56+
/// Additional text to the event
57+
/// </summary>
58+
[JsonProperty("text")]
59+
public string Text { get; set; }
60+
61+
/// <summary>
62+
/// Id of the category
63+
/// </summary>
64+
[JsonProperty("categoryId")]
65+
public int CategoryId { get; set; }
66+
}
67+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
using WebUntisAPI.Client.Converter;
8+
9+
namespace WebUntisAPI.Client.Models
10+
{
11+
internal struct GetClassregEventsRequestModel
12+
{
13+
[JsonProperty("startDate")]
14+
[JsonConverter(typeof(DateJsonConverter))]
15+
public DateTime StartDate { get; set; }
16+
17+
[JsonProperty("endDate")]
18+
[JsonConverter(typeof(DateJsonConverter))]
19+
public DateTime EndDate { get; set; }
20+
}
21+
}

WebUntisAPI.Client/WebUntisClient.Teaching.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,28 @@ public async Task<Department[]> GetAllDepartmentsAsync(string id = "getDepartmen
9090
List<Department> departments = await MakeRequestAsync<object, List<Department>>(id, "getDepartments", new object(), ct);
9191
return departments.ToArray();
9292
}
93+
94+
/// <summary>
95+
/// Get all classreg events
96+
/// </summary>
97+
/// <param name="startDate">Start date for the requested events</param>
98+
/// <param name="endDate">End date for the requested events</param>
99+
/// <param name="id">Identifier for the request</param>
100+
/// <param name="ct">Cancellatio token</param>
101+
/// <returns>All classreg events in the given date range</returns>
102+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
103+
/// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
104+
/// <exception cref="HttpRequestException">Thrown when an error happend while the http request</exception>
105+
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
106+
public async Task<ClassregEvent[]> GetClassregEventsAsync(DateTime startDate, DateTime endDate, string id = "getCLassregEvents", CancellationToken ct = default)
107+
{
108+
GetClassregEventsRequestModel model = new GetClassregEventsRequestModel()
109+
{
110+
StartDate = startDate,
111+
EndDate = endDate
112+
};
113+
List<ClassregEvent> classregEvents = await MakeRequestAsync<GetClassregEventsRequestModel, List<ClassregEvent>>(id, "getClassregEvents", model, ct);
114+
return classregEvents.ToArray();
115+
}
93116
}
94117
}

0 commit comments

Comments
 (0)