switchade t bootstrap och testar solid-bootstrap. konf för calibre. test m covers

This commit is contained in:
2025-09-06 01:27:13 +02:00
parent 5ae7c7f47b
commit 1744a5b7de
11 changed files with 476 additions and 38 deletions

View File

@@ -1,16 +1,25 @@
using Bibblan.Models;
using Bibblan.ViewModels;
using Microsoft.Extensions.Options;
namespace Bibblan.Business.Services
{
public class CalibreService
{
private readonly BibblanOptions _options;
CalibreContext _context;
public CalibreService(CalibreContext context)
public CalibreService(CalibreContext context, IOptions<BibblanOptions> options)
{
_options = options.Value;
_context = context;
}
public byte[] Cover(string path)
{
var fullPath = Path.Combine(_options.CalibreRoot, path, "cover.jpg");
return File.ReadAllBytes(fullPath);
}
public IQueryable<BookVm> GetAllBooks()
{
return from b in _context.Books

View File

@@ -8,16 +8,24 @@ namespace Bibblan.Controllers
[Route("api/[controller]")]
public class CalibreController : ControllerBase
{
CalibreService service;
public CalibreController(CalibreContext db) {
service = new CalibreService(db);
CalibreService _service;
public CalibreController(CalibreService service) {
_service = service;
}
[HttpGet("books")]
public IActionResult GetBooks()
{
var books = service.GetAllBooks().Take(100).ToList();
var books = _service.GetAllBooks().Take(100).ToList();
return Ok(books);
}
[HttpGet("cover")]
public IActionResult GetCover(string path)
{
var bytes = _service.Cover(path);
return File(bytes, "image/jpeg", true);
}
}
}

View File

@@ -0,0 +1,10 @@
namespace Bibblan.Models
{
public class BibblanOptions
{
public const string Bibblan = "Bibblan";
public string CalibreDb { get; set; } = String.Empty;
public string CalibreRoot { get; set; } = String.Empty;
}
}

View File

@@ -1,14 +1,21 @@
using Bibblan.Business.Services;
using Bibblan.Models;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.Configure<BibblanOptions>(
builder.Configuration.GetSection(BibblanOptions.Bibblan));
builder.Services.AddScoped<CalibreService, CalibreService>();
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
var db = "metadata.db";
var connection = $"Data Source={db};Mode=ReadOnly;";
builder.Services.AddDbContext<CalibreContext>(options => options.UseSqlite(connection));

View File

@@ -5,5 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Bibblan": {
"CalibreDb": "metadata.db",
"CalibreRoot": "\\\\diskstation\\Books\\"
}
}