Add new DTO and mapper
continuous-integration/drone/push Build is failing Details

Logs_Version_Filtrage_Pagination
Emre KARTAL 2 years ago
parent ec07596ea3
commit 1a8f5c8c6c

@ -28,7 +28,7 @@ namespace ApiLol.Controllers
if (pageRequest.count + pageRequest.index > nbTotal) if (pageRequest.count + pageRequest.index > nbTotal)
{ {
_logger.LogWarning($"too many, maximum {nbTotal}"); _logger.LogWarning($"too many, maximum {nbTotal}");
pageRequest.count = 10; return BadRequest("Champion limit exceed");
} }
_logger.LogInformation($"method Get call"); _logger.LogInformation($"method Get call");

@ -13,13 +13,14 @@ namespace ApiLol.Mapper
Bio = champion.Bio, Bio = champion.Bio,
Class = champion.Class.ToDto(), Class = champion.Class.ToDto(),
Icon = champion.Icon, Icon = champion.Icon,
Image = champion.Image.Base64 Image = champion.Image.ToDto(),
Skins = champion.Skins.Select(e => e.ToDto())
}; };
} }
public static Champion ToModel(this ChampionDto championDto) public static Champion ToModel(this ChampionDto championDto)
{ {
return new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image,championDto.Bio); return new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image.Base64,championDto.Bio);
} }
} }

@ -0,0 +1,21 @@
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class LargeImageMapper
{
public static LargeImageDto ToDto(this LargeImage largeImage)
{
return new LargeImageDto()
{
Base64 = largeImage.Base64
};
}
public static LargeImage ToModel(this LargeImageDto largeImageDto)
{
return new LargeImage(largeImageDto.Base64);
}
}
}

@ -14,7 +14,7 @@ namespace ApiLol.Mapper
}; };
} }
/* public static Rune ToModel(this RuneDto rune) /* public static Rune ToModel(this RuneDto runeDto)
{ {
return new Rune(rune.Name) return new Rune(rune.Name)
{ {

@ -14,7 +14,7 @@ namespace ApiLol.Mapper
}; };
} }
/* public static Skill ToModel(this SkillDto skill) /* public static Skill ToModel(this SkillDto skillDto)
{ {
return new Skill(skill.Name) return new Skill(skill.Name)
{ {

@ -1,18 +1,25 @@
using DTO; using DTO;
using Model;
namespace ApiLol.Mapper namespace ApiLol.Mapper
{ {
public static class SkinMapper public static class SkinMapper
{ {
public static SkinDto ToDto(this SkinDto skin) public static SkinDto ToDto(this Skin skin)
{ {
return new SkinDto() return new SkinDto()
{ {
Name = skin.Name, Name = skin.Name,
Description = skin.Description, Description = skin.Description,
Icon = skin.Icon, Icon = skin.Icon,
Image = skin.Image.ToDto(),
Price = skin.Price Price = skin.Price
}; };
} }
public static Skin ToModel(this SkinDto skinDto)
{
return new Skin(skinDto.Name, null, skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description);
}
} }
} }

@ -9,9 +9,9 @@ namespace ApiLol.Mapper
{ {
return (ChampionClassDto) championClass; return (ChampionClassDto) championClass;
} }
public static ChampionClass ToModel(this ChampionClassDto championClass) public static ChampionClass ToModel(this ChampionClassDto championClassDto)
{ {
return (ChampionClass) championClass; return (ChampionClass) championClassDto;
} }
} }
} }

@ -0,0 +1,58 @@
using DTO;
using DTO.enums;
using Model;
namespace ApiLol.Mapper.enums
{
public static class SkillTypeMapper
{
public static SkillTypeDto ToDto(this SkillType skillType)
{
if (skillType == SkillType.Unknown)
{
return SkillTypeDto.Unknown;
}
if (skillType == SkillType.Basic)
{
return SkillTypeDto.Basic;
}
if (skillType == SkillType.Passive)
{
return SkillTypeDto.Passive;
}
if (skillType == SkillType.Ultimate)
{
return SkillTypeDto.Ultimate;
}
else
{
return SkillTypeDto.Unknown;
}
}
public static SkillType ToModel(this SkillTypeDto skillTypeDto)
{
if (skillTypeDto == SkillTypeDto.Unknown)
{
return SkillType.Unknown;
}
if (skillTypeDto == SkillTypeDto.Basic)
{
return SkillType.Basic;
}
if (skillTypeDto == SkillTypeDto.Passive)
{
return SkillType.Passive;
}
if (skillTypeDto == SkillTypeDto.Ultimate)
{
return SkillType.Ultimate;
}
else
{
return SkillType.Unknown;
}
}
}
}

@ -6,7 +6,7 @@
public string Bio { get; set; } public string Bio { get; set; }
public ChampionClassDto Class { get; set; } public ChampionClassDto Class { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public string Image { get; set; } public LargeImageDto Image { get; set; }
public IEnumerable<SkinDto> Skins { get; set; } public IEnumerable<SkinDto> Skins { get; set; }
} }

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class LargeImageDto
{
public string Base64 { get; set; }
}
}

@ -11,6 +11,7 @@ namespace DTO
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public LargeImageDto Image { get; set; }
public float Price { get; set; } public float Price { get; set; }
} }

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO.enums
{
public enum SkillTypeDto
{
Unknown,
Basic,
Passive,
Ultimate
}
}

@ -26,7 +26,7 @@ namespace ApiTests
//Act //Act
var total = await stub.ChampionsMgr.GetNbItems(); var total = await stub.ChampionsMgr.GetNbItems();
var champion = await champs.Get(new PageRequest()); var champion = await champs.Get(new PageRequest() { index = 0, count = total });
//Assert //Assert
var objectResult = champion as OkObjectResult; var objectResult = champion as OkObjectResult;

Loading…
Cancel
Save