1
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
using BITKit;
|
||||
using IDIS;
|
||||
using IDIS.Models;
|
||||
using IDIS.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IDIS_Server_SIM.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api")]
|
||||
public class IDISController:Controller
|
||||
{
|
||||
private readonly IDIS_Service _service;
|
||||
|
||||
public IDISController(IDIS_Service service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("info")]
|
||||
public IActionResult Info()
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
Content = Environment.MachineName
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("query")]
|
||||
public async Task<IActionResult> Query(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await _service.QueryAsync(key));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(ContextModel.Error(e.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("isExist")]
|
||||
public async Task<bool> IsExist(string key)
|
||||
{
|
||||
return await _service.IsExistAsync(key);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("register")]
|
||||
public async Task<IActionResult> Register()
|
||||
{
|
||||
using var reader = new StreamReader(Request.Body);
|
||||
var json = await reader.ReadToEndAsync();
|
||||
var data = JsonConvert.DeserializeObject<IDIS_Register_Data>(json)!;
|
||||
var response = await _service.RegisterAsync(data.Handle, data.TemplateVersion, data.Value);
|
||||
return Ok(response);
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("update")]
|
||||
public string Update([FromBody] string json)
|
||||
{
|
||||
return "err:0";
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("delete")]
|
||||
public async Task<bool> Delete (string handle)
|
||||
{
|
||||
await _service.DeleteAsync(handle);
|
||||
return true;
|
||||
}
|
||||
}
|
94
IDIS_Server-SIM/Controllers/IDIS_ServiceController.cs
Normal file
94
IDIS_Server-SIM/Controllers/IDIS_ServiceController.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using BITKit;
|
||||
using IDIS;
|
||||
using IDIS.Models;
|
||||
using IDIS.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IDIS_Server_SIM.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class IDIS_ServiceController:Controller
|
||||
{
|
||||
private readonly IDIS_Service _service;
|
||||
public IDIS_ServiceController(IDIS_Service service)
|
||||
{
|
||||
_service = service;
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("info")]
|
||||
public IActionResult Info()
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
Content = Environment.MachineName
|
||||
};
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("/identityv2/data/detail")]
|
||||
public async Task<IActionResult> Query(string handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _service.QueryAsync(handle);
|
||||
var response = new IDIS_Response(result);
|
||||
var json = JsonConvert.SerializeObject(response);
|
||||
//return Ok(JsonConvert.SerializeObject(response));
|
||||
return new ContentResult()
|
||||
{
|
||||
Content = json,
|
||||
ContentType = "application/json",
|
||||
StatusCode = 200
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(new IDIS_Response(e.Message,false)
|
||||
{
|
||||
Status = 2
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("isExist")]
|
||||
public async Task<IActionResult> IsExist(string code)
|
||||
{
|
||||
return Ok(new IDIS_Response(await _service.IsExistAsync(code)));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("/identityv2/data")]
|
||||
public async Task<IActionResult> Register()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var reader = new StreamReader(Request.Body);
|
||||
var json = await reader.ReadToEndAsync();
|
||||
var data = JsonConvert.DeserializeObject<IDIS_Register_Data>(json)!;
|
||||
await _service.RegisterAsync(data.Handle, data.TemplateVersion, data.Value);
|
||||
return Ok(new IDIS_Response());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(new IDIS_Response(e.Message,false)
|
||||
{
|
||||
Status = 2
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("update")]
|
||||
public string Update()
|
||||
{
|
||||
return "err:0";
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("delete")]
|
||||
public async Task<bool> Delete (string code)
|
||||
{
|
||||
await _service.DeleteAsync(code);
|
||||
return true;
|
||||
}
|
||||
}
|
36
IDIS_Server-SIM/Controllers/IDIS_StatisticsController.cs
Normal file
36
IDIS_Server-SIM/Controllers/IDIS_StatisticsController.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using BITKit;
|
||||
using IDIS;
|
||||
using IDIS_Server_SIM.Extensions;
|
||||
using IDIS.Models;
|
||||
using IDIS.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IDIS_Server_SIM.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class IDIS_StatisticsController:Controller
|
||||
{
|
||||
private readonly IDIS_Statistics_MySQLBased _service;
|
||||
private readonly ILogger<IDIS_StatisticsController> _logger;
|
||||
public IDIS_StatisticsController(IDIS_Statistics_MySQLBased service, ILogger<IDIS_StatisticsController> logger)
|
||||
{
|
||||
_service = service;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[Route("/api/query/today")]
|
||||
public async Task<IActionResult> GetTodayQuery()
|
||||
{
|
||||
var result = await _service.GetTodayQuery();
|
||||
|
||||
return new IDIS_Response(result).ToActionResult();
|
||||
}
|
||||
[Route("/api/query/count")]
|
||||
public async Task<IActionResult> GetQueryCount(string handle)
|
||||
{
|
||||
var result = await _service.GetQueryCount(handle);
|
||||
|
||||
return new IDIS_Response(result).ToActionResult();
|
||||
}
|
||||
}
|
61
IDIS_Server-SIM/Controllers/IDIS_TemplateController.cs
Normal file
61
IDIS_Server-SIM/Controllers/IDIS_TemplateController.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using BITKit;
|
||||
using IDIS;
|
||||
using IDIS.Models;
|
||||
using IDIS.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IDIS_Server_SIM.Controllers;
|
||||
|
||||
[ApiController]
|
||||
|
||||
public class IDIS_TemplateController:Controller
|
||||
{
|
||||
private readonly IDIS_TemplateService _service;
|
||||
private readonly ILogger<IDIS_TemplateController> _logger;
|
||||
|
||||
public IDIS_TemplateController(IDIS_TemplateService service, ILogger<IDIS_TemplateController> logger)
|
||||
{
|
||||
_service = service;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[Route("/snms/api/template/v1")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Query(string prefix, string version)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(new IDIS_Response(await _service.QueryAsync(prefix, version)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(new IDIS_Response(e.Message,false)
|
||||
{
|
||||
Status = 2
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Route("/snms/api/template/v1")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Save()
|
||||
{
|
||||
using var reader = new StreamReader(Request.Body);
|
||||
var json = await reader.ReadToEndAsync();
|
||||
|
||||
try
|
||||
{
|
||||
var data = JsonConvert.DeserializeObject<IDIS_Template>(json)!;
|
||||
await _service.SaveAsync(data);
|
||||
return Ok(new IDIS_Response());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(new IDIS_Response(e.Message, false)
|
||||
{
|
||||
Status = 2
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user