AdoS8ConfigDraftsController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Admin.NET.Plugin.AiDOP.Infrastructure.S8;
  2. using Admin.NET.Plugin.AiDOP.Const.S8;
  3. using Admin.NET.Plugin.AiDOP.Dto.S8;
  4. using Admin.NET.Plugin.AiDOP.Infrastructure;
  5. using Admin.NET.Plugin.AiDOP.Service.S8;
  6. namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
  7. [ApiController]
  8. [Route("api/aidop/s8/config/wizard-drafts")]
  9. [NonUnify]
  10. public class AdoS8ConfigDraftsController : ControllerBase
  11. {
  12. private readonly S8ConfigDraftService _svc;
  13. private readonly S8TrustedScopeResolver _scope;
  14. public AdoS8ConfigDraftsController(S8ConfigDraftService svc, S8TrustedScopeResolver scope)
  15. {
  16. _svc = svc;
  17. _scope = scope;
  18. }
  19. [HttpGet]
  20. [S8Permission(S8PermissionCatalog.ConfigRead)]
  21. public async Task<IActionResult> ListAsync([FromQuery] AdoS8ConfigDraftListQueryDto query)
  22. {
  23. var scope = await _scope.ResolveAsync();
  24. query.TenantId = scope.TenantId;
  25. query.FactoryId = scope.FactoryId;
  26. return Ok(await _svc.ListAsync(query));
  27. }
  28. [HttpGet("{id:long}")]
  29. [S8Permission(S8PermissionCatalog.ConfigRead)]
  30. public async Task<IActionResult> GetAsync(long id)
  31. {
  32. try { return Ok(await _svc.GetAsync(id, await _scope.ResolveAsync())); }
  33. catch (S8NotFoundException) { return NotFound(); }
  34. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  35. }
  36. [HttpPost]
  37. [S8Permission(S8PermissionCatalog.ConfigWatchRule)]
  38. public async Task<IActionResult> CreateAsync([FromBody] AdoS8ConfigDraftCreateDto body)
  39. {
  40. try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); }
  41. catch (S8NotFoundException) { return NotFound(); }
  42. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  43. }
  44. [HttpPut("{id:long}")]
  45. [S8Permission(S8PermissionCatalog.ConfigWatchRule)]
  46. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS8ConfigDraftUpdateDto body)
  47. {
  48. try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); }
  49. catch (S8NotFoundException) { return NotFound(); }
  50. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  51. }
  52. [HttpDelete("{id:long}")]
  53. [S8Permission(S8PermissionCatalog.ConfigWatchRule)]
  54. public async Task<IActionResult> DeleteAsync(long id)
  55. {
  56. try
  57. {
  58. await _svc.DeleteAsync(id, await _scope.ResolveAsync());
  59. return Ok(new { id, deleted = true });
  60. }
  61. catch (S8NotFoundException) { return NotFound(); }
  62. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  63. }
  64. [HttpPost("{id:long}/generate-rule")]
  65. [S8Permission(S8PermissionCatalog.ConfigWatchRule)]
  66. public async Task<IActionResult> GenerateRuleAsync(long id, [FromBody] AdoS8ConfigDraftGenerateRuleDto body)
  67. {
  68. try { return Ok(await _svc.GenerateRuleAsync(id, body, await _scope.ResolveAsync())); }
  69. catch (S8NotFoundException) { return NotFound(); }
  70. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  71. }
  72. }