public static DbGetActorFilterRequest ToDbGetActorFilterRequest (this ActorListQuery from, int defaultLimit, int maxLimit) { if (from is null) { return(null); } return(new DbGetActorFilterRequest { Offset = Math.Max(from.Offset, 0), Limit = from.Limit == 0 ? defaultLimit : Math.Min(from.Limit, maxLimit), Archived = from.Archived, Contains = from.СontainsKeyWords, ActorRoleMask = from.ActorRoleMask }); }
public static Dictionary <string, object> ToDictionary (this ActorListQuery from) { if (from is null) { return(null); } return(new Dictionary <string, object> { { nameof(from.ActorRoleMask), from.ActorRoleMask }, { nameof(from.Archived), from.Archived }, { nameof(from.Limit), from.Limit }, { nameof(from.Offset), from.Offset }, { nameof(from.СontainsKeyWords), from.СontainsKeyWords }, { nameof(from.CurrentPrincipal), String.Join(',', from.CurrentPrincipal.ToDictionary() .Select(x => $"{x.Key}={x.Value}")) }, }); }
public async Task <ListResponse <Actor> > Handle(ActorListQuery request, CancellationToken cancellationToken) { Logger.LogInformation(AppLogEvent.HandleRequest, "Handle Get Actor List {request}", request.ToDictionary()); if (request is null) { Logger.LogWarning(AppLogEvent.HandleArgumentError, "Handle get task collection request with empty request"); return(ErrorResponse("Request empty argument")); } try { // Validate request var validator = new ActorListQueryValidator(); var validationResult = await validator.ValidateAsync(request) .ConfigureAwait(false); if (!validationResult.IsValid) { Logger.LogError("Query validation error. " + "Request = {request}. Error = {Error}", request.ToDictionary(), validationResult.Errors.Select(x => x.ErrorMessage)); return(ErrorResponse (validationResult.Errors.Select(x => x.ErrorMessage))); } // Get Actor for current user by user name var currentActorRequest = new DbGetActorByNameRequest (request.CurrentPrincipal?.Identity?.Name); var currentActorResponse = await Mediator .Send(currentActorRequest) .ConfigureAwait(false); Actor currentActor = null; if (currentActorResponse.Success) { currentActor = currentActorResponse.Entity; } else { Logger.LogWarning(AppLogEvent.HandleArgumentError, "Not found current actor"); return(ErrorResponse("Not found current actor")); } var defaultLimit = Configuration.GetValue (Defaults.ConfigurationApiDefaultLimitParameterName, Defaults.ConfigurationApiDefaultLimitDefaultValue); var maxLimit = Configuration.GetValue (Defaults.ConfigurationApiMaxLimitParameterName, Defaults.ConfigurationApiMaxLimitDefaultValue); var dbRequest = request.ToDbGetActorFilterRequest(defaultLimit, maxLimit); var dbResponse = await Mediator.Send(dbRequest) .ConfigureAwait(false); return(dbResponse); } catch (Exception e) { Logger.LogError(AppLogEvent.HandleErrorResponse, e, "Call repository exception"); return(ErrorResponse("Not found")); } }