Viewer to Server
This commit is contained in:
23
Server/ApiControllers/AppSettingsController.cs
Normal file
23
Server/ApiControllers/AppSettingsController.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AppSettingsController : ControllerBase, IAppSettingsController<ActionResult>
|
||||
{
|
||||
|
||||
private readonly IAppSettingsRepository<Models.Binder.AppSettings> _AppSettingsRepository;
|
||||
|
||||
public AppSettingsController(IAppSettingsRepository<Models.Binder.AppSettings> AppSettingsRepository) => _AppSettingsRepository = AppSettingsRepository;
|
||||
|
||||
[HttpGet(nameof(IAppSettingsController<ActionResult>.Action.App))]
|
||||
public ActionResult GetAppSettings() =>
|
||||
Ok(_AppSettingsRepository.GetAppSettings());
|
||||
|
||||
[HttpGet(nameof(IAppSettingsController<ActionResult>.Action.DevOps))]
|
||||
public ActionResult GetBuildNumberAndGitCommitSeven() =>
|
||||
Ok(_AppSettingsRepository.GetBuildNumberAndGitCommitSeven());
|
||||
|
||||
}
|
39
Server/ApiControllers/AttachmentsController.cs
Normal file
39
Server/ApiControllers/AttachmentsController.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
public class AttachmentsController : Controller
|
||||
{
|
||||
|
||||
private readonly IAttachmentsService _AttachmentsService;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public AttachmentsController(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService)
|
||||
{
|
||||
_AttachmentsService = attachmentsService;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
|
||||
// this endpoint was created in hope that it would make retrieving attachments to display in OpenInsight easier
|
||||
// url would be like /api/attachments/mercuryprobe/header/HgProbe_66-232268-4329_20180620052640032/data.pdf
|
||||
|
||||
[HttpGet("/api/attachments/{toolTypeName}/{tabletype}/{title}/{filename}")]
|
||||
public IActionResult GetAttachment(string toolTypeName, string tabletype, string title, string filename)
|
||||
{
|
||||
ToolType tt = _MetrologyRepository.GetToolTypeByName(toolTypeName);
|
||||
bool header = !string.Equals(tabletype.Trim(), "data", StringComparison.OrdinalIgnoreCase);
|
||||
try
|
||||
{
|
||||
string contenttype = "application/pdf";
|
||||
if (filename.ToLower().TrimEnd().EndsWith(".txt"))
|
||||
contenttype = "text/plain";
|
||||
Stream fs = _AttachmentsService.GetAttachmentStreamByTitle(tt, header, title, filename);
|
||||
return File(fs, contenttype);
|
||||
}
|
||||
catch (Exception ex) { return Content(ex.Message); }
|
||||
}
|
||||
|
||||
}
|
41
Server/ApiControllers/AwaitingDispoController.cs
Normal file
41
Server/ApiControllers/AwaitingDispoController.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Text.Json;
|
||||
|
||||
// this controller is for the Awaiting Dispo functionality
|
||||
|
||||
[Route("api/[controller]")]
|
||||
public class AwaitingDispoController : Controller, IAwaitingDispoController<IActionResult>
|
||||
{
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
public AwaitingDispoController(IMetrologyRepository metrologyRepository) =>
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
|
||||
// returns the data to show in the Awaiting Dispo grid
|
||||
// marked no-cache, just-in-case since igniteUI automatically adds a query string parameter to prevent caching
|
||||
[HttpGet]
|
||||
[ResponseCache(NoStore = true)]
|
||||
public IActionResult Index() =>
|
||||
Json(_MetrologyRepository.GetAwaitingDisposition(), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
// this endpoint is used to set the ReviewDate column, causing the header to no longer show in Awaiting Dispo
|
||||
[HttpPost("/api/awaitingdispo/markasreviewed")]
|
||||
public IActionResult MarkAsReviewed([FromQuery] long headerid, [FromQuery] int tooltypeid)
|
||||
{
|
||||
_ = _MetrologyRepository.UpdateReviewDate(tooltypeid, headerid, false);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// this endpoint is used to clear the ReviewDate column, causing the header to show up again
|
||||
[HttpPost("/api/awaitingdispo/markasawaiting")]
|
||||
public IActionResult MarkAsAwaiting([FromQuery] long headerid, [FromQuery] int tooltypeid)
|
||||
{
|
||||
if (_MetrologyRepository.UpdateReviewDate(tooltypeid, headerid, true) <= 1)
|
||||
return Ok();
|
||||
else
|
||||
return StatusCode(444);
|
||||
}
|
||||
}
|
29
Server/ApiControllers/ClientSettingsController.cs
Normal file
29
Server/ApiControllers/ClientSettingsController.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ClientSettingsController : ControllerBase, IClientSettingsController<ActionResult>
|
||||
{
|
||||
|
||||
private readonly IClientSettingsRepository _ClientSettingsRepository;
|
||||
|
||||
public ClientSettingsController(IClientSettingsRepository clientSettingsRepository) => _ClientSettingsRepository = clientSettingsRepository;
|
||||
|
||||
[HttpGet(nameof(IClientSettingsController<ActionResult>.Action.Client))]
|
||||
public ActionResult GetClientSettings()
|
||||
{
|
||||
List<string> results = _ClientSettingsRepository.GetClientSettings(Request.HttpContext.Connection?.RemoteIpAddress);
|
||||
return Ok(results);
|
||||
}
|
||||
|
||||
[HttpGet(nameof(IClientSettingsController<ActionResult>.Action.IP))]
|
||||
public ActionResult GetIpAddress()
|
||||
{
|
||||
string result = _ClientSettingsRepository.GetIpAddress(Request.HttpContext.Connection?.RemoteIpAddress);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
78
Server/ApiControllers/InboundController.cs
Normal file
78
Server/ApiControllers/InboundController.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System.Net;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public partial class InboundController : ControllerBase, IInboundController<IActionResult>
|
||||
{
|
||||
|
||||
private readonly ILogger _Logger;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IInboundRepository _InboundRepository;
|
||||
private readonly IAttachmentsService _AttachmentsService;
|
||||
private readonly IInboundDataService _InboundDataService;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IInboundRepository inboundRepository, IInboundDataService inboundDataService, IAttachmentsService attachmentsService)
|
||||
{
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_InboundRepository = inboundRepository;
|
||||
_AttachmentsService = attachmentsService;
|
||||
_InboundDataService = inboundDataService;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{tooltype}")]
|
||||
public IActionResult Data(string tooltype, [FromBody] JToken jsonbody)
|
||||
{
|
||||
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
|
||||
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
|
||||
{
|
||||
_Logger.LogInformation($"Rejected remote IP: {remoteIP}");
|
||||
return Unauthorized("Remote IP is not on allowed list");
|
||||
}
|
||||
else
|
||||
{
|
||||
DataResponse dataResponse = _InboundRepository.Data(_MetrologyRepository, _InboundDataService, tooltype, jsonbody);
|
||||
if (!dataResponse.Errors.Any())
|
||||
return Ok(dataResponse);
|
||||
else
|
||||
return BadRequest(dataResponse);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{tooltype}/attachment")]
|
||||
public IActionResult AttachFile(string tooltype, [FromQuery] long headerid, [FromQuery] string datauniqueid = "")
|
||||
{
|
||||
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
|
||||
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
|
||||
{
|
||||
_Logger.LogInformation($"Rejected remote IP: {remoteIP}");
|
||||
return Unauthorized("Remote IP is not on allowed list");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Request.Form is null)
|
||||
return BadRequest($"Invalid form");
|
||||
if (Request.Form.Files.Count != 1)
|
||||
return BadRequest($"Invalid file count");
|
||||
IFormFile formFile = Request.Form.Files[0];
|
||||
string? message = _InboundRepository.AttachFile(_MetrologyRepository, _AttachmentsService, tooltype, headerid, datauniqueid, formFile.FileName, formFile);
|
||||
if (message is null)
|
||||
return Ok();
|
||||
else
|
||||
return BadRequest(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
Server/ApiControllers/PinController.cs
Normal file
33
Server/ApiControllers/PinController.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using System.Text.Json;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
public class PinController : Controller, IPinController<IActionResult>
|
||||
{
|
||||
|
||||
private readonly IPinRepository _PinRepository;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public PinController(ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IPinRepository pinRepository)
|
||||
{
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
_PinRepository = pinRepository;
|
||||
}
|
||||
|
||||
[HttpPost("{toolTypeId}/markAsPinned")]
|
||||
public IActionResult MarkAsPinned(Shared.DataModels.HeaderCommon headerCommon)
|
||||
{
|
||||
_PinRepository.SetPinnedTable(headerCommon);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{toolTypeId}/pinned")]
|
||||
public IActionResult GetPinnedTable(int toolTypeId, string? biorad_id = null, string? cde_id = null, string? rds = null) =>
|
||||
Json(_PinRepository.GetPinnedTable(_MetrologyRepository, toolTypeId, biorad_id, cde_id, rds), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
}
|
46
Server/ApiControllers/ServiceShopOrderController.cs
Normal file
46
Server/ApiControllers/ServiceShopOrderController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class ServiceShopOrderController : ControllerBase, IServiceShopOrderController<ActionResult>
|
||||
{
|
||||
|
||||
private readonly IServiceShopOrderRepository _ServiceShopOrderRepository;
|
||||
|
||||
public ServiceShopOrderController(IServiceShopOrderRepository ServiceShopOrderRepository) => _ServiceShopOrderRepository = ServiceShopOrderRepository;
|
||||
|
||||
[HttpGet(nameof(IServiceShopOrderController<ActionResult>.Action.All))]
|
||||
public async Task<ActionResult> GetAllServiceShopOrders()
|
||||
{
|
||||
try
|
||||
{
|
||||
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderRepository.GetAllServiceShopOrders();
|
||||
return Ok(results);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError,
|
||||
"Error retrieving data from the database");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<ActionResult> GetServiceShopOrders(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderRepository.GetServiceShopOrders(id);
|
||||
return Ok(results);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError,
|
||||
"Error retrieving data from the database");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
110
Server/ApiControllers/ToolTypesController.cs
Normal file
110
Server/ApiControllers/ToolTypesController.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace OI.Metrology.Server.ApiControllers;
|
||||
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System.Data;
|
||||
using System.Text.Json;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
public class ToolTypesController : Controller, IToolTypesController<IActionResult>
|
||||
{
|
||||
// this controller powers the bulk of the UI
|
||||
// it is named after the /api/tooltypes prefix
|
||||
// the URL pattern is RESTful and the tool type is the root of every request
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IMetrologyRepository _MetrologyRepo;
|
||||
private readonly IAttachmentsService _AttachmentsService;
|
||||
private readonly IToolTypesRepository _ToolTypesRepository;
|
||||
|
||||
public ToolTypesController(AppSettings appSettings, IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, IToolTypesRepository toolTypesRepository)
|
||||
{
|
||||
_AppSettings = appSettings;
|
||||
_MetrologyRepo = metrologyRepository;
|
||||
_AttachmentsService = attachmentsService;
|
||||
_ToolTypesRepository = toolTypesRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index() =>
|
||||
Json(_ToolTypesRepository.Index(_MetrologyRepo), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public IActionResult GetToolTypeMetadata(int id, string sortby = "") =>
|
||||
Json(_ToolTypesRepository.GetToolTypeMetadata(_MetrologyRepo, id, sortby), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/headers")]
|
||||
public IActionResult GetHeaders(int id, [FromQuery] DateTime? datebegin, [FromQuery] DateTime? dateend, [FromQuery] int? page, [FromQuery] int? pagesize, [FromQuery] long? headerid)
|
||||
{
|
||||
Shared.DataModels.Result<DataTable> r = _ToolTypesRepository.GetHeaders(_MetrologyRepo, id, datebegin, dateend, page, pagesize, headerid);
|
||||
string json = JsonConvert.SerializeObject(r);
|
||||
return Content(json);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/headertitles")]
|
||||
public IActionResult GetHeaderTitles(int id, [FromQuery] int? page, [FromQuery] int? pagesize) =>
|
||||
Json(_ToolTypesRepository.GetHeaderTitles(_MetrologyRepo, id, page, pagesize), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/headers/{headerid}/fields")]
|
||||
public IActionResult GetHeaderFields(int id, long headerid) =>
|
||||
Json(_ToolTypesRepository.GetHeaderFields(_MetrologyRepo, id, headerid), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/headers/{headerid}/data")]
|
||||
public IActionResult GetData(int id, long headerid)
|
||||
{
|
||||
Shared.DataModels.Result<DataTable> r = _ToolTypesRepository.GetData(_MetrologyRepo, id, headerid);
|
||||
string json = JsonConvert.SerializeObject(r);
|
||||
return Content(json);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{toolTypeId}/export")]
|
||||
public IActionResult GetExportData(int toolTypeId, [FromQuery] DateTime? datebegin, [FromQuery] DateTime? dateend)
|
||||
{
|
||||
Shared.DataModels.Result<DataTable> r = _ToolTypesRepository.GetExportData(_MetrologyRepo, toolTypeId, datebegin, dateend);
|
||||
string json = JsonConvert.SerializeObject(r);
|
||||
return Content(json);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{toolTypeId}/csv")]
|
||||
public IActionResult GetCSVExport(int toolTypeId, [FromQuery] DateTime? datebegin, [FromQuery] DateTime? dateend, [FromQuery] string? filename)
|
||||
{
|
||||
byte[] r = _ToolTypesRepository.GetCSVExport(_MetrologyRepo, toolTypeId, datebegin, dateend);
|
||||
return File(r, "application/octet-stream", filename);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{toolTypeId}/{tabletype}/files/{attachmentId}/{filename}")]
|
||||
public IActionResult GetAttachment(int toolTypeId, string tabletype, string attachmentId, string filename)
|
||||
{
|
||||
(string? message, string? contenttype, Stream? stream) = _ToolTypesRepository.GetAttachment(_MetrologyRepo, _AttachmentsService, toolTypeId, tabletype, attachmentId, filename);
|
||||
if (message is not null)
|
||||
return Content(message);
|
||||
else if (contenttype is not null && stream is not null)
|
||||
return File(stream, contenttype);
|
||||
else
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{toolTypeId}/headers/{headerid}/oiexport")]
|
||||
public IActionResult OIExport(int toolTypeId, long headerid)
|
||||
{
|
||||
Exception? exception = _ToolTypesRepository.OIExport(_MetrologyRepo, _AppSettings.OIExportPath, toolTypeId, headerid);
|
||||
if (exception is null)
|
||||
return Ok(new { Message = "OK" });
|
||||
else
|
||||
return BadRequest(JsonConvert.SerializeObject(new { exception.Message }));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user