Moved request objects to Contract project
This commit is contained in:
parent
1ea95d81d1
commit
d4fc49c8d1
18 changed files with 50 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
namespace GitHubActionsDemo.Api.Models;
|
||||
namespace GitHubActionsDemo.Api.Contract;
|
||||
|
||||
public class AuthorRequest
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace GitHubActionsDemo.Api.Models;
|
||||
namespace GitHubActionsDemo.Api.Contract;
|
||||
|
||||
public class BookRequest
|
||||
{
|
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,6 +1,6 @@
|
|||
namespace GitHubActionsDemo.Api.Models;
|
||||
namespace GitHubActionsDemo.Api.Contract;
|
||||
|
||||
public class PageParameters
|
||||
public class PageRequest
|
||||
{
|
||||
public int Page { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 10;
|
6
src/GitHubActionsDemo.Api.Sdk/Class1.cs
Normal file
6
src/GitHubActionsDemo.Api.Sdk/Class1.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace GitHubActionsDemo.Api.Sdk;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,4 +1,4 @@
|
|||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Mappers;
|
||||
using GitHubActionsDemo.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -12,12 +12,12 @@ public class AuthorsController : BaseController
|
|||
{
|
||||
private readonly ILibraryService _libraryService;
|
||||
private readonly IValidator<AuthorRequest> _authorValidator;
|
||||
private readonly IValidator<PageParameters> _pageValidator;
|
||||
private readonly IValidator<PageRequest> _pageValidator;
|
||||
|
||||
public AuthorsController(
|
||||
ILibraryService libraryService,
|
||||
IValidator<AuthorRequest> authorValidator,
|
||||
IValidator<PageParameters> pageValidator
|
||||
IValidator<PageRequest> pageValidator
|
||||
)
|
||||
{
|
||||
_libraryService = libraryService ?? throw new ArgumentNullException(nameof(libraryService));
|
||||
|
@ -53,7 +53,7 @@ public class AuthorsController : BaseController
|
|||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IResult> GetAuthorsAsync([FromQuery] PageParameters parameters)
|
||||
public async Task<IResult> GetAuthorsAsync([FromQuery] PageRequest parameters)
|
||||
{
|
||||
var validationResult = await _pageValidator.ValidateAsync(parameters);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Mappers;
|
||||
using GitHubActionsDemo.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -12,12 +12,12 @@ public class BooksController : BaseController
|
|||
{
|
||||
private readonly ILibraryService _libraryService;
|
||||
private readonly IValidator<BookRequest> _bookValidator;
|
||||
private readonly IValidator<PageParameters> _pageValidator;
|
||||
private readonly IValidator<PageRequest> _pageValidator;
|
||||
|
||||
public BooksController(
|
||||
ILibraryService libraryService,
|
||||
IValidator<BookRequest> bookValidator,
|
||||
IValidator<PageParameters> pageValidator
|
||||
IValidator<PageRequest> pageValidator
|
||||
)
|
||||
{
|
||||
_libraryService = libraryService ?? throw new ArgumentNullException(nameof(libraryService));
|
||||
|
@ -26,7 +26,7 @@ public class BooksController : BaseController
|
|||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IResult> GetBooksAsync([FromQuery] PageParameters parameters)
|
||||
public async Task<IResult> GetBooksAsync([FromQuery] PageRequest parameters)
|
||||
{
|
||||
var validationResult = await _pageValidator.ValidateAsync(parameters);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GitHubActionsDemo.Api.Contract\GitHubActionsDemo.Api.Contract.csproj" />
|
||||
<ProjectReference Include="..\GitHubActionsDemo.Service\GitHubActionsDemo.Service.csproj" />
|
||||
<ProjectReference Include="..\GitHubActionsDemo.Persistance\GitHubActionsDemo.Persistance.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Service.Models;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Service.Models;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using FluentValidation;
|
||||
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||
|
||||
public class AuthorRequestValidator : AbstractValidator<AuthorRequest>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using FluentValidation;
|
||||
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||
|
||||
public class BookRequestValidator : AbstractValidator<BookRequest>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using FluentValidation;
|
||||
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||
|
||||
public class PageParametersValidator : AbstractValidator<PageParameters>
|
||||
public class PageParametersValidator : AbstractValidator<PageRequest>
|
||||
{
|
||||
public PageParametersValidator()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ using GitHubActionsDemo.Service.Infrastructure;
|
|||
using GitHubActionsDemo.Persistance.Infrastructure;
|
||||
using Serilog;
|
||||
using FluentValidation;
|
||||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Models.Validators;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
@ -15,7 +15,7 @@ builder.Logging.AddSerilog(logger);
|
|||
|
||||
builder.Services.AddScoped<IValidator<AuthorRequest>, AuthorRequestValidator>();
|
||||
builder.Services.AddScoped<IValidator<BookRequest>, BookRequestValidator>();
|
||||
builder.Services.AddScoped<IValidator<PageParameters>, PageParametersValidator>();
|
||||
builder.Services.AddScoped<IValidator<PageRequest>, PageParametersValidator>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Net;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using GitHubActionsDemo.Api.Contract;
|
||||
using GitHubActionsDemo.Api.Controllers;
|
||||
using GitHubActionsDemo.Api.Models;
|
||||
using GitHubActionsDemo.Service;
|
||||
|
@ -13,7 +14,7 @@ public class AuthorsControllerTests
|
|||
{
|
||||
private readonly Mock<ILibraryService> _libraryService;
|
||||
private readonly Mock<IValidator<AuthorRequest>> _authorValidator;
|
||||
private readonly Mock<IValidator<PageParameters>> _pageValidator;
|
||||
private readonly Mock<IValidator<PageRequest>> _pageValidator;
|
||||
|
||||
private readonly AuthorsController _sut;
|
||||
|
||||
|
@ -21,7 +22,7 @@ public class AuthorsControllerTests
|
|||
{
|
||||
_libraryService = new Mock<ILibraryService>();
|
||||
_authorValidator = new Mock<IValidator<AuthorRequest>>();
|
||||
_pageValidator = new Mock<IValidator<PageParameters>>();
|
||||
_pageValidator = new Mock<IValidator<PageRequest>>();
|
||||
_sut = new AuthorsController(_libraryService.Object, _authorValidator.Object, _pageValidator.Object);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,4 +66,6 @@ public class LibraryServiceTests
|
|||
result.AsT0.Value.Title.ShouldBe(newBook.Title);
|
||||
result.AsT0.Value.Isbn.ShouldBe(newBook.Isbn);
|
||||
}
|
||||
|
||||
// TODO: Note in a production application there would be a complete set of unit tests here.
|
||||
}
|
Loading…
Reference in a new issue