62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
using HackerNet.Application;
|
|
using HackerNet.Infrastructure.AspNet.Filters;
|
|
using HackerNet.Web.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HackerNet.Web.Controllers;
|
|
|
|
public class LinksController : HackerController
|
|
{
|
|
private readonly LinkService _linkService;
|
|
private readonly ILogger<LinksController> _logger;
|
|
|
|
public LinksController(LinkService linkService, ILogger<LinksController> logger)
|
|
{
|
|
_linkService = linkService;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
_logger.LogDebug("Récupération des liens publiés !");
|
|
return View(_linkService.GetPublishedLinks());
|
|
// return View(db.Links.ToArray());// retourne Link[]
|
|
// return View(_linkRepository.GetAll());// retourne Link[]
|
|
}
|
|
|
|
[HttpGet]
|
|
[CustomExceptionFilter]
|
|
public IActionResult Detail(Guid id)
|
|
{
|
|
var link = _linkService.GetLinkDetail(id);
|
|
var comments = _linkService.GetLinkComments(id);
|
|
|
|
return View(new LinkDetailViewModel(link, comments));
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize]
|
|
public IActionResult New()
|
|
{
|
|
return View(new PublishLinkCommand());
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
[Authorize]
|
|
public IActionResult New(PublishLinkCommand cmd)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(cmd);
|
|
}
|
|
|
|
_linkService.PublishLink(cmd);
|
|
|
|
SetFlashMessage("Votre lien a correctement été publié !");
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
} |