Finish Champions Controller (filtrage, pagination ...) and add function for UTChampion
continuous-integration/drone/push Build is passing Details

Logs_Version_Filtrage_Pagination
Emre KARTAL 2 years ago
parent fa57eba9b8
commit 392fc430cc

Binary file not shown.

@ -29,6 +29,7 @@ namespace ApiLol.Controllers.v1
IEnumerable<ChampionDto> dtos = (await _manager.ChampionsMgr.GetItems(pageRequest.index, pageRequest.count, pageRequest.orderingPropertyName, pageRequest.descending))
.Select(x => x.ToDto());
return Ok(dtos);
}
// GET api/<ValuesController>/5
@ -60,9 +61,9 @@ namespace ApiLol.Controllers.v1
{
_logger.LogInformation("method {Action} call with {name} and {item}", nameof(Put), name, champion);
var dtos = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
return Ok(await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel()));
var dtos = (await _manager.ChampionsMgr.GetItemByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
return Ok((await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel())).ToDto());
}

@ -45,9 +45,9 @@ namespace ApiLol.Controllers.v2
.Select(x => x.ToDto());
return Ok(dtos);
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -69,13 +69,13 @@ namespace ApiLol.Controllers.v2
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), pageRequest);
IEnumerable<ChampionDto> dtos = (await _manager.ChampionsMgr.GetItems(pageRequest.index, pageRequest.count))
IEnumerable<ChampionDto> dtos = (await _manager.ChampionsMgr.GetItems(pageRequest.index, pageRequest.count, pageRequest.orderingPropertyName, pageRequest.descending))
.Select(x => x.ToDto());
return Ok(dtos);
return Ok(new { Data = dtos, index = pageRequest.index, count = pageRequest.count, total = nbTotal});
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -95,9 +95,9 @@ namespace ApiLol.Controllers.v2
}
return Ok(dtos.First());
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -116,9 +116,9 @@ namespace ApiLol.Controllers.v2
return CreatedAtAction(nameof(Get),
(await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto());
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -143,11 +143,11 @@ namespace ApiLol.Controllers.v2
return BadRequest("Name is already exist");
}
}
return Ok(await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel()));
return Ok((await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel())).ToDto());
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -163,9 +163,9 @@ namespace ApiLol.Controllers.v2
return Ok(res);
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -181,9 +181,9 @@ namespace ApiLol.Controllers.v2
return Ok(res);
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
@ -202,9 +202,9 @@ namespace ApiLol.Controllers.v2
}
return Ok(await _manager.ChampionsMgr.DeleteItem(dtos.First()));
}
catch (Exception e)
catch (Exception error)
{
return BadRequest(e.Message);
return BadRequest(error.Message);
}
}
}

@ -21,7 +21,12 @@ namespace ApiLol.Mapper
public static Champion ToModel(this ChampionDto championDto)
{
return new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image.Base64, championDto.Bio);
var champ = new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image.Base64, championDto.Bio);
foreach(var skin in championDto.Skins)
{
champ.AddSkin(skin.ToModel(champ));
}
return champ;
}
}

@ -30,9 +30,9 @@ namespace ApiLol.Mapper
};
}
public static Skin ToModel(this SkinDto skinDto)
public static Skin ToModel(this SkinDto skinDto, Champion champ)
{
return new Skin(skinDto.Name, null, skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description);
return new Skin(skinDto.Name, champ, skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description);
}
}

@ -10,7 +10,7 @@ namespace DTO
{
public int index { get; set; } = 0;
public int count { get; set; } = 0;
public string? orderingPropertyName { get; set; } = null;
public bool descending { get; set; } = true;
public string? orderingPropertyName { get; set; } = "Name";
public bool descending { get; set; } = false;
}
}

@ -62,7 +62,7 @@ public class Champion : IEquatable<Champion>
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
internal bool AddSkin(Skin skin)
public bool AddSkin(Skin skin)
{
if (skins.Contains(skin))
return false;
@ -70,7 +70,7 @@ public class Champion : IEquatable<Champion>
return true;
}
internal bool RemoveSkin(Skin skin)
public bool RemoveSkin(Skin skin)
=> skins.Remove(skin);
public bool AddSkill(Skill skill)

@ -63,6 +63,64 @@ namespace ApiTests
var champions = objectResult?.Value as ChampionDto;
Assert.IsNotNull(champions);
}
[TestMethod]
public async Task TestPutChampion()
{
//Arange
var ChampionDto = new ChampionDto
{
Name = "Sylas",
Bio = "Good",
Class = ChampionClassDto.Tank,
Icon = "",
Image = new LargeImageDto() { Base64 = "" },
Skins = new List<SkinDto>()
};
var ChampionDtoPut = new ChampionDto
{
Name = "Sylas",
Bio = "Bad",
Class = ChampionClassDto.Tank,
Icon = "",
Image = new LargeImageDto() { Base64 = "" },
Skins = new List<SkinDto>()
};
//Act
await champs.Post(ChampionDto);
var championsResult = await champs.Put(ChampionDto.Name, ChampionDtoPut);
//Assert
var objectResult = championsResult as OkObjectResult;
Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as ChampionDto;
Assert.IsNotNull(champions);
Assert.AreNotEqual(ChampionDto.Bio, champions.Bio);
Assert.AreEqual(ChampionDtoPut.Bio, champions.Bio);
}
[TestMethod]
public async Task TestDeleteChampion()
{
//Arange
//Act
var total = await stub.ChampionsMgr.GetNbItems();
var championsResult = await champs.Delete("Akali");
//Assert
var objectResult = championsResult as OkObjectResult;
Assert.IsNotNull(objectResult);
Assert.AreEqual(objectResult.Value, true);
Assert.AreNotEqual(await stub.ChampionsMgr.GetNbItems(), total);
}
}

Loading…
Cancel
Save