-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemController.cs
More file actions
42 lines (36 loc) · 1.14 KB
/
ItemController.cs
File metadata and controls
42 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WarehouseEngine.Application.Dtos;
using WarehouseEngine.Application.Interfaces;
using WarehouseEngine.Domain.Entities;
namespace WarehouseEngine.Api.Controllers;
[ApiController]
[Authorize]
[Route("api/v{version:apiVersion}/[controller]")]
public class ItemController : ControllerBase
{
private readonly IItemService _itemService;
public ItemController(IItemService itemService)
{
_itemService = itemService;
}
[HttpGet]
[ProducesResponseType(typeof(ItemResponseDto), 200)]
public async Task<ActionResult<ItemResponseDto>> Get(Guid id)
{
var item = await _itemService.GetByIdAsync(id);
return item.Match(
item => Ok(item),
error => Problem(error.ErrorMessage, statusCode: 400)
);
}
[HttpPost]
public async Task<ActionResult<ItemResponseDto>> Create(PostItemDto itemDto)
{
var item = await _itemService.AddAsync(itemDto);
return item.Match(
item => Ok(item),
error => Problem(error.ErrorMessage, statusCode: 400)
);
}
}