完善基础数据
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using F9WebAiTest.Application.Common;
|
||||
using F9WebAiTest.Application.Common.Exceptions;
|
||||
using F9WebAiTest.Application.CQRS.SYS.Gongyingshangs.Commands;
|
||||
using F9WebAiTest.Application.CQRS.SYS.Gongyingshangs.Queries;
|
||||
using F9WebAiTest.Domain.Enums.SYS.Gongyingshangs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace F9WebAiTest.Api.Controllers;
|
||||
|
||||
/// <summary>往来单位(供应商/客户)管理</summary>
|
||||
[ApiController]
|
||||
[Route("api/sys/gongyingshang")]
|
||||
[Authorize]
|
||||
public class SysGongyingshangController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
public SysGongyingshangController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
/// <summary>分页查询(业务类型 + 销售类型 + 关键字)</summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetPaged([FromQuery] Gys_Type_Enum type = Gys_Type_Enum.干茧,
|
||||
[FromQuery] Gys_SaleType_Enum? saleType = null, [FromQuery] string like = "",
|
||||
[FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 20)
|
||||
=> Ok(ApiResult<object>.Ok(await _mediator.Send(new GetGongyingshangPagedQuery(type, saleType,
|
||||
like ?? string.Empty, pageIndex, pageSize))));
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> GetById(long id)
|
||||
{
|
||||
var result = await _mediator.Send(new GetGongyingshangByIdQuery(id));
|
||||
return result == null
|
||||
? NotFound(ApiResult<object>.Fail("往来单位不存在", 404))
|
||||
: Ok(ApiResult<object>.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] Gongyingshang_CreateCommand command)
|
||||
{
|
||||
try { return Ok(ApiResult<object>.Ok(new { id = await _mediator.Send(command) }, "新增成功")); }
|
||||
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
|
||||
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> Update(long id, [FromBody] Gongyingshang_UpdateCommand command)
|
||||
{
|
||||
try { return Ok(ApiResult<object>.Ok(await _mediator.Send(command with { Id = id }), "修改成功")); }
|
||||
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
|
||||
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> Delete(long id)
|
||||
{
|
||||
try { return Ok(ApiResult<object>.Ok(await _mediator.Send(new Gongyingshang_DelCommand(id)), "删除成功")); }
|
||||
catch (F9NotFoundException ex) { return NotFound(ApiResult<object>.Fail(ex.Message, 404)); }
|
||||
catch (F9OperationException ex) { return BadRequest(ApiResult<object>.Fail(ex.Message, 400)); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user