Compare commits

..

2 Commits

Author SHA1 Message Date
47069f5ece
fix: amend 5cb61d275d
Add missing services
2023-12-14 16:31:55 +00:00
b147439065
chore: update npm tag 20-alpine
aldo adds module property with value NodeNext in tsconfig.json
2023-12-14 16:31:25 +00:00
4 changed files with 50 additions and 2 deletions

View File

@ -3,7 +3,7 @@ WORKDIR /app
EXPOSE 80 EXPOSE 80
EXPOSE 443 EXPOSE 443
FROM node:alpine as build-deps FROM node:20-alpine as build-deps
WORKDIR /src WORKDIR /src
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
RUN npm i -g gulp-cli RUN npm i -g gulp-cli

View File

@ -0,0 +1,16 @@
using OliverBooth.Data.Web;
namespace OliverBooth.Services;
/// <summary>
/// Represents a service which fetches books from the reading list.
/// </summary>
public interface IReadingListService
{
/// <summary>
/// Gets the books in the reading list with the specified state.
/// </summary>
/// <param name="state">The state.</param>
/// <returns>A collection of books in the specified state.</returns>
IReadOnlyCollection<IBook> GetBooks(BookState state);
}

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using OliverBooth.Data.Web;
namespace OliverBooth.Services;
internal sealed class ReadingListService : IReadingListService
{
private readonly IDbContextFactory<WebContext> _dbContextFactory;
/// <summary>
/// Initializes a new instance of the <see cref="ReadingListService" /> class.
/// </summary>
/// <param name="dbContextFactory">The database context factory.</param>
public ReadingListService(IDbContextFactory<WebContext> dbContextFactory)
{
_dbContextFactory = dbContextFactory;
}
/// <summary>
/// Gets the books in the reading list with the specified state.
/// </summary>
/// <param name="state">The state.</param>
/// <returns>A collection of books in the specified state.</returns>
public IReadOnlyCollection<IBook> GetBooks(BookState state)
{
using WebContext context = _dbContextFactory.CreateDbContext();
return state == (BookState)(-1)
? context.Books.ToArray()
: context.Books.Where(b => b.State == state).ToArray();
}
}

View File

@ -2,6 +2,7 @@
"compilerOptions": { "compilerOptions": {
"lib": ["ES2022", "DOM"], "lib": ["ES2022", "DOM"],
"target": "ES2022", "target": "ES2022",
"moduleResolution": "nodenext" "module": "NodeNext",
"moduleResolution": "NodeNext"
} }
} }