| 1 | using ChapterX.Domain.Entities;
|
|---|
| 2 | using ChapterX.Domain.Repositories;
|
|---|
| 3 | using ChapterX.Infrastructure.Data.DataContext;
|
|---|
| 4 | using Microsoft.EntityFrameworkCore;
|
|---|
| 5 |
|
|---|
| 6 | namespace ChapterX.Infrastructure.Repositories
|
|---|
| 7 | {
|
|---|
| 8 | public class ReadingListRepository : GenericRepository<ReadingList>, IReadingListRepository
|
|---|
| 9 | {
|
|---|
| 10 | public ReadingListRepository(ApplicationDbContext context) : base(context)
|
|---|
| 11 | {
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | public override async Task<IEnumerable<ReadingList>> GetAllAsync(CancellationToken cancellationToken = default)
|
|---|
| 15 | {
|
|---|
| 16 | return await _dbSet
|
|---|
| 17 | .Include(r => r.User)
|
|---|
| 18 | .Include(r => r.ReadingListItems)
|
|---|
| 19 | .ThenInclude(i => i.Story)
|
|---|
| 20 | .ThenInclude(s => s.Writer)
|
|---|
| 21 | .ThenInclude(w => w!.User)
|
|---|
| 22 | .Include(r => r.ReadingListItems)
|
|---|
| 23 | .ThenInclude(i => i.Story)
|
|---|
| 24 | .ThenInclude(s => s.HasGenres)
|
|---|
| 25 | .ThenInclude(hg => hg.Genre)
|
|---|
| 26 | .ToListAsync(cancellationToken);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | public async Task<IEnumerable<ReadingList>> GetByUserIdAsync(int userId, CancellationToken cancellationToken = default)
|
|---|
| 30 | {
|
|---|
| 31 | return await _dbSet
|
|---|
| 32 | .Where(r => r.UserId == userId)
|
|---|
| 33 | .Include(r => r.User)
|
|---|
| 34 | .Include(r => r.ReadingListItems)
|
|---|
| 35 | .ThenInclude(i => i.Story)
|
|---|
| 36 | .ThenInclude(s => s.Writer)
|
|---|
| 37 | .ThenInclude(w => w!.User)
|
|---|
| 38 | .Include(r => r.ReadingListItems)
|
|---|
| 39 | .ThenInclude(i => i.Story)
|
|---|
| 40 | .ThenInclude(s => s.HasGenres)
|
|---|
| 41 | .ThenInclude(hg => hg.Genre)
|
|---|
| 42 | .ToListAsync(cancellationToken);
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|