AdoS8ConfigScenesController.cs 1.8 KB

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