mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(directory): ✨ add GetLicenses endpoint
This commit is contained in:
parent
46e98c293c
commit
0c7caa0424
2 changed files with 84 additions and 0 deletions
|
|
@ -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 LicensesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public LicensesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await _mediator.Send(new GetLicenses.Query(), cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Context;
|
||||
using FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Directory.Application.Queries
|
||||
{
|
||||
public static class GetLicenses
|
||||
{
|
||||
public class Query : IRequest<IEnumerable<LicenseViewModel>>
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : IRequestHandler<Query, IEnumerable<LicenseViewModel>>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public Handler(IQueryContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LicenseViewModel>> Handle(
|
||||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Maintainers
|
||||
.ProjectTo<LicenseViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class LicenseViewModelProfile : Profile
|
||||
{
|
||||
public LicenseViewModelProfile()
|
||||
{
|
||||
CreateMap<License, LicenseViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public class LicenseViewModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = null!;
|
||||
public string? GitHubKey { get; private set; }
|
||||
public Uri? Url { get; private set; }
|
||||
public IEnumerable<int>? FilterListIds { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue