You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.1 KiB
125 lines
4.1 KiB
7 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
5 years ago
|
using Newtonsoft.Json;
|
||
5 years ago
|
using NzbDrone.Core.Books;
|
||
7 years ago
|
using NzbDrone.Core.MediaCover;
|
||
5 years ago
|
using Readarr.Api.V1.Author;
|
||
|
using Readarr.Api.V1.BookFiles;
|
||
5 years ago
|
using Readarr.Http.REST;
|
||
7 years ago
|
|
||
5 years ago
|
namespace Readarr.Api.V1.Books
|
||
7 years ago
|
{
|
||
5 years ago
|
public class BookResource : RestResource
|
||
7 years ago
|
{
|
||
|
public string Title { get; set; }
|
||
6 years ago
|
public string Disambiguation { get; set; }
|
||
6 years ago
|
public string Overview { get; set; }
|
||
5 years ago
|
public string Publisher { get; set; }
|
||
|
public string Language { get; set; }
|
||
|
public int AuthorId { get; set; }
|
||
|
public string ForeignBookId { get; set; }
|
||
|
public int GoodreadsId { get; set; }
|
||
|
public string TitleSlug { get; set; }
|
||
|
public string Isbn { get; set; }
|
||
|
public string Asin { get; set; }
|
||
7 years ago
|
public bool Monitored { get; set; }
|
||
|
public Ratings Ratings { get; set; }
|
||
|
public DateTime? ReleaseDate { get; set; }
|
||
|
public List<string> Genres { get; set; }
|
||
5 years ago
|
public AuthorResource Author { get; set; }
|
||
7 years ago
|
public List<MediaCover> Images { get; set; }
|
||
6 years ago
|
public List<Links> Links { get; set; }
|
||
5 years ago
|
public BookStatisticsResource Statistics { get; set; }
|
||
5 years ago
|
public AddBookOptions AddOptions { get; set; }
|
||
7 years ago
|
public string RemoteCover { get; set; }
|
||
|
|
||
7 years ago
|
//Hiding this so people don't think its usable (only used to set the initial state)
|
||
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||
|
public bool Grabbed { get; set; }
|
||
|
}
|
||
|
|
||
5 years ago
|
public static class BookResourceMapper
|
||
7 years ago
|
{
|
||
5 years ago
|
public static BookResource ToResource(this Book model)
|
||
7 years ago
|
{
|
||
5 years ago
|
if (model == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
return new BookResource
|
||
7 years ago
|
{
|
||
|
Id = model.Id,
|
||
5 years ago
|
AuthorId = model.AuthorId,
|
||
|
ForeignBookId = model.ForeignBookId,
|
||
|
GoodreadsId = model.GoodreadsId,
|
||
|
TitleSlug = model.TitleSlug,
|
||
|
Asin = model.Asin,
|
||
|
Isbn = model.Isbn13,
|
||
7 years ago
|
Monitored = model.Monitored,
|
||
|
ReleaseDate = model.ReleaseDate,
|
||
|
Genres = model.Genres,
|
||
|
Title = model.Title,
|
||
6 years ago
|
Disambiguation = model.Disambiguation,
|
||
6 years ago
|
Overview = model.Overview,
|
||
5 years ago
|
Publisher = model.Publisher,
|
||
|
Language = model.Language,
|
||
7 years ago
|
Images = model.Images,
|
||
6 years ago
|
Links = model.Links,
|
||
7 years ago
|
Ratings = model.Ratings,
|
||
5 years ago
|
Author = model.Author?.Value.ToResource()
|
||
7 years ago
|
};
|
||
|
}
|
||
|
|
||
5 years ago
|
public static Book ToModel(this BookResource resource)
|
||
7 years ago
|
{
|
||
5 years ago
|
if (resource == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
var author = resource.Author?.ToModel() ?? new NzbDrone.Core.Books.Author();
|
||
5 years ago
|
|
||
5 years ago
|
return new Book
|
||
7 years ago
|
{
|
||
|
Id = resource.Id,
|
||
5 years ago
|
ForeignBookId = resource.ForeignBookId,
|
||
|
GoodreadsId = resource.GoodreadsId,
|
||
|
TitleSlug = resource.TitleSlug,
|
||
|
Asin = resource.Asin,
|
||
|
Isbn13 = resource.Isbn,
|
||
7 years ago
|
Title = resource.Title,
|
||
6 years ago
|
Disambiguation = resource.Disambiguation,
|
||
6 years ago
|
Overview = resource.Overview,
|
||
5 years ago
|
Publisher = resource.Publisher,
|
||
|
Language = resource.Language,
|
||
7 years ago
|
Images = resource.Images,
|
||
|
Monitored = resource.Monitored,
|
||
5 years ago
|
AddOptions = resource.AddOptions,
|
||
5 years ago
|
Author = author,
|
||
|
AuthorMetadata = author.Metadata.Value
|
||
7 years ago
|
};
|
||
|
}
|
||
|
|
||
5 years ago
|
public static Book ToModel(this BookResource resource, Book book)
|
||
7 years ago
|
{
|
||
5 years ago
|
var updatedBook = resource.ToModel();
|
||
7 years ago
|
|
||
5 years ago
|
book.ApplyChanges(updatedBook);
|
||
7 years ago
|
|
||
5 years ago
|
return book;
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
public static List<BookResource> ToResource(this IEnumerable<Book> models)
|
||
7 years ago
|
{
|
||
7 years ago
|
return models?.Select(ToResource).ToList();
|
||
|
}
|
||
7 years ago
|
|
||
5 years ago
|
public static List<Book> ToModel(this IEnumerable<BookResource> resources)
|
||
7 years ago
|
{
|
||
|
return resources.Select(ToModel).ToList();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|