api : franchement je vais être franc, faut avancer la partie EF, elle bloque la partie api

master
pasquizzat 2 years ago
parent 440c62d49d
commit 26fdad3ef8

@ -12,6 +12,7 @@
<ItemGroup>
<ProjectReference Include="..\StubLib\StubLib.csproj" />
<ProjectReference Include="..\TrucAuMilieu\TrucAuMilieu.csproj" />
</ItemGroup>
</Project>

@ -15,9 +15,10 @@ namespace ApiDePaul.Controllers
private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
public ChampionController(ILogger<ChampionController> logger,IDataManager datamgr)
{
_logger = logger;
this.donnees = datamgr;
}
[HttpGet]
@ -92,16 +93,16 @@ namespace ApiDePaul.Controllers
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
}
[HttpPost("Ajouter")]
/* en fait cet ajouter sert à rien, vu que la liste peut contenir un champion
[HttpPost("AjouterUnSeul")]
public async Task<ActionResult> PostChamp([FromBody] ChampionDto c)
{
Champion ca = c.DtoToChamp();
//return Ok(await donnees.ChampionsMgr.AddItem(ca));
await donnees.ChampionsMgr.AddItem(ca);
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
}
[HttpPost("AjouterPlus")]
}*/
[HttpPost("Ajouter")]
public async Task<ActionResult> PostChamps([FromBody] List<ChampionDto> lc)
{
foreach(ChampionDto c in lc)
@ -127,16 +128,16 @@ namespace ApiDePaul.Controllers
return BadRequest();
}
[HttpPut("{id}/Modifier")]
/* pareil que pour ajouter, pas besoin de faire qu'un seul champion quand une liste suffit
[HttpPut("{id}/ModifierUnSeul")]
public async Task<ActionResult> PutChamp(int id, [FromBody] ChampionDto c)
{
IEnumerable<Champion?> oldChamp = await donnees.ChampionsMgr.GetItems(id, 1);
Champion champion1 = oldChamp.First();
Champion champion2 = c.DtoToChamp();
return Ok(await donnees.ChampionsMgr.UpdateItem(champion1, champion2));
}
[HttpPut("{id}/ModifierPlus")]
}*/
[HttpPut("{id}/Modifier")]
public async Task<ActionResult> PutChamps(int id, [FromBody] List<ChampionDto> lc)
{
IEnumerable<Champion?> oldChamp = await donnees.ChampionsMgr.GetItems(id, lc.Count());

@ -0,0 +1,37 @@
using ApiDePaul.Conversion;
using ApiDePaul.DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using System.Collections.Generic;
using System.Diagnostics;
namespace ApiDePaul.Controllers
{
[ApiController]
[Route("[controller]")]
public class RuneController : ControllerBase
{
IDataManager donnees = new StubData();
private readonly ILogger<RuneController> _logger;
public RuneController(ILogger<RuneController> logger, IDataManager datamgr)
{
_logger = logger;
//this.donnees = datamgr;
}
[HttpGet]
public async Task<ActionResult<RuneDto>> GetRunes()
{
IEnumerable<Rune?> lrun = await donnees.RunesMgr.GetItems(0, donnees.RunesMgr.GetNbItems().Result);
List<RuneDto> runes = new List<RuneDto>();
lrun.ToList().ForEach(r => runes.Add(r.RuneToDto()));
return Ok(runes);
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using ApiDePaul.Conversion;
using ApiDePaul.DTO;
using Model;
using static System.Net.Mime.MediaTypeNames;
@ -24,13 +25,16 @@ namespace ApiDePaul
{
champ.Characteristics.Add(new Tuple<string,int>(ch.Key, ch.Value));
}
//Characteristics = c.Characteristics.ToDictionary(x => x.Key, x => x.Value)
foreach(var sk in c.Skills)
{
champ.Skills.Add(sk.SkillToDto());
}
return champ;
}
public static Champion DtoToChamp(this ChampionDto c)
{
Champion champ = new Champion(c.Name);
string[] classes = { "Unknown", "Assassin", "Fighter", "Mage", "Marksman", "Support", "Tank" };
var classes = Enum.GetNames(typeof(ChampionClass));
if (classes.ToList().Contains(c.Class))
{
champ.Class=(ChampionClass)Enum.Parse(typeof(ChampionClass), c.Class);
@ -45,7 +49,7 @@ namespace ApiDePaul
foreach(var s in c.Skills)
{
champ.AddSkill(s);
champ.AddSkill(s.DtoToSkill());
}
champ.AddCharacteristics(c.Characteristics.ToArray());
/*

@ -0,0 +1,38 @@
using ApiDePaul.DTO;
using Model;
namespace ApiDePaul.Conversion
{
public static class RuneMapping
{
public static RuneDto RuneToDto(this Rune r)
{
RuneDto run = new RuneDto();
run.Name = r.Name;
run.Description = r.Description;
run.Icon = r.Icon;
run.Image = r.Image.ToString();
run.Family = r.Family.ToString();
return run;
}
public static Rune DtoToRune(this RuneDto r)
{
RuneFamily fam;
string[] families = { "Unknown", "Precision", "Domination" };
if (families.ToList().Contains(r.Family))
{
fam = (RuneFamily)Enum.Parse(typeof(RuneFamily), r.Family);
}
else
{
fam = 0;
}
Rune run = new Rune(r.Name, fam);
run.Icon = r.Icon;
run.Image = new LargeImage(r.Image);
run.Description = r.Description;
return run;
}
}
}

@ -0,0 +1,33 @@
using ApiDePaul.DTO;
using Model;
namespace ApiDePaul.Conversion
{
public static class SkillMapping
{
public static SkillDto SkillToDto(this Skill s)
{
SkillDto ski = new SkillDto();
ski.Name = s.Name;
ski.Type = s.Type.ToString();
ski.Description = s.Description;
return ski;
}
public static Skill DtoToSkill(this SkillDto ski)
{
var types = Enum.GetNames(typeof(SkillType)).ToList();
SkillType type;
if (types.Contains(ski.Type.ToString()))
{
type = (SkillType)Enum.Parse(typeof(SkillType), ski.Type);
}
else
{
type = 0;
}
Skill s = new Skill(ski.Name, type,ski.Description);
return s;
}
}
}

@ -12,6 +12,6 @@ namespace ApiDePaul.DTO
public string Image { get; set; }
public List<SkinDto> Skins { get; set; }
public List<Tuple<string,int>> Characteristics { get; set; }
public HashSet<Skill> Skills { get; set; }
public List<SkillDto> Skills { get; set; }
}
}

@ -0,0 +1,11 @@
namespace ApiDePaul.DTO
{
public class RuneDto
{
public string Name { get; set; }
public string Description { get; set; }
public string Family { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
}
}

@ -0,0 +1,9 @@
namespace ApiDePaul.DTO
{
public class SkillDto
{
public string Name { get; set; }
public string Type { get; set; }
public string Description { get; set; }
}
}

@ -1,5 +1,6 @@
using Model;
using StubLib;
using TrucAuMilieu;
var builder = WebApplication.CreateBuilder(args);
@ -9,7 +10,8 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IDataManager, StubData>();
//builder.Services.AddScoped<IDataManager, StubData>();
builder.Services.AddScoped<IDataManager, DataBdd>();
var app = builder.Build();
// Configure the HTTP request pipeline.

Binary file not shown.

Binary file not shown.

@ -32,6 +32,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrucAuMilieu", "TrucAuMilie
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDePaul", "ApiDePaul\ApiDePaul.csproj", "{245F7BAC-8487-4510-8066-D12B5B2B816B}"
ProjectSection(ProjectDependencies) = postProject
{00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C} = {00B54DCE-F7B5-4C3A-AC91-EF6BAB1AD36C}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}
EndProjectSection
EndProject

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ApiDePaul\ApiDePaul.csproj" />
<ProjectReference Include="..\Model2\LibEntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>

Loading…
Cancel
Save