La in dapper, och routing. fixade upp lite exempelsidor

This commit is contained in:
2025-09-09 17:15:11 +02:00
parent 8c54a120d1
commit 01e341fce0
15 changed files with 260 additions and 24 deletions

View 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);
}
}
}