AdoS8ConfigScenesController.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/scenes")]
  9. [NonUnify]
  10. public class AdoS8ConfigScenesController : ControllerBase
  11. {
  12. private readonly S8SceneConfigService _svc;
  13. private readonly S8TrustedScopeResolver _scope;
  14. public AdoS8ConfigScenesController(S8SceneConfigService svc, S8TrustedScopeResolver scope)
  15. {
  16. _svc = svc;
  17. _scope = scope;
  18. }
  19. [HttpGet]
  20. [S8Permission(S8PermissionCatalog.ConfigRead)]
  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. [S8Permission(S8PermissionCatalog.ConfigScene)]
  30. public async Task<IActionResult> CreateAsync([FromBody] AdoS8SceneConfig body)
  31. {
  32. try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); }
  33. catch (S8NotFoundException) { return NotFound(); }
  34. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  35. }
  36. [HttpPut("{id:long}")]
  37. [S8Permission(S8PermissionCatalog.ConfigScene)]
  38. public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS8SceneConfig body)
  39. {
  40. try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); }
  41. catch (S8NotFoundException) { return NotFound(); }
  42. catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
  43. }
  44. [HttpDelete("{id:long}")]
  45. [S8Permission(S8PermissionCatalog.ConfigScene)]
  46. public async Task<IActionResult> DeleteAsync(long id)
  47. {
  48. try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); }
  49. catch (S8NotFoundException) { return NotFound(); }
  50. return Ok();
  51. }
  52. }