refactor Endpoint and LocalEndpoint assemblies to Services and LocalServices
continuous-integration/drone/push Build is passing Details

pull/52/head
maxime.BATISTA@etu.uca.fr 2 years ago
parent eb4d0cf7ca
commit a64673ce0c

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
</Project>

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Endpoint\Endpoint.csproj" />
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
</Project>

@ -1,65 +1,65 @@
using Endpoint; using Endpoint;
using LocalEndpoint.Data; using LocalEndpoint.Data;
using Models; using Models;
using System.Collections.Immutable; using System.Collections.Immutable;
namespace LocalEndpoint namespace LocalEndpoint
{ {
/// <summary> /// <summary>
/// The local endpoint is an implementation of the Endpoint API definition. /// The local endpoint is an implementation of the Endpoint API definition.
/// ///
/// </summary> /// </summary>
public class LocalEndpoint : IEndpoint public class LocalEndpoint : IEndpoint
{ {
private readonly IAuthService authService; private readonly IAuthService authService;
private readonly IRecipesService recipesService; private readonly IRecipesService recipesService;
public LocalEndpoint() public LocalEndpoint()
{ {
var db = new CatastrophicPerformancesDatabase(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); var db = new CatastrophicPerformancesDatabase(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
if (db.IsEmpty()) if (db.IsEmpty())
PrepareDatabase(db); PrepareDatabase(db);
recipesService = new RecipesService(db); recipesService = new RecipesService(db);
authService = new AuthService(db); authService = new AuthService(db);
} }
public IAuthService AccountManager => authService; public IAuthService AccountManager => authService;
public IRecipesService RecipesService => recipesService; public IRecipesService RecipesService => recipesService;
private static void PrepareDatabase(Database db) 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 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 USER2 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Yanis", MakeGuid(2));
User USER3 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Leo", MakeGuid(3)); User USER3 = new User(Constants.DEFAULT_ACCOUNT_IMAGE, "Leo", MakeGuid(3));
db.InsertUser(USER1); db.InsertUser(USER1);
db.InsertUser(USER2); db.InsertUser(USER2);
db.InsertUser(USER3); db.InsertUser(USER3);
db.InsertAccount(new Account(USER1, "chief@cook.com"), "123456"); db.InsertAccount(new Account(USER1, "chief@cook.com"), "123456");
db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456"); db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456");
db.InsertAccount(new Account(USER3, "leo@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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List<PreparationStep> { 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<Ingredient> { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.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<Ingredient> { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List<PreparationStep> { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList()));
} }
private static Guid MakeGuid(int seed) private static Guid MakeGuid(int seed)
{ {
var r = new Random(seed); var r = new Random(seed);
var guid = new byte[16]; var guid = new byte[16];
r.NextBytes(guid); r.NextBytes(guid);
return new Guid(guid); return new Guid(guid);
} }
} }
} }

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Endpoint\Services.csproj" /> <ProjectReference Include="..\Services\Services.csproj" />
<ProjectReference Include="..\Models\Models.csproj" /> <ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup> </ItemGroup>

@ -27,5 +27,10 @@ namespace Models
User? otherUser = other as User; User? otherUser = other as User;
return otherUser != null && Id.Equals(otherUser.Id); return otherUser != null && Id.Equals(otherUser.Id);
} }
override public int GetHashCode()
{
return Id.GetHashCode();
}
} }
} }

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Models\Models.csproj" /> <ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -48,28 +48,28 @@
<ItemGroup> <ItemGroup>
<AndroidResource Remove="ShopNCookTests\**" /> <AndroidResource Remove="ShopNCookTests\**" />
<AndroidResource Remove="Tests\**" /> <AndroidResource Remove="Tests\**" />
<Compile Remove="Endpoint\**" /> <Compile Remove="Services\**" />
<Compile Remove="LocalEndpoint\**" /> <Compile Remove="LocalServices\**" />
<Compile Remove="Models\**" /> <Compile Remove="Models\**" />
<Compile Remove="ShopNCookTests\**" /> <Compile Remove="ShopNCookTests\**" />
<Compile Remove="Tests\**" /> <Compile Remove="Tests\**" />
<EmbeddedResource Remove="Endpoint\**" /> <EmbeddedResource Remove="Services\**" />
<EmbeddedResource Remove="LocalEndpoint\**" /> <EmbeddedResource Remove="LocalServices\**" />
<EmbeddedResource Remove="Models\**" /> <EmbeddedResource Remove="Models\**" />
<EmbeddedResource Remove="ShopNCookTests\**" /> <EmbeddedResource Remove="ShopNCookTests\**" />
<EmbeddedResource Remove="Tests\**" /> <EmbeddedResource Remove="Tests\**" />
<MauiCss Remove="Endpoint\**" /> <MauiCss Remove="Services\**" />
<MauiCss Remove="LocalEndpoint\**" /> <MauiCss Remove="LocalServices\**" />
<MauiCss Remove="Models\**" /> <MauiCss Remove="Models\**" />
<MauiCss Remove="ShopNCookTests\**" /> <MauiCss Remove="ShopNCookTests\**" />
<MauiCss Remove="Tests\**" /> <MauiCss Remove="Tests\**" />
<MauiXaml Remove="Endpoint\**" /> <MauiXaml Remove="Services\**" />
<MauiXaml Remove="LocalEndpoint\**" /> <MauiXaml Remove="LocalServices\**" />
<MauiXaml Remove="Models\**" /> <MauiXaml Remove="Models\**" />
<MauiXaml Remove="ShopNCookTests\**" /> <MauiXaml Remove="ShopNCookTests\**" />
<MauiXaml Remove="Tests\**" /> <MauiXaml Remove="Tests\**" />
<None Remove="Endpoint\**" /> <None Remove="Services\**" />
<None Remove="LocalEndpoint\**" /> <None Remove="LocalServices\**" />
<None Remove="Models\**" /> <None Remove="Models\**" />
<None Remove="ShopNCookTests\**" /> <None Remove="ShopNCookTests\**" />
<None Remove="Tests\**" /> <None Remove="Tests\**" />
@ -118,8 +118,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="Endpoint\Endpoint.csproj" /> <ProjectReference Include="Services\Services.csproj" />
<ProjectReference Include="LocalEndpoint\LocalEndpoint.csproj" /> <ProjectReference Include="LocalServices\LocalServices.csproj" />
<ProjectReference Include="Models\Models.csproj" /> <ProjectReference Include="Models\Models.csproj" />
</ItemGroup> </ItemGroup>

@ -8,9 +8,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}"
EndProject 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

Loading…
Cancel
Save