Creation of the DTO and Mapper for the Skin class, addition of new attributes for the championDto and complete put and delete function for the champion controller #4

Merged
emre.kartal merged 1 commits from API_UT_DELETE_PUT into master 2 years ago

Binary file not shown.

@ -1,6 +1,7 @@
using ApiLol.Mapper;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -32,7 +33,7 @@ namespace ApiLol.Controllers
{
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems()))
.Select(x => x.ToDto());
if(dtos == null)
if(dtos.IsNullOrEmpty())
{
return NotFound();
}
@ -47,18 +48,28 @@ namespace ApiLol.Controllers
(await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto());
}
/* // PUT api/<ValuesController>/5
// PUT api/<ValuesController>/5
[HttpPut("{name}")]
public async void Put(string name, [FromBody] ChampionDto champion)
public async Task<IActionResult> Put(string name, [FromBody] ChampionDto champion)
{
return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel()));
}*/
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
if(dtos.IsNullOrEmpty())
{
return BadRequest();
}
return Ok(await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel()));
}
// DELETE api/<ValuesController>/5
[HttpDelete]
public async Task<IActionResult> Delete([FromBody] ChampionDto champion)
[HttpDelete("{name}")]
public async Task<IActionResult> Delete(string name)
{
return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel()));
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
if (dtos.IsNullOrEmpty())
{
return BadRequest();
}
return Ok(await _manager.ChampionsMgr.DeleteItem(dtos.First()));
}
}
}

@ -11,15 +11,15 @@ namespace ApiLol.Mapper
{
Name = champion.Name,
Bio = champion.Bio,
Class = champion.Class.ToDto(),
Icon = champion.Icon,
Image = champion.Image.Base64
};
}
public static Champion ToModel(this ChampionDto championDto)
{
return new Champion(championDto.Name)
{
Bio = championDto.Bio,
};
return new Champion(championDto.Name, championDto.Class.ToModel(), championDto.Icon, championDto.Image,championDto.Bio);
}
}

@ -0,0 +1,18 @@
using DTO;
namespace ApiLol.Mapper
{
public static class SkinMapper
{
public static SkinDto ToDto(this SkinDto skin)
{
return new SkinDto()
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price
};
}
}
}

@ -0,0 +1,17 @@
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class ChampionClassMapper
{
public static ChampionClassDto ToDto(this ChampionClass championClass)
{
return (ChampionClassDto) championClass;
}
public static ChampionClass ToModel(this ChampionClassDto championClass)
{
return (ChampionClass) championClass;
}
}
}

@ -4,5 +4,10 @@
{
public string Name { get; set; }
public string Bio { get; set; }
public ChampionClassDto Class { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
public IEnumerable<SkinDto> Skins { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class SkinDto
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public enum ChampionClassDto
{
Unknown,
Assassin,
Fighter,
Mage,
Marksman,
Support,
Tank,
}
}
Loading…
Cancel
Save