Viewer to Server
This commit is contained in:
@ -4,30 +4,30 @@ using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OI.Metrology.Archive.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OI.Metrology.Archive.ApiContollers;
|
||||
namespace OI.Metrology.Archive.ApiControllers;
|
||||
|
||||
[ApiController]
|
||||
public class InboundController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _Logger;
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IAttachmentsService _AttachmentService;
|
||||
private readonly IInboundDataService _InboundDataService;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
|
||||
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
|
||||
{
|
||||
_Repo = repo;
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
_AttachmentService = attachmentService;
|
||||
_InboundDataService = inboundDataService;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
|
||||
// this class represents the API response back to the client
|
||||
@ -61,9 +61,9 @@ public class InboundController : ControllerBase
|
||||
return Unauthorized(r);
|
||||
}
|
||||
|
||||
ToolType toolType = _Repo.GetToolTypeByName(tooltype);
|
||||
ToolType toolType = _MetrologyRepository.GetToolTypeByName(tooltype);
|
||||
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
{
|
||||
r.Errors.Add("Invalid tool type: " + tooltype);
|
||||
return BadRequest(r);
|
||||
@ -71,9 +71,9 @@ public class InboundController : ControllerBase
|
||||
|
||||
// get metadata
|
||||
|
||||
List<ToolTypeMetadata> metaData = _Repo.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
|
||||
List<ToolTypeMetadata> metaData = _MetrologyRepository.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
|
||||
|
||||
if (metaData == null)
|
||||
if (metaData is null)
|
||||
{
|
||||
r.Errors.Add("Invalid metadata for tool type: " + tooltype);
|
||||
return BadRequest(r);
|
||||
@ -81,7 +81,7 @@ public class InboundController : ControllerBase
|
||||
|
||||
// validate fields
|
||||
|
||||
if (jsonbody != null)
|
||||
if (jsonbody is not null)
|
||||
_InboundDataService.ValidateJSONFields(jsonbody, 0, metaData, r.Errors, r.Warnings);
|
||||
else
|
||||
r.Errors.Add("Invalid json");
|
||||
@ -118,12 +118,12 @@ public class InboundController : ControllerBase
|
||||
return Unauthorized("Remote IP is not on allowed list");
|
||||
}
|
||||
|
||||
ToolType toolType = _Repo.GetToolTypeByName(tooltype);
|
||||
ToolType toolType = _MetrologyRepository.GetToolTypeByName(tooltype);
|
||||
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
return BadRequest($"Invalid tool type: {tooltype}");
|
||||
|
||||
if (Request.Form == null)
|
||||
if (Request.Form is null)
|
||||
return BadRequest($"Invalid form");
|
||||
|
||||
if (Request.Form.Files.Count != 1)
|
||||
|
Reference in New Issue
Block a user