FoodRest.ProductsApi
1.0.0
//GET api/items
[ HttpGet ]
public IEnumerable < Item > Get ( ) => itemRepository . Items . ToList ( ) ;
//GET api/items/F74349D5-52B4-4A4A-0382-08DA02C684C5
[ HttpGet ( "{id:guid}" ) ]
public ActionResult < Item > Get ( Guid id )
{
var item = itemRepository . Items . First ( g => g . Id == id ) ;
if ( item != null )
return item ;
return BadRequest ( ) ;
}
//GET api/items/take/2
[ HttpGet ( "take/{productPage:int}" ) ]
public IEnumerable < Item > Get ( int productPage ) => itemRepository . Items
. Skip ( ( productPage - 1 ) * PageSize )
. Take ( PageSize ) ;
//POST api/items/add/{item}
[ HttpPost ( "add" ) ]
public async Task < ActionResult < Item > > Post ( Item item )
{
try
{
if ( item == null )
{
return BadRequest ( ) ;
}
var repitem = itemRepository . Items . FirstOrDefault ( i => i . Id == item . Id ) ;
if ( repitem != null )
{
repitem . Description = item . Description ;
repitem . Category = item . Category ;
repitem . Price = item . Price ;
repitem . Name = item . Name ;
repitem . addedTime = item . addedTime ;
itemRepository . SaveItem ( repitem ) ;
}
itemRepository . SaveItem ( item ) ;
return Ok ( ) ;
}
catch ( Exception ex )
{
return StatusCode ( StatusCodes . Status500InternalServerError , "Error retrieving data from the database" ) ;
}
}
사용자가 인증하면 30분 동안 유효한 JWT 토큰이 발급됩니다. 요청 헤더에 전송됩니다. 토큰의 데이터가 일치하지 않으면 서버는 401 Not Authorized로 응답합니다.