From 6368c3d0ddef4678263d33c6b0a3fc1c82e44da8 Mon Sep 17 00:00:00 2001 From: Emre Date: Mon, 13 Feb 2023 16:12:04 +0100 Subject: [PATCH] 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 --- .vs/API/v17/.suo | Bin 13824 -> 13312 bytes .../ApiLol/Controllers/ChampionsController.cs | 27 ++++++++++++------ .../Sources/ApiLol/Mapper/ChampionMapper.cs | 8 +++--- .../Sources/ApiLol/Mapper/SkinMapper.cs | 18 ++++++++++++ .../Mapper/enums/ChampionClassMapper.cs | 17 +++++++++++ .../Sources/DTO/ChampionDto.cs | 5 ++++ .../Sources/DTO/SkinDto.cs | 17 +++++++++++ .../Sources/DTO/enums/ChampionClassDto.cs | 19 ++++++++++++ 8 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/SkinDto.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs diff --git a/.vs/API/v17/.suo b/.vs/API/v17/.suo index 064ca0b7cb5408ee9dd9f5b7a35b18b41eefee80..3dfb49c5ef0019249645fc97556d2d66ab2872bf 100644 GIT binary patch delta 1401 zcmcIkOHUI~6ux)bLaDbck5Z;OloCsL*pd!*pb*p{G^WzpLV`OMf@m~xL1Kx(!i>Zv zF=Wn0SNapIb>XrJByMr(ztE&jkQnrw=?uo#LW3tc_wk+EbHDqYGd1oTcV87G?uGZR znBRQvdvoOj4>QILFKkI$ydN4;5%v_-6F_hmHeGq)#+3*CD;hiw#d!=Gt_w4MgpLtv zvqK@AJJEgio{p1s;hvJoHr|7?KtHZ5yx^u(Kra1KU*JIbXELpW!)NT|bYVBHgXrxx zMudn!2l_F5YU}bk6e~_5UZ=|Y6T`iKSWJLrSkj4%%sKwl{p%g?5f+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o>nfRaeCC-@(w4tLk8=l zRu*7;;Nl-?nKCG9AQL|1@b_}J8prPmu_&H)mYrf{c9|`*Id%h|WwvC_%WQ&`*acR` fZ=)Y_@k<@_i8VVHp2p9QDs1nEuZ)#!!xZ)lP}~P# diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs index ad2f3f2..1680ad1 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs @@ -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//5 + // PUT api//5 [HttpPut("{name}")] - public async void Put(string name, [FromBody] ChampionDto champion) + public async Task 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//5 - [HttpDelete] - public async Task Delete([FromBody] ChampionDto champion) + [HttpDelete("{name}")] + public async Task 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())); } } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs index 32ab8a7..dbb9679 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -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); } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs new file mode 100644 index 0000000..a093e12 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkinMapper.cs @@ -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 + }; + } + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs new file mode 100644 index 0000000..c0c52ed --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs @@ -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; + } + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs index f19a03b..09f009b 100644 --- a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs +++ b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs @@ -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 Skins { get; set; } + } } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs new file mode 100644 index 0000000..2c3962b --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/SkinDto.cs @@ -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; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs b/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs new file mode 100644 index 0000000..2f7e82d --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/enums/ChampionClassDto.cs @@ -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, + } +} -- 2.36.3