using HackerNet.Application; using HackerNet.Domain; namespace HackerNet.Infrastructure.Repositories.Memory; public class MemoryLinkRepository : ILinkRepository, IReadStore { private List _links; public MemoryLinkRepository(params Link[] links) { _links = links.ToList(); } public void Add(Link link) { _links.Add(link); } public LinkHomePage GetLinkDetail(Guid id) => GetLinks(id).Single(); public LinkHomePage[] GetPublishedLinks() { // return (from l in _links // orderby l.CreatedAt descending // select new LinkHomePage // { // Id = l.Id, // Url = l.Url, // Description = l.Description, // CommentsCount = 0, // }).ToArray(); return GetLinks().ToArray(); } private IEnumerable GetLinks(Guid? id = null) { return _links .Where(l => !id.HasValue || l.Id == id) .OrderByDescending(l => l.CreatedAt) .Select(l => new LinkHomePage { Id = l.Id, Url = l.Url, Description = l.Description, CommentsCount = 0, }); } }