snyggade till hardcover. la til author lookup
This commit is contained in:
@@ -1,46 +1,12 @@
|
||||
using Bibblan.Business.Services;
|
||||
using Bibblan.Business.Clients;
|
||||
using Bibblan.Business.Services;
|
||||
using GraphQL;
|
||||
using GraphQL.Client.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bibblan.Controllers
|
||||
{
|
||||
public class Publisher
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public class Image
|
||||
{
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public class Author
|
||||
{
|
||||
public string Name { 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; }
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
@@ -48,13 +14,13 @@ namespace Bibblan.Controllers
|
||||
{
|
||||
DatabaseService _db;
|
||||
CalibreService _calibre;
|
||||
private readonly IGraphQLClient _client;
|
||||
HardcoverClient _hardCover;
|
||||
|
||||
public BibblanController(DatabaseService databaseService, CalibreService calibre, IGraphQLClient client)
|
||||
public BibblanController(DatabaseService databaseService, CalibreService calibre, HardcoverClient hcclient)
|
||||
{
|
||||
_db = databaseService;
|
||||
_calibre = calibre;
|
||||
_client = client;
|
||||
_hardCover = hcclient;
|
||||
}
|
||||
|
||||
[HttpGet("cover")]
|
||||
@@ -140,45 +106,21 @@ namespace Bibblan.Controllers
|
||||
var tags = _db.GetTags(filter).ToList();
|
||||
return Ok(tags);
|
||||
}
|
||||
|
||||
//test
|
||||
[HttpGet("lookup")]
|
||||
public async Task<IActionResult> HardcoverLookup(string title, string author)
|
||||
[HttpGet("lookupbook")]
|
||||
public async Task<IActionResult> LookupBook(string title, string author)
|
||||
{
|
||||
var query = new GraphQLRequest
|
||||
{
|
||||
Query = @"
|
||||
query SomeNameHere($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 {
|
||||
name
|
||||
}
|
||||
}
|
||||
image {
|
||||
url
|
||||
}
|
||||
}
|
||||
}",
|
||||
Variables = new
|
||||
{
|
||||
title,
|
||||
author
|
||||
}
|
||||
};
|
||||
var response = await _client.SendQueryAsync<EditionsCollectionType>(query);
|
||||
return Ok(response.Data.Editions);
|
||||
var result = await _hardCover.LookupBook(title, author);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("lookupauthor")]
|
||||
public async Task<IActionResult> LookupAuthor(string name)
|
||||
{
|
||||
var result = await _hardCover.LookupAuthor(name);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user