#Refactor WondersController: Apply Clean Code principles (Uncle Bob style)
هذا الالتزام موجود في:
@@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
المرجع في مشكلة جديدة
حظر مستخدم