| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Admin.NET.Plugin.AiDOP.Entity.S8;
- using Admin.NET.Plugin.AiDOP.Infrastructure;
- using Admin.NET.Plugin.AiDOP.Service.S8;
- namespace Admin.NET.Plugin.AiDOP.Controllers.S8;
- [ApiController]
- [Route("api/aidop/s8/config/data-sources")]
- [NonUnify]
- public class AdoS8ConfigDataSourcesController : ControllerBase
- {
- private readonly S8DataSourceService _svc;
- private readonly S8TrustedScopeResolver _scope;
- public AdoS8ConfigDataSourcesController(S8DataSourceService svc, S8TrustedScopeResolver scope)
- {
- _svc = svc;
- _scope = scope;
- }
- [HttpGet]
- public async Task<IActionResult> ListAsync([FromQuery] long tenantId = 1, [FromQuery] long factoryId = 1)
- {
- // Compatibility-only. Security scope is resolved server-side.
- _ = tenantId; _ = factoryId;
- var scope = await _scope.ResolveAsync();
- return Ok(await _svc.ListAsync(scope.TenantId, scope.FactoryId));
- }
- [HttpPost]
- public async Task<IActionResult> CreateAsync([FromBody] AdoS8DataSource body)
- {
- try { return Ok(await _svc.CreateAsync(body, await _scope.ResolveAsync())); }
- catch (S8NotFoundException) { return NotFound(); }
- catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
- }
- [HttpPut("{id:long}")]
- public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS8DataSource body)
- {
- try { return Ok(await _svc.UpdateAsync(id, body, await _scope.ResolveAsync())); }
- catch (S8NotFoundException) { return NotFound(); }
- catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
- }
- [HttpDelete("{id:long}")]
- public async Task<IActionResult> DeleteAsync(long id)
- {
- try { await _svc.DeleteAsync(id, await _scope.ResolveAsync()); }
- catch (S8NotFoundException) { return NotFound(); }
- return Ok();
- }
- [HttpPost("{id:long}/test")]
- public async Task<IActionResult> TestAsync(long id)
- {
- try { return Ok(await _svc.TestAsync(id, await _scope.ResolveAsync())); }
- catch (S8NotFoundException) { return NotFound(); }
- catch (S8BizException ex) { return BadRequest(new { message = ex.Message }); }
- }
- }
|