diff --git a/LibraryManagement.Api/Services/Foundations/ReaderBooks/IReaderBookService.cs b/LibraryManagement.Api/Services/Foundations/ReaderBooks/IReaderBookService.cs new file mode 100644 index 0000000..16f0da4 --- /dev/null +++ b/LibraryManagement.Api/Services/Foundations/ReaderBooks/IReaderBookService.cs @@ -0,0 +1,14 @@ +//----------------------------------------------------------- +// Copyright (c) Coalition of Good-Hearted Engineers +// Free To Use To Build Reliable Library Management Solutions +//----------------------------------------------------------- + +using LibraryManagement.Api.Models.Foundations.ReaderBooks; + +namespace LibraryManagement.Api.Services.Foundations.ReaderBooks +{ + public interface IReaderBookService + { + ValueTask RetrieveReaderBookByIdAsync(Guid readerId); + } +} diff --git a/LibraryManagement.Api/Services/Foundations/ReaderBooks/ReaderBookService.cs b/LibraryManagement.Api/Services/Foundations/ReaderBooks/ReaderBookService.cs new file mode 100644 index 0000000..488c740 --- /dev/null +++ b/LibraryManagement.Api/Services/Foundations/ReaderBooks/ReaderBookService.cs @@ -0,0 +1,46 @@ +//----------------------------------------------------------- +// Copyright (c) Coalition of Good-Hearted Engineers +// Free To Use To Build Reliable Library Management Solutions +//----------------------------------------------------------- + +using LibraryManagement.Api.Models.Foundations.Books; +using LibraryManagement.Api.Models.Foundations.ReaderBooks; +using LibraryManagement.Api.Models.Foundations.Readers; +using LibraryManagement.Api.Services.Foundations.Books; +using LibraryManagement.Api.Services.Foundations.Readers; + +namespace LibraryManagement.Api.Services.Foundations.ReaderBooks +{ + public class ReaderBookService : IReaderBookService + { + private readonly IReaderService readerService; + private readonly IBookService bookService; + + public ReaderBookService( + IReaderService readerService, + IBookService bookService) + { + this.readerService = readerService; + this.bookService = bookService; + } + + public async ValueTask RetrieveReaderBookByIdAsync(Guid readerId) + { + Reader reader = + await this.readerService.RetrieveReaderByIdAsync(readerId); + + IQueryable allBooks = + this.bookService.RetrieveAllBooks(); + + List booksForReader = allBooks + .Where(book => book.ReaderId == readerId) + .ToList(); + + return new ReaderBook + { + Reader = reader, + Books = booksForReader + }; + } + } +}