From a64673ce0ccdf9fea205b619d07adf58c6bfff99 Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Sat, 13 May 2023 18:28:54 +0200 Subject: [PATCH] refactor Endpoint and LocalEndpoint assemblies to Services and LocalServices --- Endpoint/Endpoint.csproj | 13 -- LocalEndpoint/LocalEndpoint.csproj | 14 -- .../AccountOwnedRecipes.cs | 0 .../AccountRecipesPreferences.cs | 0 .../AccountServices.cs | 0 .../AuthService.cs | 0 {LocalEndpoint => LocalServices}/Constants.cs | 0 .../Data/AccountData.cs | 0 .../Data/CatastrophicPerformancesDatabase.cs | 0 .../Data/Database.cs | 0 .../Data/RecipeData.cs | 0 .../Data/UserData.cs | 0 .../LocalEndpoint.cs | 128 +++++++++--------- .../LocalServices.csproj | 2 +- .../RecipesService.cs | 0 Models/User.cs | 5 + .../IAccountOwnedRecipes.cs | 0 .../IAccountRecipesPreferences.cs | 0 {Endpoint => Services}/IAuthService.cs | 0 {Endpoint => Services}/IEndpoint.cs | 0 {Endpoint => Services}/IRecipesService.cs | 0 {Endpoint => Services}/Services.csproj | 26 ++-- ShoopNCook.csproj | 24 ++-- ShoopNCook.sln | 4 +- 24 files changed, 97 insertions(+), 119 deletions(-) delete mode 100644 Endpoint/Endpoint.csproj delete mode 100644 LocalEndpoint/LocalEndpoint.csproj rename {LocalEndpoint => LocalServices}/AccountOwnedRecipes.cs (100%) rename {LocalEndpoint => LocalServices}/AccountRecipesPreferences.cs (100%) rename {LocalEndpoint => LocalServices}/AccountServices.cs (100%) rename {LocalEndpoint => LocalServices}/AuthService.cs (100%) rename {LocalEndpoint => LocalServices}/Constants.cs (100%) rename {LocalEndpoint => LocalServices}/Data/AccountData.cs (100%) rename {LocalEndpoint => LocalServices}/Data/CatastrophicPerformancesDatabase.cs (100%) rename {LocalEndpoint => LocalServices}/Data/Database.cs (100%) rename {LocalEndpoint => LocalServices}/Data/RecipeData.cs (100%) rename {LocalEndpoint => LocalServices}/Data/UserData.cs (100%) rename {LocalEndpoint => LocalServices}/LocalEndpoint.cs (98%) rename {LocalEndpoint => LocalServices}/LocalServices.csproj (82%) rename {LocalEndpoint => LocalServices}/RecipesService.cs (100%) rename {Endpoint => Services}/IAccountOwnedRecipes.cs (100%) rename {Endpoint => Services}/IAccountRecipesPreferences.cs (100%) rename {Endpoint => Services}/IAuthService.cs (100%) rename {Endpoint => Services}/IEndpoint.cs (100%) rename {Endpoint => Services}/IRecipesService.cs (100%) rename {Endpoint => Services}/Services.csproj (95%) diff --git a/Endpoint/Endpoint.csproj b/Endpoint/Endpoint.csproj deleted file mode 100644 index d24baee..0000000 --- a/Endpoint/Endpoint.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net7.0 - enable - enable - - - - - - - diff --git a/LocalEndpoint/LocalEndpoint.csproj b/LocalEndpoint/LocalEndpoint.csproj deleted file mode 100644 index b84a3cb..0000000 --- a/LocalEndpoint/LocalEndpoint.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net7.0 - enable - enable - - - - - - - - diff --git a/LocalEndpoint/AccountOwnedRecipes.cs b/LocalServices/AccountOwnedRecipes.cs similarity index 100% rename from LocalEndpoint/AccountOwnedRecipes.cs rename to LocalServices/AccountOwnedRecipes.cs diff --git a/LocalEndpoint/AccountRecipesPreferences.cs b/LocalServices/AccountRecipesPreferences.cs similarity index 100% rename from LocalEndpoint/AccountRecipesPreferences.cs rename to LocalServices/AccountRecipesPreferences.cs diff --git a/LocalEndpoint/AccountServices.cs b/LocalServices/AccountServices.cs similarity index 100% rename from LocalEndpoint/AccountServices.cs rename to LocalServices/AccountServices.cs diff --git a/LocalEndpoint/AuthService.cs b/LocalServices/AuthService.cs similarity index 100% rename from LocalEndpoint/AuthService.cs rename to LocalServices/AuthService.cs diff --git a/LocalEndpoint/Constants.cs b/LocalServices/Constants.cs similarity index 100% rename from LocalEndpoint/Constants.cs rename to LocalServices/Constants.cs diff --git a/LocalEndpoint/Data/AccountData.cs b/LocalServices/Data/AccountData.cs similarity index 100% rename from LocalEndpoint/Data/AccountData.cs rename to LocalServices/Data/AccountData.cs diff --git a/LocalEndpoint/Data/CatastrophicPerformancesDatabase.cs b/LocalServices/Data/CatastrophicPerformancesDatabase.cs similarity index 100% rename from LocalEndpoint/Data/CatastrophicPerformancesDatabase.cs rename to LocalServices/Data/CatastrophicPerformancesDatabase.cs diff --git a/LocalEndpoint/Data/Database.cs b/LocalServices/Data/Database.cs similarity index 100% rename from LocalEndpoint/Data/Database.cs rename to LocalServices/Data/Database.cs diff --git a/LocalEndpoint/Data/RecipeData.cs b/LocalServices/Data/RecipeData.cs similarity index 100% rename from LocalEndpoint/Data/RecipeData.cs rename to LocalServices/Data/RecipeData.cs diff --git a/LocalEndpoint/Data/UserData.cs b/LocalServices/Data/UserData.cs similarity index 100% rename from LocalEndpoint/Data/UserData.cs rename to LocalServices/Data/UserData.cs diff --git a/LocalEndpoint/LocalEndpoint.cs b/LocalServices/LocalEndpoint.cs similarity index 98% rename from LocalEndpoint/LocalEndpoint.cs rename to LocalServices/LocalEndpoint.cs index ca4875b..d2d71d3 100644 --- a/LocalEndpoint/LocalEndpoint.cs +++ b/LocalServices/LocalEndpoint.cs @@ -1,65 +1,65 @@ -using Endpoint; -using LocalEndpoint.Data; -using Models; -using System.Collections.Immutable; - -namespace LocalEndpoint -{ - - /// - /// The local endpoint is an implementation of the Endpoint API definition. - /// - /// - public class LocalEndpoint : IEndpoint - { - private readonly IAuthService authService; - private readonly IRecipesService recipesService; - - - public LocalEndpoint() - { - var db = new CatastrophicPerformancesDatabase(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); - - if (db.IsEmpty()) - PrepareDatabase(db); - - recipesService = new RecipesService(db); - authService = new AuthService(db); - } - - public IAuthService AccountManager => authService; - - public IRecipesService RecipesService => recipesService; - - private static void PrepareDatabase(Database db) - { - User USER1 = new User(new Uri("https://i.ibb.co/L6t6bGR/DALL-E-2023-05-10-20-27-31-cook-looking-at-the-camera-with-a-chef-s-hat-laughing-in-an-exaggerated-w.png"), "The Funny Chief", MakeGuid(1)); - User USER2 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Yanis", MakeGuid(2)); - User USER3 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Leo", MakeGuid(3)); - - db.InsertUser(USER1); - db.InsertUser(USER2); - db.InsertUser(USER3); - - db.InsertAccount(new Account(USER1, "chief@cook.com"), "123456"); - db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456"); - db.InsertAccount(new Account(USER3, "leo@google.com"), "123456"); - - db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Fish", 50, 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList())); - } - - private static Guid MakeGuid(int seed) - { - var r = new Random(seed); - var guid = new byte[16]; - r.NextBytes(guid); - - return new Guid(guid); - } - } +using Endpoint; +using LocalEndpoint.Data; +using Models; +using System.Collections.Immutable; + +namespace LocalEndpoint +{ + + /// + /// The local endpoint is an implementation of the Endpoint API definition. + /// + /// + public class LocalEndpoint : IEndpoint + { + private readonly IAuthService authService; + private readonly IRecipesService recipesService; + + + public LocalEndpoint() + { + var db = new CatastrophicPerformancesDatabase(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); + + if (db.IsEmpty()) + PrepareDatabase(db); + + recipesService = new RecipesService(db); + authService = new AuthService(db); + } + + public IAuthService AccountManager => authService; + + public IRecipesService RecipesService => recipesService; + + private static void PrepareDatabase(Database db) + { + User USER1 = new User(new Uri("https://i.ibb.co/L6t6bGR/DALL-E-2023-05-10-20-27-31-cook-looking-at-the-camera-with-a-chef-s-hat-laughing-in-an-exaggerated-w.png"), "The Funny Chief", MakeGuid(1)); + User USER2 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Yanis", MakeGuid(2)); + User USER3 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Leo", MakeGuid(3)); + + db.InsertUser(USER1); + db.InsertUser(USER2); + db.InsertUser(USER3); + + db.InsertAccount(new Account(USER1, "chief@cook.com"), "123456"); + db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456"); + db.InsertAccount(new Account(USER3, "leo@google.com"), "123456"); + + db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Fish", 50, 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList())); + } + + private static Guid MakeGuid(int seed) + { + var r = new Random(seed); + var guid = new byte[16]; + r.NextBytes(guid); + + return new Guid(guid); + } + } } \ No newline at end of file diff --git a/LocalEndpoint/LocalServices.csproj b/LocalServices/LocalServices.csproj similarity index 82% rename from LocalEndpoint/LocalServices.csproj rename to LocalServices/LocalServices.csproj index 29b3db6..62f7504 100644 --- a/LocalEndpoint/LocalServices.csproj +++ b/LocalServices/LocalServices.csproj @@ -7,7 +7,7 @@ - + diff --git a/LocalEndpoint/RecipesService.cs b/LocalServices/RecipesService.cs similarity index 100% rename from LocalEndpoint/RecipesService.cs rename to LocalServices/RecipesService.cs diff --git a/Models/User.cs b/Models/User.cs index 21cd678..b70f7b1 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -27,5 +27,10 @@ namespace Models User? otherUser = other as User; return otherUser != null && Id.Equals(otherUser.Id); } + + override public int GetHashCode() + { + return Id.GetHashCode(); + } } } diff --git a/Endpoint/IAccountOwnedRecipes.cs b/Services/IAccountOwnedRecipes.cs similarity index 100% rename from Endpoint/IAccountOwnedRecipes.cs rename to Services/IAccountOwnedRecipes.cs diff --git a/Endpoint/IAccountRecipesPreferences.cs b/Services/IAccountRecipesPreferences.cs similarity index 100% rename from Endpoint/IAccountRecipesPreferences.cs rename to Services/IAccountRecipesPreferences.cs diff --git a/Endpoint/IAuthService.cs b/Services/IAuthService.cs similarity index 100% rename from Endpoint/IAuthService.cs rename to Services/IAuthService.cs diff --git a/Endpoint/IEndpoint.cs b/Services/IEndpoint.cs similarity index 100% rename from Endpoint/IEndpoint.cs rename to Services/IEndpoint.cs diff --git a/Endpoint/IRecipesService.cs b/Services/IRecipesService.cs similarity index 100% rename from Endpoint/IRecipesService.cs rename to Services/IRecipesService.cs diff --git a/Endpoint/Services.csproj b/Services/Services.csproj similarity index 95% rename from Endpoint/Services.csproj rename to Services/Services.csproj index d24baee..e45d1d7 100644 --- a/Endpoint/Services.csproj +++ b/Services/Services.csproj @@ -1,13 +1,13 @@ - - - - net7.0 - enable - enable - - - - - - - + + + + net7.0 + enable + enable + + + + + + + diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index 063bc5b..8a80861 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -48,28 +48,28 @@ - - + + - - + + - - + + - - + + - - + + @@ -118,8 +118,8 @@ - - + + diff --git a/ShoopNCook.sln b/ShoopNCook.sln index 6ca3619..3b6c720 100644 --- a/ShoopNCook.sln +++ b/ShoopNCook.sln @@ -8,9 +8,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServices", "LocalServices\LocalServices.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Endpoint", "Endpoint\Endpoint.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution