snyggade till hardcover. la til author lookup
This commit is contained in:
154
Server/Business/Clients/HardcoverClient.cs
Normal file
154
Server/Business/Clients/HardcoverClient.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using GraphQL;
|
||||
using GraphQL.Client.Abstractions;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
|
||||
namespace Bibblan.Business.Clients
|
||||
{
|
||||
public class Publisher
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public class Image
|
||||
{
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public class Author
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name_Personal { get; set; }
|
||||
public Image Image { get; set; }
|
||||
public string Bio { get; set; }
|
||||
public int Book_Count { get; set; }
|
||||
public DateTime? Born_Date { get; set; }
|
||||
public DateTime? Death_Date { get; set; }
|
||||
public int? Gender_Id{ get; set; }
|
||||
public Dictionary<string, List<string>> Identifiers { get; set; }
|
||||
public string State { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class Contributor
|
||||
{
|
||||
public Author Author { get; set; }
|
||||
}
|
||||
|
||||
public class Edition
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Edition_Format { get; set; }
|
||||
public int? Pages { get; set; }
|
||||
public DateTime? Release_Date { get; set; }
|
||||
public string Isbn_10 { get; set; }
|
||||
public string Isbn_13 { get; set; }
|
||||
public Publisher Publisher { get; set; }
|
||||
public List<Contributor> Contributions { get; set; }
|
||||
public Image Image { get; set; }
|
||||
}
|
||||
|
||||
public class EditionsCollectionType
|
||||
{
|
||||
public List<Edition> Editions { get; set; }
|
||||
}
|
||||
|
||||
public class AuthorsCollectionType
|
||||
{
|
||||
public List<Author> Authors { get; set; }
|
||||
}
|
||||
|
||||
public class HardcoverClient
|
||||
{
|
||||
private readonly IGraphQLClient _client;
|
||||
public HardcoverClient(IGraphQLClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<Edition>> LookupBook(string title, string? author = null)
|
||||
{
|
||||
var query = new GraphQLRequest
|
||||
{
|
||||
Query = @"
|
||||
query ($title: String!, $author: String) {
|
||||
editions(
|
||||
where: {title: {_eq: $title}, _and: {contributions: {author: {name: {_eq: $author}}}}}
|
||||
) {
|
||||
id
|
||||
title
|
||||
edition_format
|
||||
pages
|
||||
release_date
|
||||
isbn_10
|
||||
isbn_13
|
||||
publisher {
|
||||
name
|
||||
}
|
||||
contributions {
|
||||
author {
|
||||
id
|
||||
name
|
||||
name_personal
|
||||
image {
|
||||
url
|
||||
}
|
||||
bio
|
||||
books_count
|
||||
born_date
|
||||
death_date
|
||||
gender_id
|
||||
identifiers
|
||||
state
|
||||
}
|
||||
}
|
||||
image {
|
||||
url
|
||||
}
|
||||
}
|
||||
}",
|
||||
Variables = new
|
||||
{
|
||||
title,
|
||||
author
|
||||
}
|
||||
};
|
||||
var response = await _client.SendQueryAsync<EditionsCollectionType>(query);
|
||||
return response.Data.Editions;
|
||||
}
|
||||
|
||||
public async Task<List<Author>> LookupAuthor(string name)
|
||||
{
|
||||
//order_by: {books_count: desc}
|
||||
//limit: 1
|
||||
var query = new GraphQLRequest
|
||||
{
|
||||
Query = @"query ($name: String){
|
||||
authors(where: {name: {_eq: $name}}) {
|
||||
id
|
||||
name
|
||||
name_personal
|
||||
image {
|
||||
url
|
||||
}
|
||||
bio
|
||||
books_count
|
||||
born_date
|
||||
death_date
|
||||
gender_id
|
||||
identifiers
|
||||
state
|
||||
}
|
||||
}",
|
||||
Variables = new
|
||||
{
|
||||
name
|
||||
}
|
||||
};
|
||||
var response = await _client.SendQueryAsync<AuthorsCollectionType>(query);
|
||||
return response.Data.Authors;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user