/// <summary> /// Gets the capture image parameters with Json web token credentials. /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token. /// </summary> /// <returns> /// Byte array of image with transaction Id and image extension. /// </returns> public CaptureDto CaptureImage(Capture model) { var captureDto = new CaptureDto(); Log.Information("[HCM][Capture Image][Req]" + "[" + JsonSerializer.Serialize(model) + "]"); try { var(statusCode, errorResult) = LockerManagementValidator.PayloadValidator(LockerConfiguration, model.JwtCredentials.IsEnabled, model.JwtCredentials.Secret, model.JwtCredentials.Token, PayloadTypes.CaptureImage, model.LockerId, model.TransactionId, null, CaptureType.Photo); if (statusCode != StatusCode.Status200OK) { return(CaptureMapper.ToError(new CaptureDto { StatusCode = statusCode, Error = errorResult })); } var result = LockerHelper.CapturePhoto(model, LockerConfiguration); captureDto = CaptureMapper.ToObject(result); Log.Information("[HCM][Capture Image][Res]" + "[Success]"); } catch (Exception ex) { Log.Error("[HCM][Capture Image]" + "[" + ex + "]"); return(CaptureMapper.ToError(new CaptureDto { StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message) })); } return(captureDto); }
/// <summary> /// Gets the compartment status with Json web token credentials. /// Json web token credentials contains enable or disable, if enable then need to provide jwt secret and token. /// </summary> /// <returns> /// List of compartment status with object detection and LED status based requested compartment id's. /// </returns> public CompartmentStatusDto CompartmentStatus(Compartment model) { var compartmentStatusDto = new CompartmentStatusDto(); Log.Information("[HCM][Compartment Status][Req]" + "[" + JsonSerializer.Serialize(model) + "]"); try { if (!PortsHealthCheck.IsLockPortAvailable && !PortsHealthCheck.IsDetectionPortAvailable) { return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { StatusCode = StatusCode.Status503ServiceUnavailable, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.BrokenComPort, ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.BrokenComPort)) })); } var(statusCode, errorResult) = LockerManagementValidator.PayloadValidator(LockerConfiguration, model.JwtCredentials.IsEnabled, model.JwtCredentials.Secret, model.JwtCredentials.Token, PayloadTypes.CompartmentStatus, model.LockerId, model.TransactionId, model.CompartmentIds, null); if (statusCode != StatusCode.Status200OK) { return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { StatusCode = statusCode, Error = errorResult })); } var result = CompartmentManager.CompartmentStatus(model, LockerConfiguration); compartmentStatusDto = CompartmentStatusMapper.ToObject(result); Log.Information("[HCM][Compartment Status][Res]" + "[" + JsonSerializer.Serialize(result) + "]"); } catch (Exception ex) { Log.Error("[HCM][Compartment Status]" + "[" + ex + "]"); return(CompartmentStatusMapper.ToError(new CompartmentStatusDto { StatusCode = StatusCode.Status500InternalServerError, Error = new Common.Exceptions.ApplicationException(ApplicationErrorCodes.InternalServerError, ex.Message) })); } return(compartmentStatusDto); }
public void CompartmentStatusValidLockerId() { var(statusCode, _) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.CompartmentStatus, lockerId, transactionId, validCompartmentIds, null); Assert.Equal(200, statusCode); }
public void CompartmentStatusInvalidLockerId() { var(_, errorResult) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.CompartmentStatus, "Hasan", transactionId, validCompartmentIds, null); Assert.Equal(ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.InvalidLockerId), errorResult.Message); }
public void OpenCompartmentEmptyCompartmentIds() { var(_, errorResult) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.OpenCompartment, lockerId, transactionId, null, null); Assert.Equal(ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.EmptyCompartmentId), errorResult.Message); }
public void CaptureImageEmptyTransactionId() { var(_, errorResult) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.CaptureImage, lockerId, string.Empty, null, captureType); Assert.Equal(ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.EmptyTransactionId), errorResult.Message); }
public void CaptureImageValidCaptureType() { var(statusCode, _) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.CaptureImage, lockerId, transactionId, null, captureType); Assert.Equal(200, statusCode); }
public void CaptureImageInvalidCaptureType() { var(_, errorResult) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.CaptureImage, lockerId, transactionId, null, "Hasan"); Assert.Equal(ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.InvalidCaptureType), errorResult.Message); }
public void LockerStatusEmptyLockerId() { var(_, errorResult) = LockerManagementValidator.PayloadValidator(lockerConfiguration, true, jwtSecret, token, PayloadTypes.LockerStatus, string.Empty, transactionId, null, null); Assert.Equal(ApplicationErrorCodes.GetMessage(ApplicationErrorCodes.EmptyLockerId), errorResult.Message); }