public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] GetJobsByFilterRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("GetJobsByFilter started"); GetJobsByFilterResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetJobsByFilterResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (PostCodeException exc) { _logger.LogErrorAndNotifyNewRelic($"{req.Postcode} is an invalid postcode", exc); return(new ObjectResult(ResponseWrapper <GetJobsByFilterResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.ValidationError, "Invalid Postcode")) { StatusCode = StatusCodes.Status400BadRequest }); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in GetJobsByFilter", exc); return(new ObjectResult(ResponseWrapper <GetJobsByFilterResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] [RequestBodyType(typeof(GetRegistrationFormSupportActivitiesRequest), "get registration form support activities")] GetRegistrationFormSupportActivitiesRequest req, CancellationToken cancellationToken) { try { if (req.IsValid(out var validationResults)) { GetRegistrationFormSupportActivitiesResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetRegistrationFormSupportActivitiesResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response))); } else { return(new ObjectResult(ResponseWrapper <GetRegistrationFormSupportActivitiesResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults)) { StatusCode = 422 }); } } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetRegistrationFormSupportActivities", ex); return(new ObjectResult(ResponseWrapper <GetRegistrationFormSupportActivitiesResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] [RequestBodyType(typeof(PutGroupMemberCredentialsRequest), "Put Group Member Credentials")] PutGroupMemberCredentialsRequest req, CancellationToken cancellationToken) { try { bool response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (UnauthorisedException ex) { return(new ObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.UnauthorisedError, "Unauthorised Error")) { StatusCode = StatusCodes.Status401Unauthorized }); } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in PutGroupMemberCredentials", ex); return(new ObjectResult(ResponseWrapper <bool, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage reqAsHttpRequestMessage, CancellationToken cancellationToken) { try { NewRelic.Api.Agent.NewRelic.SetTransactionName("AddressService", "GetPostcodeCoordinates"); _logger.LogInformation("C# HTTP trigger function processed a request."); // accept compressed requests (can't do this with middleware) GetPostcodeCoordinatesRequest req = await HttpRequestMessageCompressionUtils.DeserialiseAsync <GetPostcodeCoordinatesRequest>(reqAsHttpRequestMessage); if (req.IsValid(out var validationResults)) { GetPostcodeCoordinatesResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response))); } else { return(new ObjectResult(ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.ValidationError, validationResults)) { StatusCode = 422 }); } } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetPostcodeCoordinates", ex); return(new ObjectResult(ResponseWrapper <GetPostcodeCoordinatesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public IActionResult Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("C# HTTP trigger function processed health check request."); return(new OkObjectResult("I'm alive!")); } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in HealthCheck", ex, req); return(new InternalServerErrorResult()); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] [RequestBodyType(typeof(GetNearbyPostcodesRequest), "get nearby postcodes")] GetNearbyPostcodesRequest req, CancellationToken cancellationToken) { try { NewRelic.Api.Agent.NewRelic.SetTransactionName("AddressService", "GetNearbyPostcodes"); _logger.LogInformation("C# HTTP trigger function processed a request."); // This validation logic belongs in a custom validation attribute on the Postcode property. However, validationContext.GetService<IExternalService> always returned null in the validation attribute (despite DI working fine elsewhere). I didn't want to spend a lot of time finding out why when there is lots to do so I've put the postcode validation logic here for now. if (!await _postcodeValidator.IsPostcodeValidAsync(req.Postcode)) { return(new ObjectResult(ResponseWrapper <GetNearbyPostcodesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.InvalidPostcode, "Invalid postcode")) { StatusCode = 422 }); } if (req.IsValid(out var validationResults)) { GetNearbyPostcodesResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetNearbyPostcodesResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response))); } else { return(new ObjectResult(ResponseWrapper <GetNearbyPostcodesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.ValidationError, validationResults)) { StatusCode = 422 }); } } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetNearbyPostcodes", ex, req); return(new ObjectResult(ResponseWrapper <GetNearbyPostcodesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] [RequestBodyType(typeof(GetGroupEmailConfigurationRequest), "get group email configuration")] GetGroupEmailConfigurationRequest req, CancellationToken cancellationToken) { try { GetGroupEmailConfigurationResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetGroupEmailConfigurationResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetGroupEmailConfiguration", ex); return(new ObjectResult(ResponseWrapper <GetGroupEmailConfigurationResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] [RequestBodyType(typeof(GetLocationsByDistanceRequest), "Get Locations By Distance")] GetLocationsByDistanceRequest req, CancellationToken cancellationToken) { try { GetLocationsByDistanceResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetLocationsByDistanceResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in GetLocationsByDistance", exc); return(new ObjectResult(ResponseWrapper <GetLocationsByDistanceResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] [RequestBodyType(typeof(GetJobsAllocatedToUserRequest), "get jobs allocated to user request")] GetJobsAllocatedToUserRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("GetJobsAllocatedToUser started"); GetJobsAllocatedToUserResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetJobsAllocatedToUserResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in GetJobsAllocatedToUser", exc); return(new ObjectResult(ResponseWrapper <GetJobsAllocatedToUserResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] [RequestBodyType(typeof(PutUpdateJobStatusToInProgressRequest), "put update job status to in progress request")] PutUpdateJobStatusToInProgressRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("PutUpdateJobStatusToInProgress started"); PutUpdateJobStatusToInProgressResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <PutUpdateJobStatusToInProgressResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in PutUpdateJobStatusToInProgress", exc); return(new ObjectResult(ResponseWrapper <PutUpdateJobStatusToInProgressResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] [RequestBodyType(typeof(GetDistanceBetweenPostcodesRequest), "Get Distance Between Postcodes")] GetDistanceBetweenPostcodesRequest req, CancellationToken cancellationToken) { try { var input = JsonConvert.SerializeObject(req); _logger.LogInformation(input); GetDistanceBetweenPostcodesResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetDistanceBetweenPostcodesResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in GetDistanceBetweenPostcodes", exc); _logger.LogError(exc.ToString(), exc); return(new ObjectResult(ResponseWrapper <GetDistanceBetweenPostcodesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] [RequestBodyType(typeof(GetPostcodesRequest), "Get Postcodes")] GetPostcodesRequest req, CancellationToken cancellationToken) { try { NewRelic.Api.Agent.NewRelic.SetTransactionName("AddressService", "GetPostcodes"); _logger.LogInformation("C# HTTP trigger function processed a request."); GetPostcodesResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <GetPostcodesResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception ex) { _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetPostcodes", ex, req); return(new ObjectResult(ResponseWrapper <GetPostcodesResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }