/// <summary> /// get (the) touchpoint id from (the) Postcode /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using (the logging) scope</param> /// <returns>the LAD code</returns> public async Task <string> GetTouchpointIDFromPostcode(string theCandidate, IScopeLoggingContext usingScope) { await usingScope.EnterMethod(); await usingScope.Information($"seeking postcode '{theCandidate}'"); var result = await Postcode.LookupAsync(theCandidate); It.IsNull(result) .AsGuard <InvalidPostcodeException>(theCandidate); It.IsEmpty(result.Postcode) .AsGuard <InvalidPostcodeException>(theCandidate); await usingScope.Information($"found postcode for '{result.Postcode}'"); await usingScope.Information($"seeking local authority '{result.Codes.AdminDistrict}'"); var authority = await Authority.Get(result.Codes.AdminDistrict); await usingScope.Information($"found local authority '{authority.LADCode}'"); await usingScope.ExitMethod(); return(authority.TouchpointID); }
/// <summary> /// inform on... /// </summary> /// <param name="theException">the exception</param> /// <param name="useLoggingScope">using (the) logging scope</param> /// <returns>the currently running task</returns> internal async Task InformOn(Exception theException, IScopeLoggingContext useLoggingScope) { await useLoggingScope.Information(theException.Message); if (It.Has(theException.InnerException)) { await InformOn(theException.InnerException, useLoggingScope); } }
/// <summary> /// do request... /// </summary> /// <param name="theRequest">the request</param> /// <param name="inScope">in scope</param> /// <returns>the http message response</returns> public async Task <HttpResponseMessage> DoRequest(HttpRequest theRequest, IScopeLoggingContext inScope) { var hasSelector = theRequest.Query.ContainsKey(LocationKey); var theLocation = theRequest.Query[LocationKey]; return(hasSelector ? await Adapter.GetAreaRoutingDetailBy(theLocation, inScope) : await Adapter.GetAllRouteIDs(inScope)); }
/// <summary> /// this is the default unknown candidate type action /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using scope</param> /// <param name="forExpression">for (the) expression</param> /// <returns>nothing, this should throw</returns> public async Task <string> UnknownCandidateTypeAction(string theCandidate, IScopeLoggingContext usingScope) { await usingScope.EnterMethod(); await usingScope.Information($"malformed request candidate: '{theCandidate}'"); await usingScope.ExitMethod(); throw new MalformedRequestException(theCandidate); }
/// <summary> /// process, add new authority for... /// submission choices... /// {"LADCode": "E00060060", "Name": "Widdicombe Sands" } /// {"TouchpointID":"0000000102", "LADCode": "E00060060", "Name": "Widdicombe Sands" } /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="usingContent">using content</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> ProcessAddNewAuthorityFor( string theTouchpoint, string usingContent, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); It.IsEmpty(usingContent) .AsGuard <ArgumentNullException>(nameof(usingContent)); await inScope.Information($"deserialising the submitted content: '{usingContent}'"); var theCandidate = JsonConvert.DeserializeObject <IncomingLocalAuthority>(usingContent); It.IsNull(theCandidate) .AsGuard <MalformedRequestException>(nameof(ILocalAuthority.LADCode)); await inScope.Information("deserialisation complete..."); if (It.IsEmpty(theCandidate.TouchpointID)) { await inScope.Information($"applying missing touchpoint details: '{theTouchpoint}'"); theCandidate.TouchpointID = theTouchpoint; } await inScope.Information($"validating the candidate: '{theCandidate.LADCode}'"); await Authority.Validate(theCandidate); await inScope.Information($"validation complete..."); await inScope.Information($"adding the candidate: '{theCandidate.LADCode}'"); var result = await Authorities.Add(theCandidate); await inScope.Information($"candidate addition complete..."); await inScope.Information($"preparing response..."); var response = Respond.Created().SetContent(result); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// process, delete (the) local authority for... /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="theLADCode">the local adinistrative district code</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> ProcessDeleteAuthorityFor( string theTouchpoint, string theLADCode, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theTouchpoint) .AsGuard <ArgumentNullException>(nameof(theTouchpoint)); It.IsEmpty(theLADCode) .AsGuard <ArgumentNullException>(nameof(theLADCode)); await inScope.Information($"seeking the admin district: '{theLADCode}'"); var result = await Authorities.Get(theLADCode); It.IsNull(result) .AsGuard <NoContentException>(); await inScope.Information($"candidate search complete: '{result.LADCode}'"); await inScope.Information($"validating touchpoint integrity: '{result.TouchpointID}' == '{theTouchpoint}'"); (result.TouchpointID != theTouchpoint) .AsGuard <NoContentException>(NoContentException.GetMessage(theTouchpoint)); await inScope.Information($"deleting authority: '{result.Name}'"); await Authorities.Delete(theLADCode); await inScope.Information($"preparing response..."); var response = Respond.Ok(); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// process, add new area routing detail /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="usingContent">using content</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> ProcessAddAreaRoutingDetailUsing( string theContent, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theContent) .AsGuard <MalformedRequestException>(); await inScope.Information($"deserialising the submitted content: '{theContent}'"); var theCandidate = JsonConvert.DeserializeObject <IncomingRoutingDetail>(theContent); await inScope.Information("deserialisation complete..."); It.IsNull(theCandidate) .AsGuard <MalformedRequestException>(); await inScope.Information($"validating the candidate: '{theCandidate.TouchpointID}'"); await RoutingDetail.Validate(theCandidate); await inScope.Information($"validation complete..."); await inScope.Information($"adding the candidate: '{theCandidate.TouchpointID}'"); var result = await RoutingDetails.Add(theCandidate); await inScope.Information($"candidate addition complete..."); await inScope.Information($"preparing response..."); var response = Respond.Created().SetContent(result); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// process, get all route id's /// </summary> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success only)</returns> internal async Task <HttpResponseMessage> ProcessGetAllRouteIDs(IScopeLoggingContext inScope) { await inScope.EnterMethod(); await inScope.Information("seeking all routing ids"); var result = await RoutingDetails.GetAllIDs(); await inScope.Information($"found {result.Count} record(s)..."); var theCandidate = $"{{ [{string.Join(", ", result.Select(x => $"\"{x}\""))}] }}"; await inScope.Information($"candidate content: '{theCandidate}'"); await inScope.Information($"preparing response..."); var response = Respond.Ok().SetContent(theCandidate); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// add new authority using... /// </summary> /// <param name="theRequest">the request</param> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="inScope">in (logging) scope</param> /// <returns></returns> internal async Task <HttpResponseMessage> AddNewAuthorityUsing(HttpRequest theRequest, string theTouchpoint, IScopeLoggingContext inScope) { var theContent = await theRequest.ReadAsStringAsync(); return(await Adapter.AddNewAuthorityFor(theTouchpoint, theContent, inScope)); }
/// <summary> /// add area routing detail using... /// </summary> /// <param name="theRequest">the request</param> /// <param name="inScope">in scope</param> /// <returns>the resulting message</returns> public async Task <HttpResponseMessage> AddAreaRoutingDetailUsing(HttpRequest theRequest, IScopeLoggingContext inScope) { var theContent = await theRequest.ReadAsStringAsync(); return(await Adapter.AddAreaRoutingDetailUsing(theContent, inScope)); }
/// <summary> /// get (the) response for... /// </summary> /// <param name="theException">the exception</param> /// <param name="useLoggingScope">use (the) logging scope</param> /// <returns>the currently running task containing the http response message</returns> public async Task <HttpResponseMessage> GetResponseFor(Exception theException, IScopeLoggingContext useLoggingScope) { if (_faultMap.ContainsKey(theException.GetType())) { await InformOn(theException, useLoggingScope); return(_faultMap[theException.GetType()].Invoke(theException)); } await useLoggingScope.ExceptionDetail(theException); return(UnknownError(theException)); }
/// <summary> /// process, get (the) area routing detail for... /// </summary> /// <param name="theTouchpointID">the touchpoint id</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success only)</returns> internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailFor(string theTouchpointID, IScopeLoggingContext inScope) { await inScope.EnterMethod(); It.IsEmpty(theTouchpointID) .AsGuard <MalformedRequestException>(); await inScope.Information($"seeking the routing details: '{theTouchpointID}'"); var theDetail = await RoutingDetails.Get(theTouchpointID); It.IsNull(theDetail) .AsGuard <MalformedRequestException>(theTouchpointID); await inScope.Information($"candidate search complete: '{theDetail.TouchpointID}'"); await inScope.Information($"preparing response..."); var response = Respond.Ok().SetContent(theDetail); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// get (the) local authority for... /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="theLADCode">the local adinistrative district code</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> GetAuthorityFor(string theTouchpoint, string theLADCode, IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessGetAuthorityFor(theTouchpoint, theLADCode, inScope), x => Faults.GetResponseFor(x, inScope));
/// <summary> /// get (the) touchpoint id using the outward code /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using (the logging) scope</param> /// <returns>the LAD code</returns> public async Task <string> GetTouchpointIDFromOutwardCode(string theCandidate, IScopeLoggingContext usingScope) { await usingScope.EnterMethod(); It.IsEmpty(theCandidate) .AsGuard <ArgumentNullException>(nameof(theCandidate)); await usingScope.Information($"seeking postcode via outward code: '{theCandidate}'"); var result = await Postcode.LookupOutwardCodeAsync(theCandidate); It.IsEmpty(result) .AsGuard <NoContentException>(); await usingScope.ExitMethod(); return(await GetTouchpointIDFromPostcode(result.FirstOrDefault(), usingScope)); }
/// <summary> /// get (the) area routing detail by... /// excluded from coverage as moq doesn't support the lambda complexity for this routine /// </summary> /// <param name="theLocation">the location</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> public async Task <HttpResponseMessage> GetAreaRoutingDetailBy(string theLocation, IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessGetAreaRoutingDetailBy(theLocation, inScope), x => Faults.GetResponseFor(x, TypeOfFunction.GetByLocation, inScope));
/// <summary> /// delete an area routing detail using... /// </summary> /// <param name="theTouchpoint">the touchpoint (id)</param> /// <param name="inScope">in scope</param> /// <returns></returns> public async Task <HttpResponseMessage> DeleteAreaRoutingDetailUsing(string theTouchpoint, IScopeLoggingContext inScope) => await Adapter.DeleteAreaRoutingDetailUsing(theTouchpoint, inScope);
/// <summary> /// process, get (the) area routing detail by... /// </summary> /// <param name="theLocation">the location</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> internal async Task <HttpResponseMessage> ProcessGetAreaRoutingDetailBy(string theLocation, IScopeLoggingContext inScope) { await inScope.EnterMethod(); theLocation = theLocation?.Trim(); It.IsEmpty(theLocation) .AsGuard <MalformedRequestException>(); await inScope.Information($"seeking the routing details for: '{theLocation}'"); await inScope.Information($"analysing the expression type..."); var theExpressionType = Analyser.GetTypeOfExpressionFor(theLocation); await inScope.Information($"seeking the action for expression type: '{theExpressionType}'"); var actionDo = Actions.GetActionFor(theExpressionType); await inScope.Information($"action for expression type: '{actionDo.Method.Name}'"); var theTouchpoint = await actionDo(theLocation, inScope); await inScope.Information($"action execution complete..."); await inScope.ExitMethod(); return(await ProcessGetAreaRoutingDetailFor(theTouchpoint, inScope)); }
/// <summary> /// delete authority for... /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="theLADCode">the local authority district code</param> /// <param name="inScope">in (logging) scope</param> /// <returns></returns> internal async Task <HttpResponseMessage> DeleteAuthorityFor(string theTouchpoint, string theLADCode, IScopeLoggingContext inScope) => await Adapter.DeleteAuthorityFor(theTouchpoint, theLADCode, inScope);
/// <summary> /// get all route id's /// </summary> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> public async Task <HttpResponseMessage> GetAllRouteIDs(IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessGetAllRouteIDs(inScope), x => Faults.GetResponseFor(x, TypeOfFunction.GetAll, inScope));
/// <summary> /// add new area routing detail /// excluded from coverage as moq doesn't support the lambda complexity for this routine /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="usingContent">using content</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> AddAreaRoutingDetailUsing(string theContent, IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessAddAreaRoutingDetailUsing(theContent, inScope), x => Faults.GetResponseFor(x, TypeOfFunction.Post, inScope));
/// <summary> /// get (the) response for... /// </summary> /// <param name="theException">the exception</param> /// <param name="theMethod">the type of method</param> /// <param name="useLoggingScope">use (the) logging scope</param> /// <returns>the currently running task containing the http response message</returns> public async Task <HttpResponseMessage> GetResponseFor(Exception theException, TypeOfFunction theMethod, IScopeLoggingContext useLoggingScope) { var exceptionType = theException.GetType(); if (_methodMap[theMethod].ContainsKey(exceptionType)) { await InformOn(theException, useLoggingScope); return(_methodMap[theMethod][exceptionType].Invoke(theException)); } await useLoggingScope.ExceptionDetail(theException); return(_methodMap[theMethod][typeof(FallbackActionException)].Invoke(theException)); }
/// <summary> /// delete an area routing detail using... /// </summary> /// <param name="theTouchpointID">the touchpoint id</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> public async Task <HttpResponseMessage> DeleteAreaRoutingDetailUsing(string theTouchpointID, IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessDeleteAreaRoutingDetailUsing(theTouchpointID, inScope), x => Faults.GetResponseFor(x, TypeOfFunction.Delete, inScope));
/// <summary> /// process, delete an area routing detail using... /// </summary> /// <param name="theTouchpointID">the touchpoint id</param> /// <param name="inScope">in logging scope</param> /// <returns>the currently running task containing the response message (success or fail)</returns> internal async Task <HttpResponseMessage> ProcessDeleteAreaRoutingDetailUsing(string theTouchpointID, IScopeLoggingContext inScope) { await inScope.EnterMethod(); await inScope.Information($"deleting the routing details for '{theTouchpointID}'"); await RoutingDetails.Delete(theTouchpointID); await inScope.Information($"preparing response..."); var response = Respond.Ok(); await inScope.Information($"preparation complete..."); await inScope.ExitMethod(); return(response); }
/// <summary> /// add new authority for... /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="usingContent">using content</param> /// <param name="inScope">in scope</param> /// <returns>the result of the operation</returns> public async Task <HttpResponseMessage> AddNewAuthorityFor(string theTouchpoint, string usingContent, IScopeLoggingContext inScope) => await SafeOperations.Try(() => ProcessAddNewAuthorityFor(theTouchpoint, usingContent, inScope), x => Faults.GetResponseFor(x, inScope));
/// <summary> /// get area routing detail for... /// </summary> /// <param name="theTouchpoint">the touchpoint</param> /// <param name="inScope">in scope</param> /// <returns>a message result</returns> public async Task <HttpResponseMessage> GetAreaRoutingDetailFor(string theTouchpoint, IScopeLoggingContext inScope) => await Adapter.GetAreaRoutingDetailFor(theTouchpoint, inScope);
/// <summary> /// get (the) touchpoint id from (the) town /// </summary> /// <param name="theCandidate">the candidate</param> /// <param name="usingScope">using (the logging) scope</param> /// <returns>the LAD code</returns> public async Task <string> GetTouchpointIDFromTown(string theCandidate, IScopeLoggingContext usingScope) { await Task.CompletedTask; throw new NotSupportedException("GetTouchpointIDFromTown: this operation has not yet been coded"); }