From 4e34679168754042f0305dedbfac031dd1da30f9 Mon Sep 17 00:00:00 2001 From: Julien LEICHER Date: Mon, 13 Dec 2021 15:07:54 +0100 Subject: [PATCH] ajout liste des liens --- .../Controllers/LinksController.cs | 10 +++++- Apps/HackerNet.Web/Program.cs | 9 ++++-- Apps/HackerNet.Web/Views/Links/Index.cshtml | 15 +++++++++ .../HackerNet.Web/Views/Shared/_Layout.cshtml | 2 +- .../Views/Shared/_LinkCard.cshtml | 7 ++++ HackerNet.Application/LinkService.cs | 22 ++++++++++++- HackerNet.Domain/ILinkRepository.cs | 4 ++- .../Memory/MemoryLinkRepository.cs | 32 +++++++++++++++++++ .../Repositories/MemoryLinkRepository.cs | 20 ------------ 9 files changed, 94 insertions(+), 27 deletions(-) create mode 100644 Apps/HackerNet.Web/Views/Links/Index.cshtml create mode 100644 Apps/HackerNet.Web/Views/Shared/_LinkCard.cshtml create mode 100644 HackerNet.Infrastructure/Repositories/Memory/MemoryLinkRepository.cs delete mode 100644 HackerNet.Infrastructure/Repositories/MemoryLinkRepository.cs diff --git a/Apps/HackerNet.Web/Controllers/LinksController.cs b/Apps/HackerNet.Web/Controllers/LinksController.cs index 9787a86..cd24de0 100644 --- a/Apps/HackerNet.Web/Controllers/LinksController.cs +++ b/Apps/HackerNet.Web/Controllers/LinksController.cs @@ -13,6 +13,14 @@ public class LinksController : Controller _linkService = linkService; } + [HttpGet] + public IActionResult Index() + { + return View(_linkService.GetPublishedLinks()); + // return View(db.Links.ToArray());// retourne Link[] + // return View(_linkRepository.GetAll());// retourne Link[] + } + [HttpGet] public IActionResult New() { @@ -29,6 +37,6 @@ public class LinksController : Controller _linkService.PublishLink(cmd); - return RedirectToAction("Index", "Home"); + return RedirectToAction("Index"); } } \ No newline at end of file diff --git a/Apps/HackerNet.Web/Program.cs b/Apps/HackerNet.Web/Program.cs index ce55c07..a7b2771 100644 --- a/Apps/HackerNet.Web/Program.cs +++ b/Apps/HackerNet.Web/Program.cs @@ -5,8 +5,11 @@ using HackerNet.Infrastructure.Repositories.Memory; var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddSingleton( - new MemoryLinkRepository(new Link("https://localhost:7050/Links/New", "Youhouuu"))); +var linksRepository = new MemoryLinkRepository(new Link("https://localhost:7050/", "Youhouuu")); + +builder.Services.AddSingleton(linksRepository); +builder.Services.AddSingleton(linksRepository); + builder.Services.AddSingleton(); builder.Services.AddControllersWithViews(); @@ -29,6 +32,6 @@ app.UseAuthorization(); app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Links}/{action=Index}/{id?}"); app.Run(); diff --git a/Apps/HackerNet.Web/Views/Links/Index.cshtml b/Apps/HackerNet.Web/Views/Links/Index.cshtml new file mode 100644 index 0000000..fc627e6 --- /dev/null +++ b/Apps/HackerNet.Web/Views/Links/Index.cshtml @@ -0,0 +1,15 @@ +@model HackerNet.Application.LinkHomePage[] +@{ + ViewData["Title"] = "Derniers liens publiƩs"; +} + +@if(Model.Length == 0){ +

Aucun lien publiƩ pour le moment.

+} +else +{ + foreach (var link in Model) + { + + } +} \ No newline at end of file diff --git a/Apps/HackerNet.Web/Views/Shared/_Layout.cshtml b/Apps/HackerNet.Web/Views/Shared/_Layout.cshtml index 59b19e1..2cbb0ce 100644 --- a/Apps/HackerNet.Web/Views/Shared/_Layout.cshtml +++ b/Apps/HackerNet.Web/Views/Shared/_Layout.cshtml @@ -9,7 +9,7 @@