Ajout du managerData

master
Thomas Chazot 2 years ago
parent bc7de911eb
commit c6e7171d0a

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace ApiLol.Controllers;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}

@ -0,0 +1,26 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:44889",
"sslPort": 44302
}
},
"profiles": {
"ApiLol": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7006;http://localhost:5131",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,13 @@
namespace ApiLol;
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -5,9 +5,29 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\EFLib\EFLib.csproj" /> <ProjectReference Include="..\DataManagers\DataManagers.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.EntityFrameworkCore" />
<None Remove="Microsoft.EntityFrameworkCore.Design" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite.Core" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -1,4 +1,11 @@
using EFLib; // See https://aka.ms/new-console-template for more information
using DataManagers;
using Model;
ChampionEntity ChampionEntity Console.WriteLine("Hello, World!");
using (var db = new DbDataManager(new EFLib.LolContext()))
{
Champion champ = await db.Add(new Model.Champion("marche", Model.ChampionClass.Assassin, "ouii", "yes", "bio"));
Console.WriteLine(champ.Name);
}

@ -0,0 +1,25 @@
using System;
using EFLib;
using Model;
namespace DataManagers
{
public static class ChampChanger
{
public static Champion ToPoco(this ChampionEntity champion)
{
return new Champion(name: champion.Name, champClass: ChampionClass.Unknown, icon: champion.Icon, bio: champion.Bio);
}
public static ChampionEntity ToEntity(this Champion champion)
{
return new ChampionEntity
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
};
}
}
}

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

@ -0,0 +1,104 @@
using System;
using Microsoft.EntityFrameworkCore;
using Model;
using EFLib;
namespace DataManagers
{
public class DbChampionManager : IChampionsManager
{
private LolContext Context { get; set; }
public DbChampionManager(LolContext context)
{
Context = context;
}
public Task<Champion?> AddItem(Champion? item)
{
throw new NotImplementedException();
}
public Task<bool> DeleteItem(Champion? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<int> GetNbItems()
{
return await Task.Run(() => Context.Champions.Count());
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,50 @@
using System;
using EFLib;
using Model;
namespace DataManagers
{
public class DbDataManager : IDataManager
{
private LolContext Context { get; set; }
public IChampionsManager ChampionsMgr => throw new NotImplementedException();
public ISkinsManager SkinsMgr => throw new NotImplementedException();
public IRunesManager RunesMgr => throw new NotImplementedException();
public IRunePagesManager RunePagesMgr => throw new NotImplementedException();
public DbDataManager(LolContext context)
{
Context = context;
}
public async Task<int> GetNumbersOfElement()
{
return await Task.Run(() => Context.Champions.Count());
}
public async Task<Champion> GetById(int id)
{
return await Task.Run(() => Context.Champions.SingleOrDefault((ChampionEntity arg) => arg.Id == id).ToPoco());
}
public async Task<Champion> Add(Champion champ)
{
ChampionEntity entity = champ.ToEntity();
await Context.Champions.AddAsync(entity);
Context.SaveChanges();
return await Task.Run(() => Context.Champions.SingleOrDefault((ChampionEntity arg) => arg.Name == champ.Name && arg.Bio == champ.Bio).ToPoco());
}
public void Dispose()
{
Context.Dispose();
}
}
}

@ -1,4 +1,6 @@
using System; using System;
using Model;
namespace EFLib namespace EFLib
{ {
public class ChampionEntity public class ChampionEntity
@ -12,6 +14,8 @@ namespace EFLib
public string Bio { get; set; } public string Bio { get; set; }
public ChampionClass champClass { get; set;}
} }
} }

@ -26,4 +26,7 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project> </Project>

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
namespace EFLib namespace EFLib
{ {
public class LolContext : DbContext public class LolContext : DbContext, IDisposable
{ {
public DbSet<ChampionEntity> Champions { get; set; } public DbSet<ChampionEntity> Champions { get; set; }

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EFLib.Migrations namespace EFLib.Migrations
{ {
[DbContext(typeof(LolContext))] [DbContext(typeof(LolContext))]
[Migration("20230126083419_oiseaux")] [Migration("20230201085244_oiseaux")]
partial class oiseaux partial class oiseaux
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -37,9 +37,12 @@ namespace EFLib.Migrations
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("champClass")
.HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("champions"); b.ToTable("Champions");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

@ -11,18 +11,19 @@ namespace EFLib.Migrations
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "champions", name: "Champions",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "INTEGER", nullable: false) Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false), Name = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false), Icon = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", nullable: false) Bio = table.Column<string>(type: "TEXT", nullable: false),
champClass = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_champions", x => x.Id); table.PrimaryKey("PK_Champions", x => x.Id);
}); });
} }
@ -30,7 +31,7 @@ namespace EFLib.Migrations
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "champions"); name: "Champions");
} }
} }
} }

@ -34,9 +34,12 @@ namespace EFLib.Migrations
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("champClass")
.HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("champions"); b.ToTable("Champions");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

@ -1,3 +1,15 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using EFLib;
Console.WriteLine("Hello, World!"); Console.WriteLine("Hello, World!");
using (var context = new LolContext())
{
context.Champions.Add(new ChampionEntity
{
Name = "Test",
Bio = "Bonjour",
Icon = "Wouhou"
});
context.SaveChanges();
}

@ -19,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFLib", "EFLib\EFLib.csproj
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDb", "ConsoleDb\ConsoleDb.csproj", "{30AF9CBD-1E40-46F2-973F-6C13F1E15660}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDb", "ConsoleDb\ConsoleDb.csproj", "{30AF9CBD-1E40-46F2-973F-6C13F1E15660}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataManagers", "DataManagers\DataManagers.csproj", "{C9FEBC1B-0157-4D48-8AFF-D3805289D083}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiLol", "ApiLol\ApiLol.csproj", "{51E7E6BF-95E8-4B0E-BB03-330893931C17}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -49,6 +53,14 @@ Global
{30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Debug|Any CPU.Build.0 = Debug|Any CPU {30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Release|Any CPU.ActiveCfg = Release|Any CPU {30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Release|Any CPU.Build.0 = Release|Any CPU {30AF9CBD-1E40-46F2-973F-6C13F1E15660}.Release|Any CPU.Build.0 = Release|Any CPU
{C9FEBC1B-0157-4D48-8AFF-D3805289D083}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9FEBC1B-0157-4D48-8AFF-D3805289D083}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9FEBC1B-0157-4D48-8AFF-D3805289D083}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9FEBC1B-0157-4D48-8AFF-D3805289D083}.Release|Any CPU.Build.0 = Release|Any CPU
{51E7E6BF-95E8-4B0E-BB03-330893931C17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51E7E6BF-95E8-4B0E-BB03-330893931C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51E7E6BF-95E8-4B0E-BB03-330893931C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51E7E6BF-95E8-4B0E-BB03-330893931C17}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -3,7 +3,7 @@ using Shared;
namespace Model namespace Model
{ {
public interface IDataManager public interface IDataManager : IDisposable
{ {
IChampionsManager ChampionsMgr { get; } IChampionsManager ChampionsMgr { get; }
ISkinsManager SkinsMgr { get; } ISkinsManager SkinsMgr { get; }

@ -29,7 +29,9 @@ public partial class StubData : IDataManager
championsAndRunePages.Add(Tuple.Create(champions[0], runePages[0])); championsAndRunePages.Add(Tuple.Create(champions[0], runePages[0]));
} }
public void Dispose()
{
}
} }

Loading…
Cancel
Save