AdoS8ConfigNotificationLayersController.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Admin.NET.Plugin.AiDOP.Entity.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/notification-layers")]
  7. [NonUnify]
  8. public class AdoS8ConfigNotificationLayersController : ControllerBase
  9. {
  10. private readonly S8NotificationLayerService _svc;
  11. private readonly S8TrustedScopeResolver _scope;
  12. public AdoS8ConfigNotificationLayersController(S8NotificationLayerService svc, S8TrustedScopeResolver scope)
  13. {
  14. _svc = svc;
  15. _scope = scope;
  16. }
  17. [HttpGet("role-options")]
  18. public async Task<IActionResult> GetRoleOptionsAsync() =>
  19. Ok(await _svc.GetRoleOptionsAsync());
  20. [HttpGet]
  21. public async Task<IActionResult> ListAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1)
  22. {
  23. // Compatibility-only. Security scope is resolved server-side.
  24. _ = tenantId; _ = factoryId;
  25. var scope = await _scope.ResolveAsync();
  26. return Ok(await _svc.ListAsync(scope.TenantId, scope.FactoryId));
  27. }
  28. [HttpPost]
  29. public async Task<IActionResult> CreateAsync([FromBody] AdoS8NotificationLayer body)
  30. {
  31. try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); }
  32. catch (S8NotFoundException) { return NotFound(); }
  33. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  34. }
  35. [HttpPut("{id:long}")]
  36. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS8NotificationLayer body)
  37. {
  38. try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); }
  39. catch (S8NotFoundException) { return NotFound(); }
  40. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  41. }
  42. [HttpDelete("{id:long}")]
  43. public async Task<IActionResult> DeleteAsync(long id)
  44. {
  45. try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); }
  46. catch (S8NotFoundException) { return NotFound(); }
  47. return Ok();
  48. }
  49. }