Enhance school simulation and management by integrating roster functionality, allowing for the installation and persistence of student and staff data. Update the school architecture to include a roster alongside existing components, ensuring proper validation against map layouts. Revise room definitions to support homeroom designations and update related tests to validate new functionalities and ensure robustness in roster handling.
ci / server (push) Failing after 3m43s
ci / client (push) Failing after 10s

This commit is contained in:
Leonid Pershin
2026-08-18 19:21:40 +03:00
parent e6182e0e45
commit 52c5082418
27 changed files with 732 additions and 66 deletions
+39 -3
View File
@@ -1,5 +1,6 @@
using System.Text.Json;
using HSchool.Content;
using HSchool.People;
using HSchool.Simulation;
using Microsoft.Extensions.Options;
@@ -101,7 +102,9 @@ internal sealed class SchoolStore
foreach (var path in Directory.EnumerateFiles(DirectoryPath, "*.json"))
{
if (string.Equals(Path.GetFileName(path), IndexFileName, StringComparison.OrdinalIgnoreCase))
var fileName = Path.GetFileName(path);
if (string.Equals(fileName, IndexFileName, StringComparison.OrdinalIgnoreCase)
|| fileName.EndsWith(".people.json", StringComparison.OrdinalIgnoreCase))
{
continue;
}
@@ -179,15 +182,48 @@ internal sealed class SchoolStore
{
File.Delete(path);
}
var people = PeoplePath(id);
if (File.Exists(people))
{
File.Delete(people);
}
}
public RosterDocument? TryReadPeople(int id)
{
var path = PeoplePath(id);
if (!File.Exists(path))
{
return null;
}
try
{
return RosterJson.Parse(File.ReadAllText(path));
}
catch (Exception ex)
{
throw new SchoolContentUnavailableException(
$"School {id} people file could not be read.",
ex);
}
}
public void SavePeople(int id, RosterDocument document)
{
WriteAtomic(PeoplePath(id), document, RosterJson.Options);
}
private string SchoolPath(int id) => Path.Combine(DirectoryPath, $"{id}.json");
private string PeoplePath(int id) => Path.Combine(DirectoryPath, $"{id}.people.json");
private string IndexPath() => Path.Combine(DirectoryPath, IndexFileName);
private static void WriteAtomic<T>(string path, T value)
private static void WriteAtomic<T>(string path, T value, JsonSerializerOptions? options = null)
{
var json = JsonSerializer.Serialize(value, Json);
var json = JsonSerializer.Serialize(value, options ?? Json);
var temp = path + ".tmp";
File.WriteAllText(temp, json);
File.Move(temp, path, overwrite: true);