69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Domain;
|
|
|
|
namespace Application
|
|
{
|
|
/// <summary>
|
|
/// Service applicatif permettant la gestion des liens de la plateforme.
|
|
/// </summary>
|
|
public class LinkService
|
|
{
|
|
private readonly ILinkRepository _linkRepository;
|
|
private readonly IData _data;
|
|
|
|
public LinkService(ILinkRepository linkRepository, IData data)
|
|
{
|
|
_linkRepository = linkRepository;
|
|
_data = data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Publie un nouveau lien sur la plateforme.
|
|
/// </summary>
|
|
/// <param name="cmd"></param>
|
|
/// <returns></returns>
|
|
public Guid PublishLink(PublishLinkCommand cmd)
|
|
{
|
|
var link = new Link(cmd.Url);
|
|
|
|
_linkRepository.Add(link);
|
|
|
|
return link.Id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Récupère tous les liens publiés jusqu'à présent.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public LinkDTO[] GetAllLinks()
|
|
{
|
|
// return (from link in _data.Links
|
|
// orderby link.CreatedAt descending
|
|
// select new LinkDTO
|
|
// {
|
|
// Id = link.Id,
|
|
// Url = link.Url,
|
|
// CreatedAt = link.CreatedAt,
|
|
// UpvotesCount = 2,
|
|
// DownvotesCount = 4,
|
|
// CommentsCount = 54,
|
|
// }).ToArray();
|
|
|
|
return _data.Links
|
|
.Select(link => new LinkDTO
|
|
{
|
|
Id = link.Id,
|
|
Url = link.Url,
|
|
CreatedAt = link.CreatedAt,
|
|
UpvotesCount = 2,
|
|
DownvotesCount = 4,
|
|
CommentsCount = 54,
|
|
})
|
|
// .Where(linkDto => linkDto.UpvotesCount > 5)
|
|
.OrderByDescending(linkDto => linkDto.CreatedAt)
|
|
.ToArray();
|
|
}
|
|
}
|
|
}
|