diff --git a/src/Catalog.API/Apis/CatalogApi.cs b/src/Catalog.API/Apis/CatalogApi.cs index ab3179e3..69a1a522 100644 --- a/src/Catalog.API/Apis/CatalogApi.cs +++ b/src/Catalog.API/Apis/CatalogApi.cs @@ -12,11 +12,6 @@ public static class CatalogApi public static IEndpointRouteBuilder MapCatalogApi(this IEndpointRouteBuilder app) { // RouteGroupBuilder for catalog endpoints - // var vapi = app.NewVersionedApi("Catalog").MapGroup("api/catalog"); - // var api = vapi.HasApiVersion(1.0).HasApiVersion(2.0); - // var v1 = vapi.HasApiVersion(1.0); - // var v2 = vapi.HasApiVersion(2.0); - var vApi = app.NewVersionedApi("Catalog"); var api = vApi.MapGroup("api/catalog").HasApiVersion(1, 0).HasApiVersion(2, 0); var v1 = vApi.MapGroup("api/catalog").HasApiVersion(1, 0); @@ -24,12 +19,12 @@ public static IEndpointRouteBuilder MapCatalogApi(this IEndpointRouteBuilder app // Routes for querying catalog items. v1.MapGet("/items", GetAllItemsV1) - // .WithName("ListItems") + .WithName("ListItems") .WithSummary("List catalog items") .WithDescription("Get a paginated list of items in the catalog.") .WithTags("Items"); v2.MapGet("/items", GetAllItems) - .WithName("ListItems") + .WithName("ListItems-V2") .WithSummary("List catalog items") .WithDescription("Get a paginated list of items in the catalog.") .WithTags("Items"); @@ -56,14 +51,14 @@ public static IEndpointRouteBuilder MapCatalogApi(this IEndpointRouteBuilder app // Routes for resolving catalog items using AI. v1.MapGet("/items/withsemanticrelevance/{text:minlength(1)}", GetItemsBySemanticRelevanceV1) - // .WithName("GetRelevantItems") + .WithName("GetRelevantItems") .WithSummary("Search catalog for relevant items") .WithDescription("Search the catalog for items related to the specified text") .WithTags("Search"); // Routes for resolving catalog items using AI. v2.MapGet("/items/withsemanticrelevance", GetItemsBySemanticRelevance) - .WithName("GetRelevantItems") + .WithName("GetRelevantItems-V2") .WithSummary("Search catalog for relevant items") .WithDescription("Search the catalog for items related to the specified text") .WithTags("Search"); @@ -96,12 +91,12 @@ public static IEndpointRouteBuilder MapCatalogApi(this IEndpointRouteBuilder app // Routes for modifying catalog items. v1.MapPut("/items", UpdateItemV1) - // .WithName("UpdateItem") + .WithName("UpdateItem") .WithSummary("Create or replace a catalog item") .WithDescription("Create or replace a catalog item") .WithTags("Items"); v2.MapPut("/items/{id:int}", UpdateItem) - .WithName("UpdateItem") + .WithName("UpdateItem-V2") .WithSummary("Create or replace a catalog item") .WithDescription("Create or replace a catalog item") .WithTags("Items"); @@ -325,12 +320,12 @@ public static async Task, NotFound

i.Id == productToUpdate.Id); + var catalogItem = await services.Context.CatalogItems.SingleOrDefaultAsync(i => i.Id == id); if (catalogItem == null) { return TypedResults.NotFound(new (){ - Detail = $"Item with id {productToUpdate.Id} not found." + Detail = $"Item with id {id} not found." }); } @@ -357,7 +352,7 @@ public static async Task, NotFound

(StatusCodes.Status400BadRequest, "application/problem+json")] diff --git a/src/Catalog.API/Catalog.API.json b/src/Catalog.API/Catalog.API.json index 5f38b71f..bce1b2a6 100644 --- a/src/Catalog.API/Catalog.API.json +++ b/src/Catalog.API/Catalog.API.json @@ -407,6 +407,7 @@ ], "summary": "List catalog items", "description": "Get a paginated list of items in the catalog.", + "operationId": "ListItems", "parameters": [ { "name": "PageSize", @@ -468,6 +469,7 @@ ], "summary": "Create or replace a catalog item", "description": "Create or replace a catalog item", + "operationId": "UpdateItem", "parameters": [ { "name": "api-version", @@ -597,6 +599,7 @@ ], "summary": "Search catalog for relevant items", "description": "Search the catalog for items related to the specified text", + "operationId": "GetRelevantItems", "parameters": [ { "name": "PageSize", diff --git a/src/Catalog.API/Catalog.API_v2.json b/src/Catalog.API/Catalog.API_v2.json index af7a2803..e8fc6d8e 100644 --- a/src/Catalog.API/Catalog.API_v2.json +++ b/src/Catalog.API/Catalog.API_v2.json @@ -165,7 +165,7 @@ ], "summary": "Create or replace a catalog item", "description": "Create or replace a catalog item", - "operationId": "UpdateItem", + "operationId": "UpdateItem-V2", "parameters": [ { "name": "id", @@ -471,7 +471,7 @@ ], "summary": "List catalog items", "description": "Get a paginated list of items in the catalog.", - "operationId": "ListItems", + "operationId": "ListItems-V2", "parameters": [ { "name": "PageSize", @@ -561,7 +561,7 @@ ], "summary": "Search catalog for relevant items", "description": "Search the catalog for items related to the specified text", - "operationId": "GetRelevantItems", + "operationId": "GetRelevantItems-V2", "parameters": [ { "name": "PageSize", diff --git a/tests/Catalog.FunctionalTests/CatalogApiTests.cs b/tests/Catalog.FunctionalTests/CatalogApiTests.cs index 2b1412bb..f4af46f2 100644 --- a/tests/Catalog.FunctionalTests/CatalogApiTests.cs +++ b/tests/Catalog.FunctionalTests/CatalogApiTests.cs @@ -4,7 +4,6 @@ using Asp.Versioning.Http; using eShop.Catalog.API.Model; using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; namespace eShop.Catalog.FunctionalTests;