feat(directory): 🚧 stub ListsViewModel to match legacy

This commit is contained in:
Collin M. Barrett 2020-08-25 06:36:30 -05:00
parent 12c7eff241
commit 992ecaba2d
3 changed files with 69 additions and 38 deletions

View file

@ -1,27 +0,0 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FilterLists.Directory.Application.Queries;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace FilterLists.Directory.Api.Controllers
{
[ApiController]
[Route("lists")]
public class FilterListsController : ControllerBase
{
private readonly IMediator _mediator;
public FilterListsController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet]
public async Task<IEnumerable<GetLists.FilterListViewModel>> Get(CancellationToken cancellationToken)
{
return await _mediator.Send(new GetLists.Query(), cancellationToken);
}
}
}

View file

@ -0,0 +1,26 @@
using System.Threading;
using System.Threading.Tasks;
using FilterLists.Directory.Application.Queries;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace FilterLists.Directory.Api.Controllers
{
[ApiController]
[Route("v1/[controller]")]
public class ListsController : ControllerBase
{
private readonly IMediator _mediator;
public ListsController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet]
public async Task<IActionResult> Get(CancellationToken cancellationToken)
{
return Ok(await _mediator.Send(new GetLists.Query(), cancellationToken));
}
}
}

View file

@ -10,11 +10,11 @@ namespace FilterLists.Directory.Application.Queries
{
public static class GetLists
{
public class Query : IRequest<IEnumerable<FilterListViewModel>>
public class Query : IRequest<IEnumerable<ListViewModel>>
{
}
public class Handler : IRequestHandler<Query, IEnumerable<FilterListViewModel>>
public class Handler : IRequestHandler<Query, IEnumerable<ListViewModel>>
{
private readonly IQueryContext _context;
@ -23,23 +23,55 @@ public Handler(IQueryContext context)
_context = context;
}
public async Task<IEnumerable<FilterListViewModel>> Handle(Query request,
public async Task<IEnumerable<ListViewModel>> Handle(Query request,
CancellationToken cancellationToken)
{
return await _context.FilterLists
.Select(fl => new FilterListViewModel(fl.Name))
.Select(fl => new ListViewModel
{
Id = default,
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
})
.ToListAsync(cancellationToken);
}
}
public class FilterListViewModel
public class ListViewModel
{
public FilterListViewModel(string name)
{
Name = name;
}
public string Name { get; }
public int Id { get; set; }
public string Name { get; set; }
public string? Description { get; set; }
public int? LicenseId { get; set; }
public int? SyntaxId { get; set; }
public IEnumerable<int> LanguageIds { get; set; }
public IEnumerable<int> TagIds { get; set; }
public string ViewUrl { get; set; }
public IEnumerable<string> 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<int> MaintainerIds { get; set; }
}
}
}