Skip to content

Commit ce97973

Browse files
Merge pull request #28 from DilmurodDeveloper/users/DilmurodDeveloper/brokers-book-select
BROKERS: Select Book
2 parents a712282 + 2ec8197 commit ce97973

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

LibraryManagement.Api/Brokers/Storages/IStorageBroker.Book.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ namespace LibraryManagement.Api.Brokers.Storages
1010
public partial interface IStorageBroker
1111
{
1212
ValueTask<Book> InsertBookAsync(Book book);
13+
IQueryable<Book> SelectAllBooks();
14+
ValueTask<Book> SelectBookByIdAsync(Guid bookId);
1315
}
1416
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,21 @@ public partial class StorageBroker
1414

1515
public async ValueTask<Book> InsertBookAsync(Book book) =>
1616
await InsertAsync(book);
17+
18+
public IQueryable<Book> SelectAllBooks()
19+
{
20+
var books = SelectAll<Book>().Include(a => a.Reader);
21+
22+
return books;
23+
}
24+
25+
public async ValueTask<Book> SelectBookByIdAsync(Guid bookId)
26+
{
27+
var readerWithBooks = Books
28+
.Include(a => a.Reader)
29+
.FirstOrDefault(a => a.BookId == bookId);
30+
31+
return await ValueTask.FromResult(readerWithBooks);
32+
}
1733
}
1834
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public async ValueTask<T> InsertAsync<T>(T @object)
2727
return @object;
2828
}
2929

30+
public IQueryable<T> SelectAll<T>() where T : class
31+
{
32+
var broker = new StorageBroker(configuration);
33+
34+
return broker.Set<T>();
35+
}
36+
3037
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
3138
{
3239
string connectionString =

0 commit comments

Comments
 (0)