api : franchement ça avance plutot bien, ce serait peut etre le temps de faire des tests, on sait jamais

master
pasquizzat 2 years ago
parent ec99ef34cc
commit 31aa15ace3

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using System.Collections.Generic;
using System.Diagnostics;
namespace ApiDePaul.Controllers
{
@ -41,6 +42,12 @@ namespace ApiDePaul.Controllers
}
return BadRequest();
}
[HttpGet("nombre")]
public async Task<ActionResult<int>> GetNombreChamp()
{
int nb = await donnees.ChampionsMgr.GetNbItems();
return Ok(nb);
}
[HttpGet("{id}/Skins")]
@ -90,8 +97,9 @@ namespace ApiDePaul.Controllers
public async Task<ActionResult> PostChamp([FromBody] ChampionDto c)
{
Champion ca = c.DtoToChamp();
return Ok(await donnees.ChampionsMgr.AddItem(ca));
//return CreatedAtAction(nameof(donnees.ChampionsMgr.GetItemsByName), new { Name = c.Name }, c);
//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")]
public async Task<ActionResult> PostChamps([FromBody] List<ChampionDto> lc)
@ -139,8 +147,7 @@ namespace ApiDePaul.Controllers
await donnees.ChampionsMgr.UpdateItem(champion1, champion2);
}
return Ok(lc.Count());
}
/*
}/*
[HttpPut("Modifier")]
public async Task<IActionResult> PutChamp([FromBody] ChampionDto c, [FromBody] ChampionDto cNouv)
{

@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using ApiDePaul.DTO;
using Model;
using static System.Net.Mime.MediaTypeNames;
namespace ApiDePaul
{
@ -12,22 +14,45 @@ namespace ApiDePaul
{
public static ChampionDto ChampToDto(this Champion c)
{
return new ChampionDto()
ChampionDto champ = new ChampionDto();
champ.Name = c.Name;
champ.Bio = c.Bio;
champ.Icon = c.Icon;
champ.Characteristics = new List<Tuple<string, int>>();
foreach(var ch in c.Characteristics)
{
Name = c.Name,
Bio = c.Bio,
Icon = c.Icon,
Characteristics = c.Characteristics.ToDictionary(x => x.Key, x => x.Value)
};
champ.Characteristics.Add(new Tuple<string,int>(ch.Key, ch.Value));
}
//Characteristics = c.Characteristics.ToDictionary(x => x.Key, x => x.Value)
return champ;
}
public static Champion DtoToChamp(this ChampionDto c)
{
Champion champ = new Champion(c.Name);
string[] classes = { "Unknown", "Assassin", "Fighter", "Mage", "Marksman", "Support", "Tank" };
if (classes.ToList().Contains(c.Class))
{
champ.Class=(ChampionClass)Enum.Parse(typeof(ChampionClass), c.Class);
}
else
{
champ.Class = 0;
}
champ.Icon = c.Icon;
champ.Image = new LargeImage(c.Image);
champ.Bio=c.Bio;
foreach(var s in c.Skills)
{
champ.AddSkill(s);
}
champ.AddCharacteristics(c.Characteristics.ToArray());
/*
//champ.Class = (ChampionClass)Enum.Parse(typeof(ChampionClass),c.Class);
champ.Icon = c.Icon;
//champ.Image = c.Image;
champ.Bio = c.Bio;
*/
return champ;
}
}

@ -17,10 +17,10 @@ namespace ApiDePaul
Name = s.Name,
Price = s.Price,
Icon = s.Icon,
Image = s.Image,
//Image = s.Image,
Description = s.Description
};
}/*
public static Champion DtoToSkin(this ChampionDto s) => new Skin(s.Name);*/
}
//public static Skin DtoToSkin(this SkinDto s) => new Skin(s.Name);
}
}

@ -11,7 +11,8 @@ namespace ApiDePaul.DTO
public string Icon { get; set; }
public string Image { get; set; }
public List<SkinDto> Skins { get; set; }
public Dictionary<string, int> Characteristics { get; set; }
public List<Tuple<string,int>> Characteristics { get; set; }
public HashSet<Skill> Skills { get; set; }
public float valuer { get; set; } = 0;
}
}

@ -7,7 +7,7 @@ namespace ApiDePaul.DTO
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public LargeImage Image { get; set; }
public string Image { get; set; }
public float Price { get; set; }
}
}

Loading…
Cancel
Save