2021-12-14 09:06:56 +01:00

55 lines
1.3 KiB
C#

using System.ComponentModel.DataAnnotations;
using HackerNet.Domain;
namespace HackerNet.Application;
public class LinkService
{
private readonly ILinkRepository _repository;
private readonly IReadStore _readStore;
public LinkService(ILinkRepository repository, IReadStore readStore)
{
_repository = repository;
_readStore = readStore;
}
public Guid PublishLink(PublishLinkCommand cmd)
{
var link = new Link(cmd.Url, cmd.Description);
_repository.Add(link);
return link.Id;
}
public LinkHomePage[] GetPublishedLinks()
=> _readStore.GetPublishedLinks();
public LinkHomePage GetLinkDetail(Guid id)
=> _readStore.GetLinkDetail(id);
}
public interface IReadStore
{
LinkHomePage[] GetPublishedLinks();
LinkHomePage GetLinkDetail(Guid id);
}
public class LinkHomePage
{
public Guid Id { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public int CommentsCount { get; set; }
}
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; }
}