publication d'un lien
This commit is contained in:
parent
fab4e35d73
commit
ebfc06199e
@ -0,0 +1,34 @@
|
||||
using HackerNet.Application;
|
||||
using HackerNet.Infrastructure.Repositories.Memory;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HackerNet.Web.Controllers;
|
||||
|
||||
public class LinksController : Controller
|
||||
{
|
||||
private readonly LinkService _linkService;
|
||||
|
||||
public LinksController(LinkService linkService)
|
||||
{
|
||||
_linkService = linkService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult New()
|
||||
{
|
||||
return View(new PublishLinkCommand());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult New(PublishLinkCommand cmd)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View(cmd);
|
||||
}
|
||||
|
||||
_linkService.PublishLink(cmd);
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,13 @@
|
||||
using HackerNet.Application;
|
||||
using HackerNet.Domain;
|
||||
using HackerNet.Infrastructure.Repositories.Memory;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddSingleton<ILinkRepository>(
|
||||
new MemoryLinkRepository(new Link("https://localhost:7050/Links/New", "Youhouuu")));
|
||||
builder.Services.AddSingleton<LinkService>();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
@ -8,9 +15,9 @@ var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7049;http://localhost:5245",
|
||||
"applicationUrl": "https://localhost:7050;http://localhost:5246",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
||||
24
Apps/HackerNet.Web/Views/Links/New.cshtml
Normal file
24
Apps/HackerNet.Web/Views/Links/New.cshtml
Normal file
@ -0,0 +1,24 @@
|
||||
@model HackerNet.Application.PublishLinkCommand
|
||||
@{
|
||||
ViewData["Title"] = "Publier un nouveau lien";
|
||||
}
|
||||
|
||||
<div class="shadow-xl p-6">
|
||||
<h1 class="font-semibold text-xl text-indigo-500">@ViewData["Title"]</h1>
|
||||
|
||||
<form asp-action="New" method="post">
|
||||
<label asp-for="@Model.Url"></label>
|
||||
<input class="mt-4 bg-gray-100 rounded-xl px-2 py-4 block w-full" asp-for="@Model.Url" />
|
||||
<span class="text-red-700 text-sm block" asp-validation-for="@Model.Url"></span>
|
||||
|
||||
<label asp-for="@Model.Description"></label>
|
||||
<textarea class="mt-4 bg-gray-100 rounded-xl px-2 py-4 block w-full" asp-for="@Model.Description">
|
||||
</textarea>
|
||||
<span class="text-red-700 text-sm block" asp-validation-for="@Model.Description"></span>
|
||||
|
||||
<div class="mt-4 flex justify-end">
|
||||
<button type="submit" class="px-4 py-2 text-indigo-500 font-semibold rounded-xl bg-indigo-100">Publier un lien</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@ -3,44 +3,27 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - HackerNet.Web</title>
|
||||
<title>@ViewData["Title"] - HackerNet</title>
|
||||
<link href="https://unpkg.com/tailwindcss@@^2/dist/tailwind.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">HackerNet.Web</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<header class="mx-auto max-w-4xl p-4">
|
||||
<nav class="flex items-center justify-between">
|
||||
<a asp-controller="Home" asp-action="Index" class="font-semibold text-indigo-500">Hacker<strong>Net</strong></a>
|
||||
<div>
|
||||
<a asp-controller="Links" asp-action="New" class="px-4 py-2 text-indigo-500 font-semibold rounded-xl bg-indigo-100">Publier un lien</a>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<div class="mx-auto max-w-4xl px-4">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
<footer class="mt-4 mx-auto max-w-4xl px-4">
|
||||
© 2021 - HackerNet.Web - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using HackerNet.Domain;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using HackerNet.Domain;
|
||||
|
||||
namespace HackerNet.Application;
|
||||
public class LinkService
|
||||
@ -22,6 +23,11 @@ public class LinkService
|
||||
|
||||
public class PublishLinkCommand
|
||||
{
|
||||
[Required(ErrorMessage = "L'url est requise")]
|
||||
[Display(Name = "Url du site")]
|
||||
[Url]
|
||||
public string Url { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "La description est obligatoire")]
|
||||
public string Description { get; set; }
|
||||
}
|
||||
5
omnisharp.json
Normal file
5
omnisharp.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"msbuild": {
|
||||
"useBundledOnly": true
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user