diff --git a/src/Apis/CustomersApi.cs b/src/Apis/CustomersApi.cs index e04083f..0ae78e5 100644 --- a/src/Apis/CustomersApi.cs +++ b/src/Apis/CustomersApi.cs @@ -1,4 +1,5 @@ using Asp.Versioning; +using Asp.Versioning.Builder; using Mapster; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -23,10 +24,13 @@ public void Register(IEndpointRouteBuilder builder) summary: "Customers", description: "Customers that we can apply projects and tickets.")); - group.MapGet("", GetAll) .Produces>(200, "application/json", "text/xml"); - group.MapGet("{id:int}", GetOne).WithName("GetOneCustomer"); + group.MapGet("{id:int}", GetOne) + .WithName("GetOneCustomer") + .MapToApiVersion(new ApiVersion(2.0)); + group.MapGet("{id:int}", GetOne10) + .MapToApiVersion(new ApiVersion(1.0)); group.MapPost("", Post); group.MapPut("{id:int}", Update); group.MapDelete("{id:int}", Delete); @@ -59,6 +63,26 @@ public static async Task GetOne(BillingContext ctx, int id, bool includ return Results.Ok(result); } + // Get One + public static async Task GetOne10(BillingContext ctx, int id) + { + var result = await ctx.Customers + .Where(c => c.Id == id) + .Select(c => new + { + c.Id, + c.CompanyName, + c.Contact, + c.PhoneNumber + }) + .FirstOrDefaultAsync(); + + if (result is null) return Results.NotFound("No customer with that id Exists"); + + return Results.Ok(result); + } + + // Create public static async Task Post(BillingContext ctx, Customer model) { diff --git a/src/Services/AcceptHeaderApiVersionReader.cs b/src/Services/AcceptHeaderApiVersionReader.cs index b2779f0..3c8fc3e 100644 --- a/src/Services/AcceptHeaderApiVersionReader.cs +++ b/src/Services/AcceptHeaderApiVersionReader.cs @@ -14,7 +14,7 @@ namespace RestDesign.Services public class AcceptHeaderApiVersionReader : IApiVersionReader { // looking for application/vnd.wilderminds.arest-v2+json - private const string Pattern = @".wilderminds.arest-v(\d+(\.\d+)?)\+\S+$"; + private const string Pattern = @".design.rest-v(\d+(\.\d+)?)\+\S+$"; public void AddParameters(IApiVersionParameterDescriptionContext context) { diff --git a/src/test.rest b/src/test.rest index 950a69d..6c49307 100644 --- a/src/test.rest +++ b/src/test.rest @@ -5,20 +5,14 @@ Accept: application/json ### -GET http://localhost:5000/api/customers +GET http://localhost:5000/api/customers?v=1.0 Accept: application/json ### -GET {{root}}/regions -Accept: application/json - -### +GET http://localhost:5000/api/customers/9 +Accept: application/vnd.design.rest-v2+json +#X-Version: 2.0 -GET {{root}}/sites -Accept: application/json ### - -GET {{root}}/sites/1457 -Accept: application/json