mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(directory): ✨ finish fleshing out base GET endpoints
This commit is contained in:
parent
e1d567bf8e
commit
faf9d321f3
9 changed files with 335 additions and 1 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 LanguagesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public LanguagesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await _mediator.Send(new GetLanguages.Query(), cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 SoftwareController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SoftwareController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await _mediator.Send(new GetSoftware.Query(), cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 SyntaxesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SyntaxesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await _mediator.Send(new GetSyntaxes.Query(), cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 TagsController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public TagsController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await _mediator.Send(new GetTags.Query(), cancellationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
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 GetLanguages
|
||||
{
|
||||
public class Query : IRequest<IEnumerable<LanguageViewModel>>
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : IRequestHandler<Query, IEnumerable<LanguageViewModel>>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public Handler(IQueryContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LanguageViewModel>> Handle(
|
||||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Languages
|
||||
.ProjectTo<LanguageViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class LicenseViewModelProfile : Profile
|
||||
{
|
||||
public LicenseViewModelProfile()
|
||||
{
|
||||
CreateMap<Language, LanguageViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public class LanguageViewModel
|
||||
{
|
||||
public string Iso6391 { get; private set; } = null!;
|
||||
public string Name { get; private set; } = null!;
|
||||
public IEnumerable<int>? FilterListIds { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ public async Task<IEnumerable<LicenseViewModel>> Handle(
|
|||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Maintainers
|
||||
return await _context.Licenses
|
||||
.ProjectTo<LicenseViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
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 GetSoftware
|
||||
{
|
||||
public class Query : IRequest<IEnumerable<SoftwareViewModel>>
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : IRequestHandler<Query, IEnumerable<SoftwareViewModel>>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public Handler(IQueryContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SoftwareViewModel>> Handle(
|
||||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Software
|
||||
.ProjectTo<SoftwareViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class SoftwareViewModelProfile : Profile
|
||||
{
|
||||
public SoftwareViewModelProfile()
|
||||
{
|
||||
CreateMap<Software, SoftwareViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public class SoftwareViewModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = null!;
|
||||
public string? Description { get; private set; }
|
||||
public Uri? HomeUrl { get; private set; }
|
||||
public Uri? DownloadUrl { get; private set; }
|
||||
public bool SupportsAbpUrlScheme { get; private set; }
|
||||
public IEnumerable<int>? SyntaxIds { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
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 GetSyntaxes
|
||||
{
|
||||
public class Query : IRequest<IEnumerable<SyntaxViewModel>>
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : IRequestHandler<Query, IEnumerable<SyntaxViewModel>>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public Handler(IQueryContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SyntaxViewModel>> Handle(
|
||||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Syntaxes
|
||||
.ProjectTo<SyntaxViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class SyntaxViewModelProfile : Profile
|
||||
{
|
||||
public SyntaxViewModelProfile()
|
||||
{
|
||||
CreateMap<Syntax, SyntaxViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public class SyntaxViewModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = null!;
|
||||
public string? Description { get; private set; }
|
||||
public Uri? Url { get; private set; }
|
||||
public IEnumerable<int>? FilterListIds { get; private set; }
|
||||
public IEnumerable<int>? SoftwareIds { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
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 GetTags
|
||||
{
|
||||
public class Query : IRequest<IEnumerable<TagViewModel>>
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : IRequestHandler<Query, IEnumerable<TagViewModel>>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public Handler(IQueryContext context, IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TagViewModel>> Handle(
|
||||
Query request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Tags
|
||||
.ProjectTo<TagViewModel>(_mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public class TagViewModelProfile : Profile
|
||||
{
|
||||
public TagViewModelProfile()
|
||||
{
|
||||
CreateMap<Tag, TagViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public class TagViewModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = null!;
|
||||
public string? Description { get; private set; }
|
||||
public IEnumerable<int>? FilterListIds { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue