Skip to content

Commit d5cc7ec

Browse files
committed
Add departments and their get method
1 parent b9877e5 commit d5cc7ec

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

API.Test/TeachingTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@ public void GetRoom()
5050
else
5151
Assert.Fail();
5252
}
53+
54+
[Test]
55+
public void GetDepartment()
56+
{
57+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
58+
59+
Task<Department[]> departments = Client.GetAllDepartmentsAsync();
60+
departments.Wait();
61+
if (departments.Result != null)
62+
Assert.Pass();
63+
else
64+
Assert.Fail();
65+
}
5366
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
9+
namespace WebUntisAPI.Client.Models
10+
{
11+
/// <summary>
12+
/// A department
13+
/// </summary>
14+
[DebuggerDisplay("Name: {Name, nq}")]
15+
public class Department
16+
{
17+
/// <summary>
18+
/// Id of the department
19+
/// </summary>
20+
[JsonProperty("id")]
21+
public int Id { get; set; }
22+
23+
/// <summary>
24+
/// Name of the department
25+
/// </summary>
26+
[JsonProperty("name")]
27+
public string Name { get; set; }
28+
29+
/// <summary>
30+
/// Long name of the department
31+
/// </summary>
32+
[JsonProperty("longName")]
33+
public string LongName { get; set; }
34+
}
35+
}

WebUntisAPI.Client/WebUntisClient.Teaching.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,21 @@ public async Task<Room[]> GetAllRoomsAsync(string id = "getRooms", CancellationT
7979
List<Room> rooms = await MakeRequestAsync<object, List<Room>>(id, "getRooms", new object(), ct);
8080
return rooms.ToArray();
8181
}
82+
83+
/// <summary>
84+
/// Get all departments
85+
/// </summary>
86+
/// <param name="id">Identifier for request</param>
87+
/// <param name="ct">Cancellation token</param>
88+
/// <returns>All departments</returns>
89+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
90+
/// <exception cref="UnauthorizedAccessException">Thrown when you're not logged in</exception>
91+
/// <exception cref="HttpRequestException">Thrown when an error happend while the http request</exception>
92+
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
93+
public async Task<Department[]> GetAllDepartmentsAsync(string id = "getDepartments", CancellationToken ct = default)
94+
{
95+
List<Department> departments = await MakeRequestAsync<object, List<Department>>(id, "getDepartments", new object(), ct);
96+
return departments.ToArray();
97+
}
8298
}
8399
}

0 commit comments

Comments
 (0)