Esempio n. 1
0
        public async Task <IActionResult> Get
            ([FromQuery] _ApiListQueryType request)
        {
            try
            {
                var currentPrincipal = HttpContext.User;
                var currentUserName  = currentPrincipal?.Identity?.Name;
                using var logScope = Logger.BeginScope("{User}",
                                                       currentUserName);
                Logger.LogInformation(ApiLogEvent.ApiRequest,
                                      "Get geo list {Request}",
                                      request.ToDictionary());

                var query  = request.ToListQuery <_EntityType>(currentPrincipal);
                var result = await Mediator.Send(query);

                if (result is null || !result.Success)
                {
                    Logger.LogWarning(ApiLogEvent.ApiErrorResponse,
                                      "Get geo list error response. Error={Error}.",
                                      result?.Errors);
                    return(BadRequest());
                }
                return(Ok(result.ToEntityList <_ApiEntityType>()));
            }
            catch (Exception ex)
                when(Logger.WriteScopeWhenException
                         (ApiLogEvent.ApiErrorResponse, ex))
                {
                    return(BadRequest());
                }
        }
 public static Dictionary <string, object> ToDictionary
     (this _ApiEntityListQueryType from)
 => from is null
         ? null
         : new Dictionary <string, object>
 {
     { nameof(from.Archived), from.Archived },
     { nameof(from.Limit), from.Limit },
     { nameof(from.Offset), from.Offset },
     { nameof(from.ContainsKeyWords), from.ContainsKeyWords },
     { nameof(from.ProjectId), from.ProjectId },
     { nameof(from.DistanceLong), from.DistanceLong },
     { nameof(from.CenterLat), from.CenterLat },
     { nameof(from.CenterLong), from.CenterLong },
     { nameof(from.DistanceLat), from.DistanceLat },
 };
 public static _EntityListQueryType ToListQuery <TEntity>
     (this _ApiEntityListQueryType from,
     ClaimsPrincipal currentPrincipal)
     where TEntity : _EntityType
 => from is null
         ? null
 : new _EntityListQueryType
 {
     Archived         = from.Archived,
     CurrentPrincipal = currentPrincipal,
     ProjectId        = from.ProjectId,
     Limit            = from.Limit,
     Offset           = from.Offset,
     СontainsKeyWords = from.ContainsKeyWords,
     DistanceLong     = from.DistanceLong,
     CenterLat        = from.CenterLat,
     CenterLong       = from.CenterLong,
     DistanceLat      = from.DistanceLat,
 };