Skip to content

Commit

Permalink
Address PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekistler committed Jan 10, 2025
1 parent 319011e commit 06bce6c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
23 changes: 9 additions & 14 deletions src/Catalog.API/Apis/CatalogApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@ 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);
var v2 = vApi.MapGroup("api/catalog").HasApiVersion(2, 0);

// 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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -325,12 +320,12 @@ public static async Task<Results<Created, BadRequest<ProblemDetails>, NotFound<P
[AsParameters] CatalogServices services,
CatalogItem productToUpdate)
{
var catalogItem = await services.Context.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
var catalogItem = await services.Context.CatalogItems.SingleOrDefaultAsync(i => i.Id == id);

if (catalogItem == null)
{
return TypedResults.NotFound<ProblemDetails>(new (){
Detail = $"Item with id {productToUpdate.Id} not found."
Detail = $"Item with id {id} not found."
});
}

Expand All @@ -357,7 +352,7 @@ public static async Task<Results<Created, BadRequest<ProblemDetails>, NotFound<P
{
await services.Context.SaveChangesAsync();
}
return TypedResults.Created($"/api/catalog/items/{productToUpdate.Id}");
return TypedResults.Created($"/api/catalog/items/{id}");
}

[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest, "application/problem+json")]
Expand Down
3 changes: 3 additions & 0 deletions src/Catalog.API/Catalog.API.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
],
"summary": "List catalog items",
"description": "Get a paginated list of items in the catalog.",
"operationId": "ListItems",
"parameters": [
{
"name": "PageSize",
Expand Down Expand Up @@ -468,6 +469,7 @@
],
"summary": "Create or replace a catalog item",
"description": "Create or replace a catalog item",
"operationId": "UpdateItem",
"parameters": [
{
"name": "api-version",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/Catalog.API/Catalog.API_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion tests/Catalog.FunctionalTests/CatalogApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 06bce6c

Please sign in to comment.