La in dapper, och routing. fixade upp lite exempelsidor
This commit is contained in:
53
Server/Controllers/BibblanController.cs
Normal file
53
Server/Controllers/BibblanController.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Bibblan.Business.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bibblan.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class BibblanController : ControllerBase
|
||||
{
|
||||
DatabaseService _db;
|
||||
CalibreService _calibre;
|
||||
|
||||
public BibblanController(DatabaseService databaseService, CalibreService calibre)
|
||||
{
|
||||
_db = databaseService;
|
||||
_calibre = calibre;
|
||||
}
|
||||
|
||||
[HttpGet("cover")]
|
||||
public IActionResult GetCover(string path)
|
||||
{
|
||||
//TODO: Bör kanske inte gå direkt mot calibres filer..
|
||||
var bytes = _calibre.Cover(path);
|
||||
return File(bytes, "image/jpeg", true);
|
||||
}
|
||||
|
||||
[HttpGet("books")]
|
||||
public IActionResult GetBooks()
|
||||
{
|
||||
var authors = _db.GetBooks(100).ToList();
|
||||
return Ok(authors);
|
||||
}
|
||||
|
||||
[HttpGet("authors")]
|
||||
public IActionResult GetAuthors()
|
||||
{
|
||||
var authors = _db.GetAuthors(100).ToList();
|
||||
return Ok(authors);
|
||||
}
|
||||
|
||||
[HttpGet("books/author/{authorid}")]
|
||||
public IActionResult GetBooksByAuthor(int authorid)
|
||||
{
|
||||
var authors = _db.GetBooks(100, new BookFilter
|
||||
{
|
||||
Author = authorid
|
||||
}).ToList();
|
||||
return Ok(authors);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user