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 project 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 project 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());
                }
        }
Exemplo n.º 2
0
        public static Dictionary <string, object> ToDictionary
            (this _ApiEntityListQueryType from)
        {
            if (from is null)
            {
                return(null);
            }

            return(new Dictionary <string, object>
            {
                { nameof(from.Archived), from.Archived },
                { nameof(from.Limit), from.Limit },
                { nameof(from.Offset), from.Offset },
                { nameof(from.ContainsKeyWords), from.ContainsKeyWords }
            });
        }
Exemplo n.º 3
0
        public static _EntityListQueryType ToListQuery <TEntity>
            (this _ApiEntityListQueryType from,
            ClaimsPrincipal currentPrincipal)
            where TEntity : _EntityType
        {
            if (from is null)
            {
                return(null);
            }

            var result = new _EntityListQueryType
            {
                Archived         = from.Archived,
                CurrentPrincipal = currentPrincipal,
                Limit            = from.Limit,
                Offset           = from.Offset,
                СontainsKeyWords = from.ContainsKeyWords
            };

            return(result);
        }