diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
index f7057e6..6684108 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj
@@ -21,6 +21,8 @@
+
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs
index 48775fc..2db9d8b 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs
@@ -1,17 +1,20 @@
-using API_LoL_Project.Mapper;
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Mapper;
using API_LoL_Project.Middleware;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
+using System.Collections.Generic;
using System.Text.Json;
using System.Xml.Linq;
-// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_LoL_Project.Controllers
{
+ /*[Route("api/v{version:apiVersion}/[controller]")]*/
[Route("api/[controller]")]
+ /*[ApiVersion("1.0")]*/
[ApiController]
public class ChampionsController : ControllerBase
{
@@ -30,42 +33,58 @@ namespace API_LoL_Project.Controllers
- // GET: api/
+ // GET: api//getAllChampions
[HttpGet]
- public async Task>> Get([FromQuery] Request.PageRequest request)
+ public async Task>> Get([FromQuery] Request.PageRequest request)
{
try
{
var totalcount = await dataManager.GetNbItems();
- if (request.count + request.index > totalcount)
+ if (request.count * request.index >= totalcount)
{
- _logger.LogWarning("No chamions found with Id");
- return BadRequest("No chamions found with Id ");
+ _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount);
+ return BadRequest("To many object is asked the max is : " + totalcount);
}
- _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);;
- var champions = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
- IEnumerable res = champions.Select(c => c.toDTO());
- if (res.Count() >= 0 || res == null)
+
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ;
+ var champions = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
+ IEnumerable res = champions.Select(c => c.ToDTO());
+ if (res.Count() <= 0 || res == null)
{
- _logger.LogWarning("No chamions found with Id");
- return BadRequest("No chamions found with Id ");
+ _logger.LogError("No chamions found the total count is {totalcount} ", totalcount);
+ return BadRequest("No chamions found : totalcount is : "+ totalcount);
}
- return Ok(res);
+
+ var respList = res.Select(r => new LolResponce
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Get)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ var pageResponse = new PageResponse(respList,request.index,request.count,totalcount);
+
+ return Ok(pageResponse);
}
catch (Exception e)
{
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
-
-
}
-
- // GET api//5
- [HttpGet("{name}")]
- public async Task> GetChampionsByName(string name)
+ /*// GET api//5
+ [HttpGet("{id}")]
+ public async Task>> GetChampionsById(int name)
{
try
{
@@ -73,10 +92,11 @@ namespace API_LoL_Project.Controllers
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
_logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
- ChampionDTO res = champion.First().toDTO();
+ IEnumerable res = champion.Select(c => c.toFullDTO());
+
if (res == null)
{
- _logger.LogWarning("No chamions found with {name}", name); ;
+ _logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok(res);
@@ -86,6 +106,79 @@ namespace API_LoL_Project.Controllers
{
return BadRequest(e.Message);
+ }
+ }*/
+
+ // GET: api//LargeImage
+ [HttpGet("image/{name}")]
+ public async Task> GetChampionsImage(string name)
+ {
+ try
+ {
+ var champion = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/
+ ChampionFullDTO res = champion.First().toFullDTO();//.First
+
+ if (res == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res.LargeImage);
+
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+
+ }
+ }
+
+
+ // GET api//name
+ [HttpGet("{name}")]
+ public async Task>> GetChampionsByName(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name);
+ try
+ {
+ var totalcount = await dataManager.GetNbItemsByName(name);
+ if ( totalcount <= 0)
+ {
+ _logger.LogWarning("No chamions found with this name {name}", name); ;
+ return BadRequest("No chamions found with this name: " + name);
+ }
+
+ var champion = await dataManager.GetItemsByName(name, 0, totalcount);
+ /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/
+ if (champion.Count() <= 0 || champion == null )
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound("No chamions found with"+name);
+ }
+ ChampionFullDTO res = champion.First().toFullDTO();//.First
+
+
+ var links = new List
+ {
+ EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
+ };
+
+ var response = new LolResponce(res,links);
+ return Ok(response);
+
+ }
+ catch (Exception e)
+ {
+
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest("Somthing goes wrong caching the Champions controller : " + e.Message);
+
}
}
@@ -96,33 +189,48 @@ namespace API_LoL_Project.Controllers
{
try
{
- var newChampion = value.toModel();
+ var newChampion = value.ToModel();
await dataManager.AddItem(newChampion);
- return CreatedAtAction(nameof(Get), newChampion) ;
+ // can we check with a method
+ //var savedChampions = await dataManager.GetItemsByName(newChampion.name, 0, await dataManager.GetNbItems())
+ /*if (savedChampions.Count() >= 0 || res == null)
+ {
+ _logger.LogWarning("No chamions found ");
+ return BadRequest("No chamions found ");
+ }*/
+ _logger.LogInformation("Sucessfully saved Champions : " + newChampion.Name);
+
+ return CreatedAtAction(nameof(Get), newChampion);
}
catch (Exception e)
{
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
}
-
+ // should change for id cause model implementation use filteringbyName to getItemByNAme and it use substring
// PUT api//5
[HttpPut("{name}")]
public async Task Put(string name, [FromBody] ChampionDTO value)
{
-
-
try
{
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name);
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
- await dataManager.UpdateItem(champion.First(), value.toModel());
+ if (champion == null)
+ {
+ _logger.LogError("No chamions found with {name} in the dataBase", name); ;
+ return NotFound();
+ }
+ await dataManager.UpdateItem(champion.First(), value.ToModel());
return Ok();
}
- catch(Exception e)
+ catch (Exception e)
{
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
}
@@ -133,20 +241,23 @@ namespace API_LoL_Project.Controllers
{
try
{
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Delete), name);
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
if (champion != null) await dataManager.DeleteItem(champion.First());
else
{
+ _logger.LogWarning("No chamions found with {name}", name); ;
return NotFound();
}
return Ok();
}
catch (Exception e)
{
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
return BadRequest(e.Message);
}
-
+
}
/* [HttpGet]
@@ -159,17 +270,48 @@ namespace API_LoL_Project.Controllers
}*/
[HttpGet("/{name}/skins")]
- public async Task> GetChampionsSkins(string name)
+ public async Task> GetChampionsSkins(string name)
{
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkins), name);
var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
//skinsDTO
- IEnumerable res = champions.First().Skins;
-
+ IEnumerable res = champions.First().Skins.Select(c => c.ToDto());
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
return Ok(res);
}
- [HttpGet("/{name}/skills")]
- public async Task> GetChampionsSkills(string name)
+ /* [HttpGet("/{name}/skills")]
+ public async Task> GetChampionsSkills(string name)
+ {
+ _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name);
+ var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
+ if (champions == null)
+ {
+ _logger.LogWarning("No chamions found with {name}", name); ;
+ return NotFound();
+ }
+ //skinsDTO
+ IEnumerable res = champions.First().Skills.to;
+ if (res == null)
+ {
+ _logger.LogWarning("No skins found for {name}", name); ;
+ return NotFound();
+ }
+
+ return Ok(res);
+ }*/
+
+ [HttpPost("/{name}/skills")]
+ public async Task>> AddChampionsSkills(string name)
{
var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems());
//SkillDTO
@@ -187,4 +329,6 @@ namespace API_LoL_Project.Controllers
}*/
}
+
+
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
index 1950fa3..3d7cfb4 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs
@@ -5,13 +5,13 @@
//max leght
public string? orderingPropertyName { get; set; } = null;
public bool? descending { get; set; } = false;
- const int maxPageSize = 50;
- public int PageNumber { get; set; } = 1;
+ // const int maxPageSize = 50;
+ // public int PageNumber { get; set; } = 1;
public int index { get; set; } = 1;
public int count { get; set; } = 1;
-
+/*
//max lentght
private int _pageSize;
public int PageSize
@@ -24,6 +24,6 @@
{
_pageSize = (value > maxPageSize) ? maxPageSize : value;
}
- }
+ }*/
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs
new file mode 100644
index 0000000..3ef451d
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs
@@ -0,0 +1,22 @@
+namespace API_LoL_Project.Controllers.Response
+{
+ public class EndPointLink
+ {
+ public string Href { get; set; }
+ public string Rel { get; set; }
+ public string Method { get; set; }
+ public EndPointLink()
+ {
+ }
+ public EndPointLink(string href, string rel, string method)
+ {
+ Href = href;
+ Rel = rel;
+ Method = method;
+ }
+ public static EndPointLink To(string href, string rel = "self", string method = "GET")
+ {
+ return new EndPointLink { Href = href, Rel = rel, Method = method };
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
index f75a599..62a21bc 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs
@@ -1,6 +1,22 @@
-namespace API_LoL_Project.Controllers.Response
+using API_LoL_Project.Middleware;
+
+namespace API_LoL_Project.Controllers.Response
{
- public class PageResponse
+ public class PageResponse
{
+ public IEnumerable> Data { get; set; }
+ public int Index { get; set; } = 1;
+ public int TotalCount { get; set; } = 1;
+ public int Count { get; set; } = 1;
+
+
+ public PageResponse(IEnumerable> data, int indexRequested, int countRequested, int totalCount)
+ {
+ this.Data = data;
+ this.Index = indexRequested;
+ this.TotalCount = totalCount;
+ this.Count = countRequested;
+ }
}
}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
index 7b9a2f2..9ec17e0 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs
@@ -2,6 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using Model;
using API_LoL_Project.Mapper;
+using API_LoL_Project.Controllers.Response;
+using API_LoL_Project.Middleware;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -12,40 +14,71 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class RuneController : ControllerBase
{
- public IRunesManager runesManager;
+ public IRunesManager dataManager;
// you should create a custom logger to be prety
private readonly ILogger _logger;
public RuneController(IDataManager dataManager, ILogger logger)
{
- this.runesManager = dataManager.RunesMgr;
+ this.dataManager = dataManager.RunesMgr;
this._logger = logger;
}
- /*// GET: api/
+ // GET: api/
[HttpGet]
- public async Task> Get()
+ public async Task>> GetAllRunes([FromQuery] Request.PageRequest request)
{
try
{
- var runes = await runesManager.GetItems(0, await runesManager.GetNbItems());
+ var totalcount = await dataManager.GetNbItems();
+ if (request.count * request.index >= totalcount)
+ {
+ _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount);
+ return BadRequest("To many object is asked the max is : " + totalcount);
+ }
+
+ _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ;
+ var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable res = runes.Select(c => c.toDTO());
- return Ok(res);
+ if (res.Count() <= 0 || res == null)
+ {
+ _logger.LogError("No runes found the total count is {totalcount} ", totalcount);
+ return BadRequest("No runes found : totalcount is : " + totalcount);
+ }
+
+ var respList = res.Select(r => new LolResponce
+ (
+ r,
+ new List
+ {
+ EndPointLink.To($"/api/[controller]/{r.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"),
+ EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"),
+ }
+ ));
+
+ var pageResponse = new PageResponse(respList, request.index, request.count, totalcount);
+
+ return Ok(pageResponse);
}
catch (Exception e)
{
- _logger.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString());
+ _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message);
return BadRequest(e.Message);
}
- }*/
+ }
+
// GET: api/
- [HttpGet]
+ /* [HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
try
@@ -54,12 +87,12 @@ namespace API_LoL_Project.Controllers
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
- return BadRequest("to many rows ask the max is " + totalcount) ;
+ return BadRequest("to many rows ask the max is " + totalcount);
}
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
-
- var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName,(request.descending == null ? false : (bool)request.descending));
+
+ var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
@@ -77,9 +110,45 @@ namespace API_LoL_Project.Controllers
}
+*/
+
+ [HttpGet("{name}")]
+ public async Task>> GetRuneByName(string name)
+ {
+ try
+ {
+
+ var rune = await dataManager
+ .GetItemsByName(name, 0, await dataManager.GetNbItems());
+ _logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name);
+ RuneDTO res = rune.First().toDTO();
+
+ if (res == null)
+ {
+ _logger.LogWarning("No runes found with {name}", name); ;
+ return NotFound();
+ }
+ var links = new List
+ {
+ EndPointLink.To($"/api/[controller]/{res.Name}", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self"),
+ EndPointLink.To($"/api/[controller]/{res.Name}/", "self")
+ };
+
+ var response = new LolResponce(res, links);
+ return Ok(response);
+ }
+ catch (Exception e)
+ {
+
+ _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message);
+ return BadRequest(e.Message);
+
+ }
+ }
- // GET api//5
+ /* // GET api//5
[HttpGet("{id}")]
public string Get(int id)
{
@@ -97,24 +166,10 @@ namespace API_LoL_Project.Controllers
}
- }
+ }*/
// POST api/
- [HttpPost]
- public void Post([FromBody] string value)
- {
- try
- {
- await dataManager.AddItem(value.toModel());
- return Ok();
- }
- catch ()
- {
- new HttpException(400, 'Cannot create rune')
- }
-
-
- }
+
// PUT api//5
[HttpPut("{id}")]
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
index 2d0934b..271d180 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs
@@ -1,4 +1,5 @@
-using Microsoft.AspNetCore.Mvc;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -8,7 +9,7 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class RunePageController : ControllerBase
{
- // GET: api/
+ /* // GET: api/
[HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
@@ -65,6 +66,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")]
public void Delete(int id)
{
- }
+ }*/
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs
index 950897f..042bc7e 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs
@@ -8,7 +8,7 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class SkillController : ControllerBase
{
- // GET: api/
+ /* // GET: api/
[HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
@@ -65,6 +65,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")]
public void Delete(int id)
{
- }
+ }*/
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
index db11f8d..9f41870 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs
@@ -1,4 +1,6 @@
-using Microsoft.AspNetCore.Mvc;
+using DTO;
+using Microsoft.AspNetCore.Mvc;
+using Model;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -8,13 +10,21 @@ namespace API_LoL_Project.Controllers
[ApiController]
public class SkinController : ControllerBase
{
+ /* public ISkinsManager dataManager;
+ private readonly ILogger _logger;
+ public SkinController(IDataManager dataManager, ILogger logger)
+ {
+ this.dataManager = dataManager.SkinsMgr;
+ this._logger = logger;
+ }
+
// GET: api/
[HttpGet]
public async Task>> Get([FromQuery] Request.PageRequest request)
{
try
{
- var totalcount = await runesManager.GetNbItems();
+ var totalcount = await dataManager.GetNbItems();
if (request.count + request.index > totalcount)
{
_logger.LogWarning("to many rows ask the max is {totalcount}", totalcount);
@@ -23,7 +33,7 @@ namespace API_LoL_Project.Controllers
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);
- var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
+ var runes = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending));
IEnumerable res = runes.Select(c => c.toDTO());
if (res.Count() >= 0 || res == null)
{
@@ -65,6 +75,6 @@ namespace API_LoL_Project.Controllers
[HttpDelete("{id}")]
public void Delete(int id)
{
- }
+ }*/
}
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
index a7c1e89..8d48d22 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs
@@ -10,9 +10,10 @@ namespace API_LoL_Project.Mapper
{
if (item == null)
{
- var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
+ var message = string.Format("Champion cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
+ throw new Exception(message);
}
return new ChampionDTO() {
Name = item.Name,
@@ -35,9 +36,11 @@ namespace API_LoL_Project.Mapper
{
if (item == null)
{
- var message = string.Format("Champion with name = {} nhhoddt found", item.Name);
+ var message = string.Format("Champion with name = {} not found", item.Name);
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
*/
+ throw new Exception(message);
+
}
return new ChampionFullDTO()
{
@@ -45,8 +48,8 @@ namespace API_LoL_Project.Mapper
Bio = item.Bio,
Characteristics = item.Characteristics,
skills = item.Skills,
- skins = item.Skins,
- LargeImage = item.Image
+ skins = item.Skins.Select(i => i.ToDto()),
+ LargeImage = item.Image.ToDTO()
};
@@ -57,9 +60,12 @@ namespace API_LoL_Project.Mapper
{
if (dto == null)
{
- var message = string.Format("Champion with name = {} nhhoddt found", dto.Name);
+ var message = string.Format("Champion cannot be empty");
/*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
- */}
+ */
+ throw new Exception(message);
+
+ }
return new(dto.Name);
}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs
new file mode 100644
index 0000000..31f13ab
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs
@@ -0,0 +1,23 @@
+using DTO;
+using Model;
+
+namespace API_LoL_Project.Mapper
+{
+ public static class ImageMappeur
+ {
+ public static ImageDTO ToDTO(this LargeImage item)
+ {
+ if (item == null)
+ {
+ var message = string.Format("Image cannot be empty");
+ /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));
+ */
+ }
+ return new ImageDTO()
+ {
+ base64 = item.Base64
+ };
+ }
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs
index 3b2b752..69b1fb3 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs
@@ -24,4 +24,4 @@
}
}
-}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs
index ad5a96b..4293ba1 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs
@@ -17,7 +17,18 @@ namespace API_LoL_Project.Mapper
throw new NotImplementedException();
}
+ public static SkinDto ToDto(this Skin item)
+ {
+ return new SkinDto()
+ {
+ Name = item.Name,
+ Description = item.Description,
+ Icon = item.Icon,
+ Price = item.Price
+ };
+
+ }
}
}
-}
+
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs
new file mode 100644
index 0000000..7207f72
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs
@@ -0,0 +1,7 @@
+namespace API_LoL_Project.Middleware
+{
+ public class HateosMiddleware
+ {
+
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs
new file mode 100644
index 0000000..22b7703
--- /dev/null
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs
@@ -0,0 +1,18 @@
+using API_LoL_Project.Controllers.Response;
+using System.Net;
+
+namespace API_LoL_Project.Middleware
+{
+ public class LolResponce
+ {
+ public T Data { get; set; }
+ public List Links { get; set; } = null;
+
+
+ public LolResponce(T data , List? links)
+ {
+ this.Data = data;
+ this.Links = links;
+ }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
index 79eb2d3..f4c432c 100644
--- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
+++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs
@@ -13,7 +13,7 @@ builder.Services.AddSwaggerGen();
builder.Services.AddSingleton();
var app = builder.Build();
-
+// à enlever
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
diff --git a/EntityFramework_LoL/Sources/Business/Extensions.cs b/EntityFramework_LoL/Sources/Business/Extensions.cs
index 9f99257..ac81eaa 100644
--- a/EntityFramework_LoL/Sources/Business/Extensions.cs
+++ b/EntityFramework_LoL/Sources/Business/Extensions.cs
@@ -22,7 +22,7 @@ namespace Business
: temp.OrderBy(item => prop.GetValue(item));
}
}
- return temp.Skip(index * count).Take(count)
+ return temp.Skip(index * count).Take(count);
}
}
}
diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
index 5d0e9f6..75db492 100644
--- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
+++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs
@@ -1,23 +1,31 @@
using Model;
+using System.Collections.ObjectModel;
+using System.ComponentModel.DataAnnotations;
namespace DTO
{
public class ChampionDTO
{
public string Name { get; set; }
- public string Bio { get; set; }
+ public string Bio { get; set; }
+ public string Icon { get; set; }
+
/*public string Icon { get; set; }
- */
- }
+ */
+ }
public class ChampionFullDTO
{
+ /*[Required(ErrorMessage = "Name is required")]
+ [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/
public string Name { get; set; }
public string Bio { get; set; }
- public string Characteristics { get; set; }
- public byte[] LargeImage { get; set; }
+ public ReadOnlyDictionary Characteristics { get; set; }
+ public ImageDTO LargeImage { get; set; }
- public IEnumerable skins { get; set; }
+ public IEnumerable skins { get; set; }
public IEnumerable skills { get; set; }
}
+
+
}
\ No newline at end of file
diff --git a/EntityFramework_LoL/Sources/DTO/ImageDTO.cs b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs
new file mode 100644
index 0000000..3b5cec1
--- /dev/null
+++ b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class ImageDTO
+ {
+ public string base64 { get; set; }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
index 495f618..64b8989 100644
--- a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
+++ b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs
@@ -1,4 +1,5 @@
using Model;
+using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,9 +14,9 @@ namespace DTO
public string Description { get; set; }
- public RuneFamily Family { get; set; }
+ public RuneFamily Family { get; set; }
- public string Icon { get; set; }
+ public string Icon { get; set; }
public LargeImage Image { get; set; }
}
diff --git a/EntityFramework_LoL/Sources/DTO/SkillDto.cs b/EntityFramework_LoL/Sources/DTO/SkillDto.cs
new file mode 100644
index 0000000..2b7f006
--- /dev/null
+++ b/EntityFramework_LoL/Sources/DTO/SkillDto.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DTO
+{
+ public class SkillDto
+ {
+ public string Name { get; set; }
+ public string Description { get; set; }
+ }
+}
diff --git a/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/EntityFramework_LoL/Sources/DTO/SkinDto.cs
new file mode 100644
index 0000000..2c3962b
--- /dev/null
+++ b/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/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln
index ef88d8c..dc80334 100644
--- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln
+++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln
@@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entiti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -61,6 +61,10 @@ Global
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.Build.0 = Release|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU