AdoS8ConfigDraftsController.cs 2.7 KB

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