#Refactor WondersController: Apply Clean Code principles (Uncle Bob style)

هذا الالتزام موجود في:
2025-10-06 00:15:04 +03:00
الأصل 9511f1928b
التزام 0eea59051e
7 ملفات معدلة مع 357 إضافات و76 حذوفات

عرض الملف

@@ -5,18 +5,25 @@ namespace WondersAPI.Data
{
public static class DataSeedingApplication
{
public static List<Wonder> SeedWonders(string filePath)
{
if (!File.Exists(filePath))
throw new FileNotFoundException($"Seed data file not found: {filePath}");
public static List<Wonder> LoadWondersFromJsonFile(string jsonFilePath) =>
ReadAndConvertJsonToWonders(jsonFilePath);
var json = File.ReadAllText(filePath);
var wonders = JsonSerializer.Deserialize<List<Wonder>>(json, new JsonSerializerOptions
private static List<Wonder> ReadAndConvertJsonToWonders(string jsonFilePath)
{
ThrowIfJsonFileDoesNotExist(jsonFilePath);
return ConvertJsonStringToWonderList(File.ReadAllText(jsonFilePath));
}
private static void ThrowIfJsonFileDoesNotExist(string jsonFilePath)
{
if (!File.Exists(jsonFilePath))
throw new FileNotFoundException($"The seed data file was not found at path: {jsonFilePath}");
}
private static List<Wonder> ConvertJsonStringToWonderList(string jsonString) =>
JsonSerializer.Deserialize<List<Wonder>>(jsonString, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
return wonders ?? new List<Wonder>();
}
}) ?? new List<Wonder>();
}
}
}