59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using AMREZ.EOP.Abstractions.Applications.UseCases.MasterData.Brand;
|
|
using AMREZ.EOP.Contracts.DTOs.Common;
|
|
using AMREZ.EOP.Contracts.DTOs.MasterData.Brand;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AMREZ.EOP.API.Controllers.MasterData;
|
|
|
|
[ApiController]
|
|
[Route("api/master/brands")]
|
|
public sealed class BrandsController : ControllerBase
|
|
{
|
|
private readonly IListBrandsUseCase _list;
|
|
private readonly IGetBrandUseCase _get;
|
|
private readonly ICreateBrandUseCase _create;
|
|
private readonly IUpdateBrandUseCase _update;
|
|
private readonly IDeleteBrandUseCase _delete;
|
|
|
|
public BrandsController(
|
|
IListBrandsUseCase list,
|
|
IGetBrandUseCase get,
|
|
ICreateBrandUseCase create,
|
|
IUpdateBrandUseCase update,
|
|
IDeleteBrandUseCase delete)
|
|
{
|
|
_list = list; _get = get; _create = create; _update = update; _delete = delete;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<PagedResponse<BrandResponse>>> List([FromQuery] BrandListRequest query, CancellationToken ct)
|
|
=> Ok(await _list.ExecuteAsync(query, ct));
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> Get(Guid id, CancellationToken ct)
|
|
{
|
|
var res = await _get.ExecuteAsync(id, ct);
|
|
return res is null ? NotFound() : Ok(res);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create([FromBody] BrandCreateRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _create.ExecuteAsync(body, ct);
|
|
return CreatedAtAction(nameof(Get), new { id = res.Id }, res);
|
|
}
|
|
|
|
[HttpPut("{id:guid}")]
|
|
public async Task<IActionResult> Update(Guid id, [FromBody] BrandUpdateRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _update.ExecuteAsync(id, body, ct);
|
|
return res is null ? NotFound() : Ok(res);
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
|
{
|
|
var ok = await _delete.ExecuteAsync(id, ct);
|
|
return ok ? NoContent() : NotFound();
|
|
}
|
|
} |