Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

1.5 KB
Raw Blame
using System.Collections.Generic;
using API.Entities;
using API.Entities.Enums;
using API.Extensions;

namespace API.Helpers.Builders;

public class ReadingListBuilder : IEntityBuilder<ReadingList>
{
    private readonly ReadingList _readingList;
    public ReadingList Build() => _readingList;

    public ReadingListBuilder(string title)
    {
        title = title.Trim();
        _readingList = new ReadingList()
        {
            Title = title,
            NormalizedTitle = title.ToNormalized(),
            Summary = string.Empty,
            Promoted = false,
            Items = new List<ReadingListItem>(),
            AgeRating = AgeRating.Unknown
        };
    }

    public ReadingListBuilder WithSummary(string summary)
    {
        _readingList.Summary = summary ?? string.Empty;
        return this;
    }

    public ReadingListBuilder WithItem(ReadingListItem item)
    {
        _readingList.Items ??= new List<ReadingListItem>();
        _readingList.Items.Add(item);
        return this;
    }

    public ReadingListBuilder WithRating(AgeRating rating)
    {
        _readingList.AgeRating = rating;
        return this;
    }

    public ReadingListBuilder WithPromoted(bool promoted)
    {
        _readingList.Promoted = promoted;
        return this;
    }

    public ReadingListBuilder WithCoverImage(string coverImage)
    {
        _readingList.CoverImage = coverImage;
        return this;
    }

    public ReadingListBuilder WithAppUserId(int userId)
    {
        _readingList.AppUserId = userId;
        return this;
    }
}