diff --git a/Application/LinkService.cs b/Application/LinkService.cs index 7af9e0c..5d080bf 100644 --- a/Application/LinkService.cs +++ b/Application/LinkService.cs @@ -50,6 +50,16 @@ namespace Application // CommentsCount = 54, // }).ToArray(); + return LinksDTO().ToArray(); + } + + public LinkDTO GetLinkById(Guid id) + { + return LinksDTO().Single(link => link.Id == id); + } + + private IQueryable LinksDTO() + { return _data.Links .Select(link => new LinkDTO { @@ -61,8 +71,7 @@ namespace Application CommentsCount = 54, }) // .Where(linkDto => linkDto.UpvotesCount > 5) - .OrderByDescending(linkDto => linkDto.CreatedAt) - .ToArray(); + .OrderByDescending(linkDto => linkDto.CreatedAt); } } } diff --git a/Apps/Website/Controllers/LinksController.cs b/Apps/Website/Controllers/LinksController.cs index 4c0d6e6..97a7fd3 100644 --- a/Apps/Website/Controllers/LinksController.cs +++ b/Apps/Website/Controllers/LinksController.cs @@ -1,3 +1,4 @@ +using System; using Application; using Microsoft.AspNetCore.Mvc; @@ -18,6 +19,12 @@ namespace Website return View(_service.GetAllLinks()); } + [HttpGet("{controller}/detail/{linkId:guid}")] + public IActionResult Show(Guid linkId) + { + return View(_service.GetLinkById(linkId)); + } + // [HttpGet] // Implicite car HttpGet par défaut public IActionResult Create() { diff --git a/Apps/Website/Views/Links/Index.cshtml b/Apps/Website/Views/Links/Index.cshtml index 9c2af1f..eb10f0c 100644 --- a/Apps/Website/Views/Links/Index.cshtml +++ b/Apps/Website/Views/Links/Index.cshtml @@ -11,7 +11,7 @@ } \ No newline at end of file diff --git a/Apps/Website/Views/Links/Show.cshtml b/Apps/Website/Views/Links/Show.cshtml new file mode 100644 index 0000000..d9d491a --- /dev/null +++ b/Apps/Website/Views/Links/Show.cshtml @@ -0,0 +1,6 @@ +@model Application.LinkDTO +@{ + ViewData["Title"] = $"Viewing link {Model.Url}"; +} + +

Viewing link @Model.Url