Add Refit SDK
This commit is contained in:
parent
d4fc49c8d1
commit
0cb97f48df
25 changed files with 121 additions and 123 deletions
|
@ -1,9 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace GitHubActionsDemo.Api.Contract;
|
namespace GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
|
||||||
public class AuthorRequest
|
public class AuthorRequest
|
||||||
{
|
{
|
10
src/GitHubActionsDemo.Api.Sdk/Authors/AuthorResponse.cs
Normal file
10
src/GitHubActionsDemo.Api.Sdk/Authors/AuthorResponse.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
namespace GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
|
||||||
|
public class AuthorResponse
|
||||||
|
{
|
||||||
|
public int AuthorId { get; set; }
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public DateTime DateCreated { get; set; }
|
||||||
|
public DateTime DateModified { get; set; }
|
||||||
|
}
|
16
src/GitHubActionsDemo.Api.Sdk/Authors/IAuthorApi.cs
Normal file
16
src/GitHubActionsDemo.Api.Sdk/Authors/IAuthorApi.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
|
using Refit;
|
||||||
|
|
||||||
|
namespace GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
|
||||||
|
public interface IAuthorApi
|
||||||
|
{
|
||||||
|
[Get("/authors/")]
|
||||||
|
Task<PagedResponse<AuthorResponse>> GetAuthorsAsync();
|
||||||
|
|
||||||
|
[Get("/authors/{authorId}")]
|
||||||
|
Task<AuthorResponse> GetAuthorAsync(int authorId);
|
||||||
|
|
||||||
|
[Post("/authors/")]
|
||||||
|
Task<AuthorResponse> CreateAuthorAsync([Body] AuthorRequest request);
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
namespace GitHubActionsDemo.Api.Contract;
|
namespace GitHubActionsDemo.Api.Sdk.Books;
|
||||||
|
|
||||||
public class BookRequest
|
public class BookRequest
|
||||||
{
|
{
|
14
src/GitHubActionsDemo.Api.Sdk/Books/BookResponse.cs
Normal file
14
src/GitHubActionsDemo.Api.Sdk/Books/BookResponse.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
|
||||||
|
namespace GitHubActionsDemo.Api.Sdk.Books;
|
||||||
|
|
||||||
|
public class BookResponse
|
||||||
|
{
|
||||||
|
public int BookId { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public AuthorResponse Author { get; set; }
|
||||||
|
public string Isbn { get; set; }
|
||||||
|
public DateTime DatePublished { get; set; }
|
||||||
|
public DateTime DateCreated { get; set; }
|
||||||
|
public DateTime DateModified { get; set; }
|
||||||
|
}
|
16
src/GitHubActionsDemo.Api.Sdk/Books/IBookApi.cs
Normal file
16
src/GitHubActionsDemo.Api.Sdk/Books/IBookApi.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
|
using Refit;
|
||||||
|
|
||||||
|
namespace GitHubActionsDemo.Api.Sdk.Books;
|
||||||
|
|
||||||
|
public interface IBookApi
|
||||||
|
{
|
||||||
|
[Get("/books/")]
|
||||||
|
Task<PagedResponse<BookResponse>> GetBooksAsync();
|
||||||
|
|
||||||
|
[Get("/books/{bookId}")]
|
||||||
|
Task<BookResponse> GetBookAsync(int bookId);
|
||||||
|
|
||||||
|
[Post("/books/")]
|
||||||
|
Task<IList<BookResponse>> CreateBookAsync([Body] BookRequest request);
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
namespace GitHubActionsDemo.Api.Sdk;
|
|
||||||
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,5 +5,8 @@
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Refit" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace GitHubActionsDemo.Api.Contract;
|
namespace GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
|
|
||||||
public class PageRequest
|
public class PageRequest
|
||||||
{
|
{
|
16
src/GitHubActionsDemo.Api.Sdk/Shared/PagedResponse.cs
Normal file
16
src/GitHubActionsDemo.Api.Sdk/Shared/PagedResponse.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using System.Collections;
|
||||||
|
namespace GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
|
|
||||||
|
public class PagedResponse<T> where T : class
|
||||||
|
{
|
||||||
|
public int Page { get; set; }
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Result.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IList<T> Result { get; set; }
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
using GitHubActionsDemo.Api.Mappers;
|
using GitHubActionsDemo.Api.Mappers;
|
||||||
using GitHubActionsDemo.Service;
|
using GitHubActionsDemo.Service;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using GitHubActionsDemo.Api.Models;
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace GitHubActionsDemo.Api.Controllers;
|
namespace GitHubActionsDemo.Api.Controllers;
|
||||||
|
@ -12,8 +12,13 @@ public class BaseController : ControllerBase
|
||||||
return Results.StatusCode((int)HttpStatusCode.InternalServerError);
|
return Results.StatusCode((int)HttpStatusCode.InternalServerError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IResult PagedResult<T>(int page, int pageSize, T result) where T : IList
|
public IResult PagedResult<T>(int page, int pageSize, IList<T> result) where T : class
|
||||||
{
|
{
|
||||||
return Results.Ok(new PagedResponse<T>(page, pageSize, result));
|
return Results.Ok(new PagedResponse<T>
|
||||||
|
{
|
||||||
|
Page = page,
|
||||||
|
PageSize = pageSize,
|
||||||
|
Result = result
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Books;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
using GitHubActionsDemo.Api.Mappers;
|
using GitHubActionsDemo.Api.Mappers;
|
||||||
using GitHubActionsDemo.Service;
|
using GitHubActionsDemo.Service;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GitHubActionsDemo.Api.Contract\GitHubActionsDemo.Api.Contract.csproj" />
|
<ProjectReference Include="..\GitHubActionsDemo.Api.Sdk\GitHubActionsDemo.Api.Sdk.csproj" />
|
||||||
<ProjectReference Include="..\GitHubActionsDemo.Service\GitHubActionsDemo.Service.csproj" />
|
<ProjectReference Include="..\GitHubActionsDemo.Service\GitHubActionsDemo.Service.csproj" />
|
||||||
<ProjectReference Include="..\GitHubActionsDemo.Persistance\GitHubActionsDemo.Persistance.csproj" />
|
<ProjectReference Include="..\GitHubActionsDemo.Persistance\GitHubActionsDemo.Persistance.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
using GitHubActionsDemo.Api.Models;
|
using GitHubActionsDemo.Api.Models;
|
||||||
using GitHubActionsDemo.Service.Models;
|
using GitHubActionsDemo.Service.Models;
|
||||||
|
|
||||||
|
@ -16,12 +16,14 @@ public static class AuthorMapper
|
||||||
|
|
||||||
public static AuthorResponse Map(this Author author)
|
public static AuthorResponse Map(this Author author)
|
||||||
{
|
{
|
||||||
return new AuthorResponse(
|
return new AuthorResponse
|
||||||
author.AuthorId,
|
{
|
||||||
author.FirstName,
|
AuthorId = author.AuthorId,
|
||||||
author.LastName,
|
FirstName = author.FirstName,
|
||||||
author.DateCreated,
|
LastName = author.LastName,
|
||||||
author.DateModified
|
DateCreated = author.DateCreated,
|
||||||
);
|
DateModified = author.DateModified
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Books;
|
||||||
using GitHubActionsDemo.Api.Models;
|
using GitHubActionsDemo.Api.Models;
|
||||||
using GitHubActionsDemo.Service.Models;
|
using GitHubActionsDemo.Service.Models;
|
||||||
|
|
||||||
|
@ -18,14 +18,15 @@ public static class BookMapper
|
||||||
|
|
||||||
public static BookResponse Map(this Book book)
|
public static BookResponse Map(this Book book)
|
||||||
{
|
{
|
||||||
return new BookResponse(
|
return new BookResponse
|
||||||
book.BookId,
|
{
|
||||||
book.Title,
|
BookId = book.BookId,
|
||||||
book.Author.Map(),
|
Title = book.Title,
|
||||||
book.Isbn,
|
Author = book.Author.Map(),
|
||||||
book.DatePublished,
|
Isbn = book.Isbn,
|
||||||
book.DateCreated,
|
DatePublished = book.DatePublished,
|
||||||
book.DateModified
|
DateCreated = book.DateCreated,
|
||||||
);
|
DateModified = book.DateModified
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
namespace GitHubActionsDemo.Api.Models;
|
|
||||||
|
|
||||||
public class AuthorResponse
|
|
||||||
{
|
|
||||||
public AuthorResponse(
|
|
||||||
int authorId,
|
|
||||||
string firstName,
|
|
||||||
string lastName,
|
|
||||||
DateTime dateCreated,
|
|
||||||
DateTime dateModified
|
|
||||||
)
|
|
||||||
{
|
|
||||||
AuthorId = authorId;
|
|
||||||
FirstName = firstName;
|
|
||||||
LastName = lastName;
|
|
||||||
DateCreated = dateCreated;
|
|
||||||
DateModified = dateModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int AuthorId { get; }
|
|
||||||
public string FirstName { get; }
|
|
||||||
public string LastName { get; }
|
|
||||||
public DateTime DateCreated { get; }
|
|
||||||
public DateTime DateModified { get; }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
namespace GitHubActionsDemo.Api.Models;
|
|
||||||
|
|
||||||
public class BookResponse
|
|
||||||
{
|
|
||||||
public BookResponse(
|
|
||||||
int bookId,
|
|
||||||
string title,
|
|
||||||
AuthorResponse author,
|
|
||||||
string isbn,
|
|
||||||
DateTime datePublished,
|
|
||||||
DateTime dateCreated,
|
|
||||||
DateTime dateModified
|
|
||||||
)
|
|
||||||
{
|
|
||||||
BookId = bookId;
|
|
||||||
Title = title;
|
|
||||||
Author = author;
|
|
||||||
Isbn = isbn;
|
|
||||||
DatePublished = datePublished;
|
|
||||||
DateCreated = dateCreated;
|
|
||||||
DateModified = dateModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int BookId { get; }
|
|
||||||
public string Title { get; }
|
|
||||||
public AuthorResponse Author { get; }
|
|
||||||
public string Isbn { get; }
|
|
||||||
public DateTime DatePublished { get; }
|
|
||||||
public DateTime DateCreated { get; }
|
|
||||||
public DateTime DateModified { get; }
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
using System.Collections;
|
|
||||||
namespace GitHubActionsDemo.Api.Models;
|
|
||||||
|
|
||||||
public class PagedResponse<T> where T : IList
|
|
||||||
{
|
|
||||||
public PagedResponse(int page, int pageSize, T result)
|
|
||||||
{
|
|
||||||
Page = page;
|
|
||||||
PageSize = pageSize;
|
|
||||||
Result = result;
|
|
||||||
Count = result.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Page { get; }
|
|
||||||
public int PageSize { get; }
|
|
||||||
public int Count { get; }
|
|
||||||
public T Result { get; }
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||||
|
|
||||||
public class AuthorRequestValidator : AbstractValidator<AuthorRequest>
|
public class AuthorRequestValidator : AbstractValidator<AuthorRequest>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Books;
|
||||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||||
|
|
||||||
public class BookRequestValidator : AbstractValidator<BookRequest>
|
public class BookRequestValidator : AbstractValidator<BookRequest>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
namespace GitHubActionsDemo.Api.Models.Validators;
|
namespace GitHubActionsDemo.Api.Models.Validators;
|
||||||
|
|
||||||
public class PageParametersValidator : AbstractValidator<PageRequest>
|
public class PageParametersValidator : AbstractValidator<PageRequest>
|
||||||
|
|
|
@ -2,7 +2,9 @@ using GitHubActionsDemo.Service.Infrastructure;
|
||||||
using GitHubActionsDemo.Persistance.Infrastructure;
|
using GitHubActionsDemo.Persistance.Infrastructure;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using GitHubActionsDemo.Api.Contract;
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Books;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
using GitHubActionsDemo.Api.Models.Validators;
|
using GitHubActionsDemo.Api.Models.Validators;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using GitHubActionsDemo.Api.Contract;
|
|
||||||
using GitHubActionsDemo.Api.Controllers;
|
using GitHubActionsDemo.Api.Controllers;
|
||||||
using GitHubActionsDemo.Api.Models;
|
|
||||||
using GitHubActionsDemo.Service;
|
using GitHubActionsDemo.Service;
|
||||||
using GitHubActionsDemo.Service.Models;
|
using GitHubActionsDemo.Service.Models;
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Authors;
|
||||||
|
using GitHubActionsDemo.Api.Sdk.Shared;
|
||||||
|
|
||||||
namespace GitHubActionsDemo.Api.Tests;
|
namespace GitHubActionsDemo.Api.Tests;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue