ajout du détail d'un lien
This commit is contained in:
parent
849d4e2260
commit
da4179a065
@ -1,5 +1,4 @@
|
||||
using HackerNet.Application;
|
||||
using HackerNet.Infrastructure.Repositories.Memory;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HackerNet.Web.Controllers;
|
||||
@ -21,6 +20,14 @@ public class LinksController : Controller
|
||||
// return View(_linkRepository.GetAll());// retourne Link[]
|
||||
}
|
||||
|
||||
// TODO: Page de détail d'un lien
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Detail(Guid id)
|
||||
{
|
||||
return View(_linkService.GetLinkDetail(id));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult New()
|
||||
{
|
||||
@ -28,6 +35,7 @@ public class LinksController : Controller
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult New(PublishLinkCommand cmd)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
||||
6
Apps/HackerNet.Web/Views/Links/Detail.cshtml
Normal file
6
Apps/HackerNet.Web/Views/Links/Detail.cshtml
Normal file
@ -0,0 +1,6 @@
|
||||
@model HackerNet.Application.LinkHomePage
|
||||
@{
|
||||
ViewData["Title"] = $"Détail du lien {Model.Url}";
|
||||
}
|
||||
|
||||
<partial name="_LinkCard" model="@Model" />
|
||||
@ -7,7 +7,7 @@
|
||||
<link href="https://unpkg.com/tailwindcss@@^2/dist/tailwind.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header class="mx-auto max-w-4xl p-4">
|
||||
<header class="mx-auto max-w-4xl px-4 py-8">
|
||||
<nav class="flex items-center justify-between">
|
||||
<a asp-controller="Links" asp-action="Index" class="font-semibold text-indigo-500">Hacker<strong>Net</strong></a>
|
||||
<div>
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
@model HackerNet.Application.LinkHomePage
|
||||
|
||||
<article class="shadow-xl mb-6 p-4 rounded-sm">
|
||||
<article class="shadow-xl mb-6 p-6 rounded-sm">
|
||||
<h3 class="text-indigo-500 font-semibold text-xl"><a href="@Model.Url">@Model.Url</a></h3>
|
||||
|
||||
<p>@Model.Description</p>
|
||||
|
||||
<div>
|
||||
<a asp-controller="Links" asp-action="Detail" asp-route-id="@Model.Id">Détail du lien</a>
|
||||
<div class="mt-4">
|
||||
<a class="text-indigo-500 hover:underline" asp-controller="Links" asp-action="Detail" asp-route-id="@Model.Id">Détail du lien</a>
|
||||
</div>
|
||||
</article>
|
||||
@ -23,14 +23,16 @@ public class LinkService
|
||||
}
|
||||
|
||||
public LinkHomePage[] GetPublishedLinks()
|
||||
{
|
||||
return _readStore.GetPublishedLinks();
|
||||
}
|
||||
=> _readStore.GetPublishedLinks();
|
||||
|
||||
public LinkHomePage GetLinkDetail(Guid id)
|
||||
=> _readStore.GetLinkDetail(id);
|
||||
}
|
||||
|
||||
public interface IReadStore
|
||||
{
|
||||
LinkHomePage[] GetPublishedLinks();
|
||||
LinkHomePage GetLinkDetail(Guid id);
|
||||
}
|
||||
|
||||
public class LinkHomePage
|
||||
|
||||
@ -19,6 +19,9 @@ public class MemoryLinkRepository : ILinkRepository, IReadStore
|
||||
_links.Add(link);
|
||||
}
|
||||
|
||||
public LinkHomePage GetLinkDetail(Guid id)
|
||||
=> GetLinks(id).Single();
|
||||
|
||||
public LinkHomePage[] GetPublishedLinks()
|
||||
{
|
||||
// return (from l in _links
|
||||
@ -31,7 +34,13 @@ public class MemoryLinkRepository : ILinkRepository, IReadStore
|
||||
// CommentsCount = 0,
|
||||
// }).ToArray();
|
||||
|
||||
return GetLinks().ToArray();
|
||||
}
|
||||
|
||||
private IEnumerable<LinkHomePage> GetLinks(Guid? id = null)
|
||||
{
|
||||
return _links
|
||||
.Where(l => !id.HasValue || l.Id == id)
|
||||
.OrderByDescending(l => l.CreatedAt)
|
||||
.Select(l => new LinkHomePage
|
||||
{
|
||||
@ -39,6 +48,6 @@ public class MemoryLinkRepository : ILinkRepository, IReadStore
|
||||
Url = l.Url,
|
||||
Description = l.Description,
|
||||
CommentsCount = 0,
|
||||
}).ToArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user