dodanie endpointu zwracającego produkt po nazwie
This commit is contained in:
parent
c4f62ec62b
commit
d68dd5b65b
@ -45,6 +45,17 @@ namespace FirmTracker_Server.Controllers
|
|||||||
return Ok(product);
|
return Ok(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("name/{name}")]
|
||||||
|
[ProducesResponseType(200)]
|
||||||
|
[ProducesResponseType(404)]
|
||||||
|
public IActionResult GetProductByName(string name)
|
||||||
|
{
|
||||||
|
var product = _productCrud.GetProductByName(name);
|
||||||
|
if (product ==null)
|
||||||
|
return NotFound();
|
||||||
|
return Ok(product);
|
||||||
|
}
|
||||||
|
|
||||||
// PUT: api/Products/5
|
// PUT: api/Products/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[ProducesResponseType(200)] // Created
|
[ProducesResponseType(200)] // Created
|
||||||
|
@ -61,6 +61,16 @@ namespace FirmTracker_Server.nHibernate.Products
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Product GetProductByName(string productName)
|
||||||
|
{
|
||||||
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
{
|
||||||
|
var query = session.CreateQuery("from Product where Name = :name");
|
||||||
|
query.SetParameter("name", productName);
|
||||||
|
return query.UniqueResult<Product>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateProduct(Product product)
|
public void UpdateProduct(Product product)
|
||||||
{
|
{
|
||||||
using (var session = SessionFactory.OpenSession())
|
using (var session = SessionFactory.OpenSession())
|
||||||
|
Loading…
Reference in New Issue
Block a user