Skip to content

Commit 0c0bac5

Browse files
committed
GetProductByName
1 parent 8e6fcbf commit 0c0bac5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public async Task<ActionResult<IEnumerable<Product>>> GetProductByCategory(strin
5656
return Ok(products);
5757
}
5858

59+
[Route("[action]/{name}", Name = "GetProductByName")]
60+
[HttpGet]
61+
[ProducesResponseType((int)HttpStatusCode.NotFound)]
62+
[ProducesResponseType(typeof(IEnumerable<Product>), (int)HttpStatusCode.OK)]
63+
public async Task<ActionResult<IEnumerable<Product>>> GetProductByName(string name)
64+
{
65+
var items = await _repository.GetProductByName(name);
66+
if (items == null)
67+
{
68+
_logger.LogError($"Products with name: {name} not found.");
69+
return NotFound();
70+
}
71+
return Ok(items);
72+
}
73+
5974
[HttpPost]
6075
[ProducesResponseType(typeof(Product), (int)HttpStatusCode.OK)]
6176
public async Task<ActionResult<Product>> CreateProduct([FromBody] Product product)

0 commit comments

Comments
 (0)