Пример #1
0
        public async Task <ActionResult <List <HttpTimeline> > > TimelineList([FromQuery][Username] string?relate, [FromQuery][ValidationSet("own", "join", "default")] string?relateType, [FromQuery] string?visibility)
        {
            List <TimelineVisibility>?visibilityFilter = null;

            if (visibility != null)
            {
                visibilityFilter = new List <TimelineVisibility>();
                var items = visibility.Split('|');
                foreach (var item in items)
                {
                    if (item.Equals(nameof(TimelineVisibility.Private), StringComparison.OrdinalIgnoreCase))
                    {
                        if (!visibilityFilter.Contains(TimelineVisibility.Private))
                        {
                            visibilityFilter.Add(TimelineVisibility.Private);
                        }
                    }
                    else if (item.Equals(nameof(TimelineVisibility.Register), StringComparison.OrdinalIgnoreCase))
                    {
                        if (!visibilityFilter.Contains(TimelineVisibility.Register))
                        {
                            visibilityFilter.Add(TimelineVisibility.Register);
                        }
                    }
                    else if (item.Equals(nameof(TimelineVisibility.Public), StringComparison.OrdinalIgnoreCase))
                    {
                        if (!visibilityFilter.Contains(TimelineVisibility.Public))
                        {
                            visibilityFilter.Add(TimelineVisibility.Public);
                        }
                    }
                    else
                    {
                        return(BadRequestWithCommonResponse(ErrorCodes.Common.InvalidModel, string.Format(Resource.MessageTimelineListQueryVisibilityUnknown, visibility)));
                    }
                }
            }

            TimelineUserRelationship?relationship = null;

            if (relate != null)
            {
                try
                {
                    var relatedUserId = await _userService.GetUserIdByUsernameAsync(relate);

                    var relationType = relateType is null ? TimelineUserRelationshipType.Default : Enum.Parse <TimelineUserRelationshipType>(relateType, true);

                    relationship = new TimelineUserRelationship(relationType, relatedUserId);
                }
                catch (EntityNotExistException)
                {
                    return(BadRequestWithCommonResponse(ErrorCodes.TimelineController.QueryRelateNotExist, Resource.MessageTimelineListQueryRelateNotExist));
                }
            }

            var timelines = await _service.GetTimelinesAsync(relationship, visibilityFilter);

            var result = await Map(timelines);

            return(result);
        }