Пример #1
0
 public Channel(ChannelCategory category, string name)
 {
     Category = category;
     Name = name;
     PartitionKey = SlugService.ToSlug(Category.ToString());
     RowKey = SlugService.ToSlug(Name);
 }
Пример #2
0
 public ProductService(MeredithDbContext meredithDbContext, SlugService slugService,
                       ICloudinaryService cloudinaryService)
 {
     _dbContext         = meredithDbContext;
     _slugService       = slugService;
     _cloudinaryService = cloudinaryService;
 }
Пример #3
0
        public void SlugLongTextTest()
        {
            string       input       = "LongTextInput4567892123456789312345678941234567895123456789612345678971234567898123456789912345678901";
            ISlugService slugService = new SlugService();
            string       result      = slugService.ConvertSlug(input);

            Assert.True(result.Length <= 100);
        }
Пример #4
0
        public void SymbolsText()
        {
            string       input       = "W@e#b$ --D(e)v-e=l+o;p:e?r ";
            string       expected    = "web-dev-eloper";
            ISlugService slugService = new SlugService();
            string       result      = slugService.ConvertSlug(input);

            Assert.Equal(expected, result);
        }
Пример #5
0
        public void ConvertBulgarianText()
        {
            string       input       = "Частна обява: Позиция - \"Продуктов мениджър\"";
            string       expected    = "chastna-obyava-poziciya-produktov-menidjur";
            ISlugService slugService = new SlugService();
            string       result      = slugService.ConvertSlug(input);

            Assert.Equal(expected, result);
        }
Пример #6
0
    public Result <UpdateProjectResponse> UpdateProject(Guid reference, UpdateProjectRequest request)
    {
        using var session     = _apiDatabase.SessionFactory().OpenSession();
        using var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);

        var project = session
                      .Query <ProjectRecord>()
                      .SingleOrDefault(x => x.Reference == reference);

        if (project == null)
        {
            return(Result <UpdateProjectResponse> .Failure($"Unable to find project with reference: {reference}."));
        }

        var urlSlugResult = SlugService.FromText(request.Title, request.UrlSlug);

        if (urlSlugResult.IsFailure)
        {
            return(Result <UpdateProjectResponse> .From(urlSlugResult));
        }

        project.Title           = request.Title;
        project.UrlSlug         = urlSlugResult.Value;
        project.StartedAt       = request.StartedAt;
        project.Summary         = request.Summary;
        project.Description     = request.Description;
        project.SourceCodeUrl   = request.SourceCodeUrl;
        project.PreviewImageUrl = request.PreviewImageUrl;
        project.DisplayOrder    = request.DisplayOrder;
        project.ViewUrl         = request.ViewUrl;
        project.Tags            = request.Tags;

        session.Update(project);

        transaction.Commit();

        return(Result <UpdateProjectResponse> .Of(new UpdateProjectResponse
        {
            Reference = project.Reference,
            Title = project.Title,
            UrlSlug = project.UrlSlug,
            StartedAt = project.StartedAt,
            Summary = project.Summary,
            Description = project.Description,
            SourceCodeUrl = project.SourceCodeUrl,
            PreviewImageUrl = project.PreviewImageUrl,
            DisplayOrder = project.DisplayOrder,
            CreatedAt = project.CreatedAt,
            ViewUrl = project.ViewUrl,
            Tags = project.Tags
        }));
    }
 public PayloadController(
     AppDbContext dbContext,
     ImageService imageService,
     BuildService buildService,
     BlueprintConverter blueprintConverter,
     SlugService slugService)
 {
     _dbContext          = dbContext;
     _imageService       = imageService;
     _buildService       = buildService;
     _blueprintConverter = blueprintConverter;
     _slugService        = slugService;
 }
Пример #8
0
    public Result <UpdateBlogPostResponse> UpdateBlogPost(Guid reference, UpdateBlogPostRequest request)
    {
        using var session     = _apiDatabase.SessionFactory().OpenSession();
        using var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);

        var blogPost = session
                       .Query <BlogPostRecord>()
                       .SingleOrDefault(x => x.Reference == reference);

        if (blogPost == null)
        {
            return(Result <UpdateBlogPostResponse> .Failure($"Unable to find blog post with reference: {reference}."));
        }

        var urlSlugResult = SlugService.FromText(request.Title, request.UrlSlug);

        if (urlSlugResult.IsFailure)
        {
            return(Result <UpdateBlogPostResponse> .From(urlSlugResult));
        }

        blogPost.Title   = request.Title;
        blogPost.Title   = request.Title;
        blogPost.UrlSlug = urlSlugResult.Value;
        blogPost.Summary = request.Summary;
        blogPost.Content = request.Content;

        session.Update(blogPost);

        transaction.Commit();

        return(Result <UpdateBlogPostResponse> .Of(new UpdateBlogPostResponse
        {
            Reference = blogPost.Reference,
            Title = blogPost.Title,
            UrlSlug = blogPost.UrlSlug,
            PostedAt = blogPost.PostedAt,
            Summary = blogPost.Summary,
            Content = blogPost.Content
        }));
    }
Пример #9
0
    public Result <CreateBlogPostResponse> CreateBlogPost(CreateBlogPostRequest request)
    {
        using var session     = _apiDatabase.SessionFactory().OpenSession();
        using var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);

        var urlSlugResult = SlugService.FromText(request.Title, request.UrlSlug);

        if (urlSlugResult.IsFailure)
        {
            return(Result <CreateBlogPostResponse> .From(urlSlugResult));
        }

        var blogPost = new BlogPostRecord
        {
            Reference = Guid.NewGuid(),
            Title     = request.Title,
            UrlSlug   = urlSlugResult.Value,
            PostedAt  = DateTime.UtcNow,
            Summary   = request.Summary,
            Content   = request.Content
        };

        session.Save(blogPost);

        transaction.Commit();

        return(Result <CreateBlogPostResponse> .Of(new CreateBlogPostResponse
        {
            Reference = blogPost.Reference,
            Title = blogPost.Title,
            UrlSlug = blogPost.UrlSlug,
            PostedAt = blogPost.PostedAt,
            Summary = blogPost.Summary,
            Content = blogPost.Content
        }));
    }
 public static string ToPartitionKey(string userId)
 {
     return(SlugService.ToSlug(userId));
 }
 public RpcController(SlugService slugService)
 {
     _slugService = slugService;
 }
Пример #12
0
 public SlugServiceTests()
 {
     _slugService = new SlugService();
 }
Пример #13
0
 public TenantService(MeredithDbContext dbContext, SlugService slugService, IUserService userService)
 {
     _dbContext   = dbContext;
     _slugService = slugService;
     _userService = userService;
 }
Пример #14
0
 public void Setup()
 {
     _result = SlugService.FromText(_before);
 }
        public ICollection <ItemContract> Latest(string userId)
        {
            var itemsResult   = new List <ItemContract>();
            var subscriptions = TableService.ByPartitionKey <Subscription>(Subscription.ToPartitionKey(userId), Subscription.TableName, 999);

            foreach (var subscription in subscriptions)
            {
                var filters = subscription.FilterList;

                var channelQuery = new TableQuery <Item>
                {
                    FilterString = TableQuery.CombineFilters(
                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, SlugService.ToSlug(subscription.ChannelPartitionKey + subscription.ChannelRowKey)),
                        TableOperators.And,
                        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, DateTime.UtcNow.AddDays(-14).ToString("u")))
                };

                itemsResult.AddRange((from item in TableService.Query <Item>(Item.TableName, channelQuery)
                                      select new ItemContract
                {
                    Title = item.Title,
                    Link = item.Link,
                    Description = item.Description,
                    PublishedDateRFC822 = item.PublishedDateRFC822,
                    PublishedDate = item.GetPublishedDateTime()
                }).Where(
                                         item => filters == null || filters.Count == 0 || filters.Any(filter => item.Description.Contains(filter) || item.Title.Contains(filter)))
                                     .Take(MaxRows)
                                     .ToList());
            }

            return(itemsResult);
        }
Пример #16
0
    public Result <CreateProjectResponse> CreateProject(CreateProjectRequest request)
    {
        using var session     = _apiDatabase.SessionFactory().OpenSession();
        using var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);

        var urlSlug = SlugService.FromText(request.Title, request.UrlSlug);

        if (urlSlug.IsFailure)
        {
            return(Result <CreateProjectResponse> .From(urlSlug));
        }

        var project = new ProjectRecord
        {
            Reference       = Guid.NewGuid(),
            Title           = request.Title,
            UrlSlug         = urlSlug.Value,
            StartedAt       = request.StartedAt,
            Summary         = request.Summary,
            Description     = request.Description,
            SourceCodeUrl   = request.SourceCodeUrl,
            PreviewImageUrl = request.PreviewImageUrl,
            DisplayOrder    = request.DisplayOrder,
            CreatedAt       = DateTime.UtcNow,
            ViewUrl         = request.ViewUrl,
            Tags            = request.Tags
        };

        session.Save(project);

        transaction.Commit();

        var settingsResult = _projectsSettingsService.GetProjectsSettings();

        if (settingsResult.IsFailure)
        {
            return(Result <CreateProjectResponse> .From(settingsResult));
        }

        _projectsSettingsService.UpdateProjectsSettings(new UpdateProjectsSettingsRequest
        {
            DisplayOrder = settingsResult.Value.DisplayOrder
                           .Select(x => x.Reference)
                           .Concat(new [] { project.Reference })
                           .ToList()
        });

        return(Result <CreateProjectResponse> .Of(new CreateProjectResponse
        {
            Reference = project.Reference,
            Title = project.Title,
            UrlSlug = project.UrlSlug,
            StartedAt = project.StartedAt,
            Summary = project.Summary,
            Description = project.Description,
            SourceCodeUrl = project.SourceCodeUrl,
            PreviewImageUrl = project.PreviewImageUrl,
            DisplayOrder = project.DisplayOrder,
            CreatedAt = project.CreatedAt,
            ViewUrl = project.ViewUrl,
            Tags = project.Tags
        }));
    }
Пример #17
0
 public Item(string channelPartitionKey, string channelRowKey)
 {
     PartitionKey = SlugService.ToSlug(channelPartitionKey + channelRowKey);
     RowKey       = DateTime.UtcNow.ToString("u") + "|" + Guid.NewGuid();
 }
Пример #18
0
 static SlugBenchmark()
 {
     _slugService = new SlugService();
 }