-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCategoryController.cs
56 lines (46 loc) · 1.71 KB
/
CategoryController.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Threading.Tasks;
using CleanArchCourse.Application.Features.CategoryOperations.Command.CreateCategory;
using CleanArchCourse.Application.Features.CategoryOperations.Command.DeleteCategory;
using CleanArchCourse.Application.Features.CategoryOperations.Command.UpdateCategory;
using Microsoft.AspNetCore.Mvc;
using CleanArchCourse.Application.Features.CategoryOperations.Queries.GetAllCategory;
using CleanArchCourse.Application.Features.CategoryOperations.Queries.GetByIdCategory;
using MediatR;
namespace CleanArchCourse.WebAPI.Controllers
{
[Route("api/[controller]s")]
[ApiController]
public class CategoryController : ControllerBase
{
private readonly IMediator _mediator;
public CategoryController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet]
public async Task<IActionResult> GetAll()
{
return Ok(await _mediator.Send(new GetAllCategoryRequest()));
}
[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id)
{
return Ok(await _mediator.Send(new GetByIdCategoryRequest { Id = id }));
}
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateCategoryRequest request)
{
return Ok(await _mediator.Send(request));
}
[HttpPut]
public async Task<IActionResult> Update([FromBody] UpdateCategoryRequest request)
{
return Ok(await _mediator.Send(request));
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
return Ok(await _mediator.Send(new DeleteCategoryRequest { Id = id }));
}
}
}