From 6dce16625460c17991d4fdc7f4e68b6a1509f369 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Tue, 25 Aug 2020 07:01:58 -0500 Subject: [PATCH] =?UTF-8?q?feat(directory):=20=E2=9C=A8=20implement=20GetL?= =?UTF-8?q?ists=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/FilterLists.sln.DotSettings | 2 + .../Queries/GetLists.cs | 77 +++++++++++-------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/services/FilterLists.sln.DotSettings b/services/FilterLists.sln.DotSettings index 5e46ac4e8..de90d1de6 100644 --- a/services/FilterLists.sln.DotSettings +++ b/services/FilterLists.sln.DotSettings @@ -5,5 +5,7 @@ NEVER False True + CHOP_IF_LONG + CHOP_IF_LONG CHOP_IF_LONG True \ No newline at end of file diff --git a/services/directory/src/FilterLists.Directory.Application/Queries/GetLists.cs b/services/directory/src/FilterLists.Directory.Application/Queries/GetLists.cs index 85089f647..39b79b552 100644 --- a/services/directory/src/FilterLists.Directory.Application/Queries/GetLists.cs +++ b/services/directory/src/FilterLists.Directory.Application/Queries/GetLists.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -23,30 +24,42 @@ public Handler(IQueryContext context) _context = context; } - public async Task> Handle(Query request, + public async Task> Handle( + Query request, CancellationToken cancellationToken) { return await _context.FilterLists .Select(fl => new ListViewModel { - Id = default, + Id = fl.Id, Name = fl.Name, Description = fl.Description, - LicenseId = default, - SyntaxId = default, - LanguageIds = default, - TagIds = default, - ViewUrl = default, - ViewUrlMirrors = default, - HomeUrl = default, - PolicyUrl = default, - SubmissionUrl = default, - IssuesUrl = default, - ForumUrl = default, - ChatUrl = default, - EmailAddress = default, - DonateUrl = default, - MaintainerIds = default + LicenseId = fl.License == null + ? default + : fl.License.Id, + SyntaxId = fl.FilterListSyntaxes.Any() + ? fl.FilterListSyntaxes.First().Syntax.Id + : default, + LanguageIds = fl.FilterListLanguages.Select(fll => fll.Language.Iso6391), + TagIds = fl.FilterListTags.Select(flt => flt.Tag.Id), + ViewUrl = fl.SegmentViewUrls.Any() + ? fl.SegmentViewUrls.OrderBy(s => s.Position).First().Url + : default, + ViewUrlMirrors = fl.SegmentViewUrls.Any() + ? fl.SegmentViewUrls.OrderBy(s => s.Position) + .First() + .SegmentViewUrlMirrors + .Select(m => m.Url) + : default, + HomeUrl = fl.HomeUrl, + PolicyUrl = fl.PolicyUrl, + SubmissionUrl = fl.SubmissionUrl, + IssuesUrl = fl.IssuesUrl, + ForumUrl = fl.ForumUrl, + ChatUrl = fl.ChatUrl, + EmailAddress = fl.EmailAddress, + DonateUrl = fl.DonateUrl, + MaintainerIds = fl.FilterListMaintainers.Select(flm => flm.Maintainer.Id) }) .ToListAsync(cancellationToken); } @@ -55,23 +68,23 @@ public async Task> Handle(Query request, public class ListViewModel { public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } = null!; public string? Description { get; set; } public int? LicenseId { get; set; } public int? SyntaxId { get; set; } - public IEnumerable LanguageIds { get; set; } - public IEnumerable TagIds { get; set; } - public string ViewUrl { get; set; } - public IEnumerable ViewUrlMirrors { get; set; } - public string HomeUrl { get; set; } - public string PolicyUrl { get; set; } - public string SubmissionUrl { get; set; } - public string IssuesUrl { get; set; } - public string ForumUrl { get; set; } - public string ChatUrl { get; set; } - public string EmailAddress { get; set; } - public string DonateUrl { get; set; } - public IEnumerable MaintainerIds { get; set; } + public IEnumerable? LanguageIds { get; set; } + public IEnumerable? TagIds { get; set; } + public Uri? ViewUrl { get; set; } + public IEnumerable? ViewUrlMirrors { get; set; } + public Uri? HomeUrl { get; set; } + public Uri? PolicyUrl { get; set; } + public Uri? SubmissionUrl { get; set; } + public Uri? IssuesUrl { get; set; } + public Uri? ForumUrl { get; set; } + public Uri? ChatUrl { get; set; } + public string? EmailAddress { get; set; } + public Uri? DonateUrl { get; set; } + public IEnumerable? MaintainerIds { get; set; } } } } \ No newline at end of file