53 lines
1.2 KiB
C#
53 lines
1.2 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()
|
|
{
|
|
return _readStore.GetPublishedLinks();
|
|
}
|
|
}
|
|
|
|
public interface IReadStore
|
|
{
|
|
LinkHomePage[] GetPublishedLinks();
|
|
}
|
|
|
|
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; }
|
|
} |