Skip to content

V14/feature/all segment endpoint#16054

Merged
Zeegaan merged 4 commits into
v14/devfrom
v14/feature/all-segment-endpoint
Apr 18, 2024
Merged

V14/feature/all segment endpoint#16054
Zeegaan merged 4 commits into
v14/devfrom
v14/feature/all-segment-endpoint

Conversation

@Migaroez

@Migaroez Migaroez commented Apr 15, 2024

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Description

This PR adds the contractual stable endpoint to retrieve all "defined" (content) segments. Since Umbraco has no way (yet?) to define segments out of the box, we supply a noop implementation of the service behind the endpoint to just return an empty paged list.

Testing

Consider basic Get endpoint testing including authorization with settings section
You can use the following code to quickly override the service to return something.

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;

namespace Umbraco.Cms.Web.UI;

public class SegmentService : ISegmentService
{
    private static readonly Segment[] segments = new Segment[] {
        new Segment
        {
            Alias = "segment-one",
            Name = "First Segment"
        },
        new Segment
        {
            Alias = "segment-two",
            Name = "Second Segment"
        },
        new Segment
        {
            Alias = "segment-three",
            Name = "Thrird Segment"
        },
    };

    public async Task<Attempt<PagedModel<Segment>?, SegmentOperationStatus>> GetPagedSegmentsAsync(int skip = 0, int take = 100)
    {
        return await Task.FromResult(Attempt.SucceedWithStatus<PagedModel<Segment>?, SegmentOperationStatus>(
            SegmentOperationStatus.Success,
            new PagedModel<Segment> { Total = segments.Length, Items = segments.Skip(0).Take(take) }));
    }
}

public class SegmentServiceOverrideComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder) => builder.Services.AddUnique<ISegmentService, SegmentService>();
}

@Migaroez Migaroez changed the base branch from contrib to v14/dev April 16, 2024 06:58
@Migaroez Migaroez marked this pull request as ready for review April 16, 2024 07:03

@Zeegaan Zeegaan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and tests good, found 2 small things 😁

Comment thread src/Umbraco.Cms.Api.Management/ViewModels/Segment/SegmentResponseModel.cs Outdated
Comment thread src/Umbraco.Cms.Api.Management/Controllers/Segment/AllSegmentController.cs Outdated
Migaroez and others added 2 commits April 18, 2024 10:49
Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
@Zeegaan Zeegaan merged commit d04769a into v14/dev Apr 18, 2024
@Zeegaan Zeegaan deleted the v14/feature/all-segment-endpoint branch April 18, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants