AdoS8ConfigNotificationLayersController.cs 2.4 KB

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